Skip to content

Commit

Permalink
refactor: Make AccessPaths#calculateMaxNumberOfRides an instance method
Browse files Browse the repository at this point in the history
  • Loading branch information
t2gran committed Oct 10, 2024
1 parent 47c6348 commit 936fc2e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<T> route() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -118,13 +117,11 @@ public List<RaptorAccessEgress> 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)
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 936fc2e

Please sign in to comment.