diff --git a/application/src/main/java/org/opentripplanner/apis/gtfs/datafetchers/LegImpl.java b/application/src/main/java/org/opentripplanner/apis/gtfs/datafetchers/LegImpl.java index 5548ca5ff59..3f1255d9985 100644 --- a/application/src/main/java/org/opentripplanner/apis/gtfs/datafetchers/LegImpl.java +++ b/application/src/main/java/org/opentripplanner/apis/gtfs/datafetchers/LegImpl.java @@ -28,6 +28,7 @@ import org.opentripplanner.routing.alertpatch.TransitAlert; import org.opentripplanner.routing.alternativelegs.AlternativeLegs; import org.opentripplanner.routing.alternativelegs.AlternativeLegsFilter; +import org.opentripplanner.routing.alternativelegs.SearchTime; import org.opentripplanner.transit.model.network.Route; import org.opentripplanner.transit.model.organization.Agency; import org.opentripplanner.transit.model.timetable.Trip; @@ -277,16 +278,16 @@ private Leg getSource(DataFetchingEnvironment environment) { @Override public DataFetcher> previousLegs() { - return alternativeLegs(AlternativeLegs.SearchDirection.PREVIOUS); + return alternativeLegs(SearchTime.BEFORE); } @Override public DataFetcher> nextLegs() { - return alternativeLegs(AlternativeLegs.SearchDirection.NEXT); + return alternativeLegs(SearchTime.AFTER); } private DataFetcher> alternativeLegs( - AlternativeLegs.SearchDirection searchDirection + SearchTime searchDirection ) { return environment -> { if (environment.getSource() instanceof ScheduledTransitLeg originalLeg) { diff --git a/application/src/main/java/org/opentripplanner/apis/transmodel/model/plan/LegType.java b/application/src/main/java/org/opentripplanner/apis/transmodel/model/plan/LegType.java index 6ba90ea8b09..6ca8c74070e 100644 --- a/application/src/main/java/org/opentripplanner/apis/transmodel/model/plan/LegType.java +++ b/application/src/main/java/org/opentripplanner/apis/transmodel/model/plan/LegType.java @@ -33,7 +33,7 @@ import org.opentripplanner.model.plan.TransitLeg; import org.opentripplanner.model.plan.legreference.LegReferenceSerializer; import org.opentripplanner.routing.alternativelegs.AlternativeLegs; -import org.opentripplanner.routing.alternativelegs.AlternativeLegs.SearchDirection; +import org.opentripplanner.routing.alternativelegs.SearchTime; public class LegType { @@ -486,7 +486,7 @@ public static GraphQLObjectType create( leg, env.getArgument("previous"), GqlUtil.getTransitService(env), - SearchDirection.PREVIOUS, + SearchTime.BEFORE, env.getArgument("filter") ); }) @@ -526,7 +526,7 @@ public static GraphQLObjectType create( leg, env.getArgument("next"), GqlUtil.getTransitService(env), - SearchDirection.NEXT, + SearchTime.AFTER, env.getArgument("filter") ); }) diff --git a/application/src/main/java/org/opentripplanner/routing/alternativelegs/AlternativeLegs.java b/application/src/main/java/org/opentripplanner/routing/alternativelegs/AlternativeLegs.java index b7c20b4c12d..7a1c45684cd 100644 --- a/application/src/main/java/org/opentripplanner/routing/alternativelegs/AlternativeLegs.java +++ b/application/src/main/java/org/opentripplanner/routing/alternativelegs/AlternativeLegs.java @@ -39,18 +39,13 @@ */ public class AlternativeLegs { - public enum SearchDirection { - NEXT, - PREVIOUS, - } - public static final int ZERO_COST = 0; public static List getAlternativeLegs( Leg leg, Integer numberLegs, TransitService transitService, - SearchDirection searchDirection, + SearchTime searchDirection, AlternativeLegsFilter filter ) { return getAlternativeLegs( @@ -86,7 +81,7 @@ public static List getAlternativeLegs( Leg leg, Integer numberLegs, TransitService transitService, - SearchDirection searchDirection, + SearchTime searchDirection, AlternativeLegsFilter filter, boolean exactOriginStop, boolean exactDestinationStop @@ -109,7 +104,7 @@ public static List getAlternativeLegs( ScheduledTransitLeg::getStartTime ); - if (searchDirection == SearchDirection.PREVIOUS) { + if (searchDirection == SearchTime.BEFORE) { legComparator = legComparator.reversed(); } @@ -140,7 +135,7 @@ private static Stream generateLegs( TripPatternBetweenStops tripPatternBetweenStops, ZonedDateTime departureTime, LocalDate originalDate, - SearchDirection searchDirection + SearchTime searchDirection ) { TripPattern pattern = tripPatternBetweenStops.tripPattern; int boardingPosition = tripPatternBetweenStops.positions.boardingPosition; @@ -153,7 +148,7 @@ private static Stream generateLegs( tts.getServiceDayMidnight() + tts.getRealtimeDeparture() ); - if (searchDirection == SearchDirection.PREVIOUS) { + if (searchDirection == SearchTime.BEFORE) { comparator = comparator.reversed(); } @@ -183,7 +178,7 @@ private static Stream generateLegs( continue; } - boolean departureTimeInRange = searchDirection == SearchDirection.PREVIOUS + boolean departureTimeInRange = searchDirection == SearchTime.BEFORE ? tripTimes.getDepartureTime(boardingPosition) <= secondsSinceMidnight : tripTimes.getDepartureTime(boardingPosition) >= secondsSinceMidnight; diff --git a/application/src/main/java/org/opentripplanner/routing/alternativelegs/SearchTime.java b/application/src/main/java/org/opentripplanner/routing/alternativelegs/SearchTime.java new file mode 100644 index 00000000000..1417dba47d2 --- /dev/null +++ b/application/src/main/java/org/opentripplanner/routing/alternativelegs/SearchTime.java @@ -0,0 +1,6 @@ +package org.opentripplanner.routing.alternativelegs; + +public enum SearchTime { + AFTER, + BEFORE, +} diff --git a/application/src/test/java/org/opentripplanner/routing/stoptimes/AlternativeLegsTest.java b/application/src/test/java/org/opentripplanner/routing/stoptimes/AlternativeLegsTest.java index c9833eae3a5..3380e8deb9f 100644 --- a/application/src/test/java/org/opentripplanner/routing/stoptimes/AlternativeLegsTest.java +++ b/application/src/test/java/org/opentripplanner/routing/stoptimes/AlternativeLegsTest.java @@ -12,6 +12,7 @@ import org.opentripplanner.model.plan.legreference.ScheduledTransitLegReference; import org.opentripplanner.routing.alternativelegs.AlternativeLegs; import org.opentripplanner.routing.alternativelegs.AlternativeLegsFilter; +import org.opentripplanner.routing.alternativelegs.SearchTime; import org.opentripplanner.transit.model.framework.FeedScopedId; import org.opentripplanner.transit.service.DefaultTransitService; @@ -51,7 +52,7 @@ void testPreviousLegs() { originalLeg, 3, transitService, - AlternativeLegs.SearchDirection.PREVIOUS, + SearchTime.BEFORE, AlternativeLegsFilter.NO_FILTER ); @@ -85,7 +86,7 @@ void testNextLegs() { originalLeg, 3, transitService, - AlternativeLegs.SearchDirection.NEXT, + SearchTime.AFTER, AlternativeLegsFilter.NO_FILTER ); @@ -119,7 +120,7 @@ void testCircularRoutes() { originalLeg, 2, transitService, - AlternativeLegs.SearchDirection.NEXT, + SearchTime.AFTER, AlternativeLegsFilter.NO_FILTER ); @@ -147,7 +148,7 @@ void testComplexCircularRoutes() { originalLeg, 2, transitService, - AlternativeLegs.SearchDirection.NEXT, + SearchTime.AFTER, AlternativeLegsFilter.NO_FILTER ); var legs = toString(alternativeLegs);