From 936fc2e22ccd78fc624adff5a89684702111d278 Mon Sep 17 00:00:00 2001 From: Thomas Gran Date: Thu, 10 Oct 2024 16:47:22 +0200 Subject: [PATCH] refactor: Make AccessPaths#calculateMaxNumberOfRides an instance method --- .../raptor/rangeraptor/RangeRaptor.java | 18 ++++++++++-------- .../rangeraptor/transit/AccessPaths.java | 13 +++++-------- .../rangeraptor/transit/AccessPathsTest.java | 5 ++--- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/main/java/org/opentripplanner/raptor/rangeraptor/RangeRaptor.java b/src/main/java/org/opentripplanner/raptor/rangeraptor/RangeRaptor.java index 2aeb1a1bb26..02c39f9e52c 100644 --- a/src/main/java/org/opentripplanner/raptor/rangeraptor/RangeRaptor.java +++ b/src/main/java/org/opentripplanner/raptor/rangeraptor/RangeRaptor.java @@ -1,5 +1,7 @@ package org.opentripplanner.raptor.rangeraptor; +import static java.util.Objects.requireNonNull; + import org.opentripplanner.framework.application.OTPRequestTimeoutException; import org.opentripplanner.raptor.api.debug.RaptorTimers; import org.opentripplanner.raptor.api.model.RaptorConstants; @@ -75,14 +77,14 @@ public RangeRaptor( LifeCycleEventPublisher lifeCyclePublisher, RaptorTimers timers ) { - this.worker = worker; - this.transitData = transitData; - this.calculator = calculator; - this.timers = timers; - this.accessPaths = accessPaths; - this.minNumberOfRounds = AccessPaths.calculateMaxNumberOfRides(accessPaths); - this.roundTracker = roundTracker; - this.lifeCycle = lifeCyclePublisher; + this.worker = requireNonNull(worker); + this.transitData = requireNonNull(transitData); + this.calculator = requireNonNull(calculator); + this.timers = requireNonNull(timers); + this.accessPaths = requireNonNull(accessPaths); + this.minNumberOfRounds = accessPaths.calculateMaxNumberOfRides(); + this.roundTracker = requireNonNull(roundTracker); + this.lifeCycle = requireNonNull(lifeCyclePublisher); } public RaptorRouterResult route() { diff --git a/src/main/java/org/opentripplanner/raptor/rangeraptor/transit/AccessPaths.java b/src/main/java/org/opentripplanner/raptor/rangeraptor/transit/AccessPaths.java index 8a5b4104eab..7b4c3b76321 100644 --- a/src/main/java/org/opentripplanner/raptor/rangeraptor/transit/AccessPaths.java +++ b/src/main/java/org/opentripplanner/raptor/rangeraptor/transit/AccessPaths.java @@ -10,7 +10,6 @@ import java.util.Collection; import java.util.List; import java.util.function.IntUnaryOperator; -import javax.annotation.Nullable; import org.opentripplanner.raptor.api.model.RaptorAccessEgress; import org.opentripplanner.raptor.api.model.RaptorConstants; import org.opentripplanner.raptor.api.model.SearchDirection; @@ -118,13 +117,11 @@ public List arrivedOnBoardByNumOfRides(int round) { return filterOnTimePenaltyLimitIfExist(arrivedOnBoardByNumOfRides.get(round)); } - public static int calculateMaxNumberOfRides(@Nullable AccessPaths paths) { - return paths == null - ? 0 - : Math.max( - Arrays.stream(paths.arrivedOnStreetByNumOfRides.keys()).max().orElse(0), - Arrays.stream(paths.arrivedOnBoardByNumOfRides.keys()).max().orElse(0) - ); + public int calculateMaxNumberOfRides() { + return Math.max( + Arrays.stream(arrivedOnStreetByNumOfRides.keys()).max().orElse(0), + Arrays.stream(arrivedOnBoardByNumOfRides.keys()).max().orElse(0) + ); } /** diff --git a/src/test/java/org/opentripplanner/raptor/rangeraptor/transit/AccessPathsTest.java b/src/test/java/org/opentripplanner/raptor/rangeraptor/transit/AccessPathsTest.java index 505fa67706e..8611a046a5b 100644 --- a/src/test/java/org/opentripplanner/raptor/rangeraptor/transit/AccessPathsTest.java +++ b/src/test/java/org/opentripplanner/raptor/rangeraptor/transit/AccessPathsTest.java @@ -78,9 +78,8 @@ void arrivedOnBoardByNumOfRides() { @Test void calculateMaxNumberOfRides() { - assertEquals(0, AccessPaths.calculateMaxNumberOfRides(null)); - assertEquals(3, AccessPaths.calculateMaxNumberOfRides(create(STANDARD))); - assertEquals(3, AccessPaths.calculateMaxNumberOfRides(create(MULTI_CRITERIA))); + assertEquals(3, create(STANDARD).calculateMaxNumberOfRides()); + assertEquals(3, create(MULTI_CRITERIA).calculateMaxNumberOfRides()); } @Test