From ac912a6e9f671abb5baefa2a8d9e3b113af9d64c Mon Sep 17 00:00:00 2001 From: Michael Tsang Date: Mon, 11 Nov 2024 15:02:03 +0000 Subject: [PATCH] rename the enum again --- .../apis/gtfs/datafetchers/LegImpl.java | 8 ++++---- .../apis/transmodel/model/plan/LegType.java | 6 +++--- .../routing/alternativelegs/AlternativeLegs.java | 12 ++++++------ .../alternativelegs/NavigationDirection.java | 15 +++++++++++++++ .../routing/alternativelegs/SearchTime.java | 6 ------ .../routing/stoptimes/AlternativeLegsTest.java | 10 +++++----- 6 files changed, 33 insertions(+), 24 deletions(-) create mode 100644 application/src/main/java/org/opentripplanner/routing/alternativelegs/NavigationDirection.java delete mode 100644 application/src/main/java/org/opentripplanner/routing/alternativelegs/SearchTime.java 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 54a40cef843..b02ea12e525 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,7 +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.routing.alternativelegs.NavigationDirection; import org.opentripplanner.transit.model.network.Route; import org.opentripplanner.transit.model.organization.Agency; import org.opentripplanner.transit.model.timetable.Trip; @@ -278,15 +278,15 @@ private Leg getSource(DataFetchingEnvironment environment) { @Override public DataFetcher> previousLegs() { - return alternativeLegs(SearchTime.BEFORE); + return alternativeLegs(NavigationDirection.PREVIOUS); } @Override public DataFetcher> nextLegs() { - return alternativeLegs(SearchTime.AFTER); + return alternativeLegs(NavigationDirection.NEXT); } - private DataFetcher> alternativeLegs(SearchTime timeLine) { + private DataFetcher> alternativeLegs(NavigationDirection timeLine) { return environment -> { if (environment.getSource() instanceof ScheduledTransitLeg originalLeg) { var args = new GraphQLTypes.GraphQLLegNextLegsArgs(environment.getArguments()); 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 6ca8c74070e..4b405f50f66 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.SearchTime; +import org.opentripplanner.routing.alternativelegs.NavigationDirection; public class LegType { @@ -486,7 +486,7 @@ public static GraphQLObjectType create( leg, env.getArgument("previous"), GqlUtil.getTransitService(env), - SearchTime.BEFORE, + NavigationDirection.PREVIOUS, env.getArgument("filter") ); }) @@ -526,7 +526,7 @@ public static GraphQLObjectType create( leg, env.getArgument("next"), GqlUtil.getTransitService(env), - SearchTime.AFTER, + NavigationDirection.NEXT, 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 b71287a1c0e..7b685cf8193 100644 --- a/application/src/main/java/org/opentripplanner/routing/alternativelegs/AlternativeLegs.java +++ b/application/src/main/java/org/opentripplanner/routing/alternativelegs/AlternativeLegs.java @@ -45,7 +45,7 @@ public static List getAlternativeLegs( Leg leg, Integer numberLegs, TransitService transitService, - SearchTime timeLine, + NavigationDirection timeLine, AlternativeLegsFilter filter ) { return getAlternativeLegs(leg, numberLegs, transitService, timeLine, filter, false, false); @@ -73,7 +73,7 @@ public static List getAlternativeLegs( Leg leg, Integer numberLegs, TransitService transitService, - SearchTime timeLine, + NavigationDirection timeLine, AlternativeLegsFilter filter, boolean exactOriginStop, boolean exactDestinationStop @@ -96,7 +96,7 @@ public static List getAlternativeLegs( ScheduledTransitLeg::getStartTime ); - if (timeLine == SearchTime.BEFORE) { + if (timeLine == NavigationDirection.PREVIOUS) { legComparator = legComparator.reversed(); } @@ -127,7 +127,7 @@ private static Stream generateLegs( TripPatternBetweenStops tripPatternBetweenStops, ZonedDateTime departureTime, LocalDate originalDate, - SearchTime timeLine + NavigationDirection timeLine ) { TripPattern pattern = tripPatternBetweenStops.tripPattern; int boardingPosition = tripPatternBetweenStops.positions.boardingPosition; @@ -140,7 +140,7 @@ private static Stream generateLegs( tts.getServiceDayMidnight() + tts.getRealtimeDeparture() ); - if (timeLine == SearchTime.BEFORE) { + if (timeLine == NavigationDirection.PREVIOUS) { comparator = comparator.reversed(); } @@ -170,7 +170,7 @@ private static Stream generateLegs( continue; } - boolean departureTimeInRange = timeLine == SearchTime.BEFORE + boolean departureTimeInRange = timeLine == NavigationDirection.PREVIOUS ? tripTimes.getDepartureTime(boardingPosition) <= secondsSinceMidnight : tripTimes.getDepartureTime(boardingPosition) >= secondsSinceMidnight; diff --git a/application/src/main/java/org/opentripplanner/routing/alternativelegs/NavigationDirection.java b/application/src/main/java/org/opentripplanner/routing/alternativelegs/NavigationDirection.java new file mode 100644 index 00000000000..4c3f17adf48 --- /dev/null +++ b/application/src/main/java/org/opentripplanner/routing/alternativelegs/NavigationDirection.java @@ -0,0 +1,15 @@ +package org.opentripplanner.routing.alternativelegs; + +/** + * This enum describes how the user navigates on a list of items. + */ +public enum NavigationDirection { + /** + * Get the next set of items. + */ + NEXT, + /** + * Get the previous set of items. + */ + PREVIOUS, +} diff --git a/application/src/main/java/org/opentripplanner/routing/alternativelegs/SearchTime.java b/application/src/main/java/org/opentripplanner/routing/alternativelegs/SearchTime.java deleted file mode 100644 index 1417dba47d2..00000000000 --- a/application/src/main/java/org/opentripplanner/routing/alternativelegs/SearchTime.java +++ /dev/null @@ -1,6 +0,0 @@ -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 3380e8deb9f..65e99825a9e 100644 --- a/application/src/test/java/org/opentripplanner/routing/stoptimes/AlternativeLegsTest.java +++ b/application/src/test/java/org/opentripplanner/routing/stoptimes/AlternativeLegsTest.java @@ -12,7 +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.routing.alternativelegs.NavigationDirection; import org.opentripplanner.transit.model.framework.FeedScopedId; import org.opentripplanner.transit.service.DefaultTransitService; @@ -52,7 +52,7 @@ void testPreviousLegs() { originalLeg, 3, transitService, - SearchTime.BEFORE, + NavigationDirection.PREVIOUS, AlternativeLegsFilter.NO_FILTER ); @@ -86,7 +86,7 @@ void testNextLegs() { originalLeg, 3, transitService, - SearchTime.AFTER, + NavigationDirection.NEXT, AlternativeLegsFilter.NO_FILTER ); @@ -120,7 +120,7 @@ void testCircularRoutes() { originalLeg, 2, transitService, - SearchTime.AFTER, + NavigationDirection.NEXT, AlternativeLegsFilter.NO_FILTER ); @@ -148,7 +148,7 @@ void testComplexCircularRoutes() { originalLeg, 2, transitService, - SearchTime.AFTER, + NavigationDirection.NEXT, AlternativeLegsFilter.NO_FILTER ); var legs = toString(alternativeLegs);