From 124f58956014f92fadc3887c3a194f9dd36b9769 Mon Sep 17 00:00:00 2001 From: Michael Tsang Date: Thu, 10 Oct 2024 16:28:11 +0100 Subject: [PATCH 1/9] add previousLegs into GTFS GraphQL API --- .../apis/gtfs/datafetchers/LegImpl.java | 11 +++- .../gtfs/generated/GraphQLDataFetchers.java | 11 ++++ .../apis/gtfs/generated/GraphQLTypes.java | 64 +++++++++++++++++++ .../opentripplanner/apis/gtfs/schema.graphqls | 18 ++++++ 4 files changed, 103 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/opentripplanner/apis/gtfs/datafetchers/LegImpl.java b/src/main/java/org/opentripplanner/apis/gtfs/datafetchers/LegImpl.java index 9ec83a4bf67..2fd9220cae5 100644 --- a/src/main/java/org/opentripplanner/apis/gtfs/datafetchers/LegImpl.java +++ b/src/main/java/org/opentripplanner/apis/gtfs/datafetchers/LegImpl.java @@ -271,8 +271,17 @@ private Leg getSource(DataFetchingEnvironment environment) { return environment.getSource(); } + @Override + public DataFetcher> previousLegs() { + return nextOrPreviousLegs(true); + } + @Override public DataFetcher> nextLegs() { + return nextOrPreviousLegs(false); + } + + private DataFetcher> nextOrPreviousLegs(boolean includeDepartBefore) { return environment -> { if (environment.getSource() instanceof ScheduledTransitLeg originalLeg) { var args = new GraphQLTypes.GraphQLLegNextLegsArgs(environment.getArguments()); @@ -307,7 +316,7 @@ public DataFetcher> nextLegs() { environment.getSource(), numberOfLegs, environment.getContext().transitService(), - false, + includeDepartBefore, AlternativeLegsFilter.NO_FILTER, limitToExactOriginStop, limitToExactDestinationStop diff --git a/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLDataFetchers.java b/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLDataFetchers.java index 67944543580..d39be5ed728 100644 --- a/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLDataFetchers.java +++ b/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLDataFetchers.java @@ -1,9 +1,11 @@ //THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. package org.opentripplanner.apis.gtfs.generated; +import graphql.relay.Connection; import graphql.relay.Connection; import graphql.relay.DefaultEdge; import graphql.relay.Edge; +import graphql.relay.Edge; import graphql.schema.DataFetcher; import graphql.schema.TypeResolver; import java.util.Currency; @@ -24,8 +26,12 @@ import org.opentripplanner.apis.gtfs.model.FeedPublisher; import org.opentripplanner.apis.gtfs.model.PlanPageInfo; import org.opentripplanner.apis.gtfs.model.RideHailingProvider; +import org.opentripplanner.apis.gtfs.model.RouteTypeModel; +import org.opentripplanner.apis.gtfs.model.StopOnRouteModel; +import org.opentripplanner.apis.gtfs.model.StopOnTripModel; import org.opentripplanner.apis.gtfs.model.StopPosition; import org.opentripplanner.apis.gtfs.model.TripOccupancy; +import org.opentripplanner.apis.gtfs.model.UnknownModel; import org.opentripplanner.ext.fares.model.FareRuleSet; import org.opentripplanner.ext.ridehailing.model.RideEstimate; import org.opentripplanner.model.StopTimesInPattern; @@ -48,6 +54,8 @@ import org.opentripplanner.routing.graphfinder.PatternAtStop; import org.opentripplanner.routing.graphfinder.PlaceAtDistance; import org.opentripplanner.routing.vehicle_parking.VehicleParking; +import org.opentripplanner.routing.vehicle_parking.VehicleParking; +import org.opentripplanner.routing.vehicle_parking.VehicleParking; import org.opentripplanner.routing.vehicle_parking.VehicleParkingSpaces; import org.opentripplanner.routing.vehicle_parking.VehicleParkingState; import org.opentripplanner.service.realtimevehicles.model.RealtimeVehicle; @@ -58,6 +66,7 @@ import org.opentripplanner.service.vehiclerental.model.VehicleRentalPlace; import org.opentripplanner.service.vehiclerental.model.VehicleRentalStation; import org.opentripplanner.service.vehiclerental.model.VehicleRentalStationUris; +import org.opentripplanner.service.vehiclerental.model.VehicleRentalStationUris; import org.opentripplanner.service.vehiclerental.model.VehicleRentalSystem; import org.opentripplanner.service.vehiclerental.model.VehicleRentalVehicle; import org.opentripplanner.transit.model.basic.Money; @@ -500,6 +509,8 @@ public interface GraphQLLeg { public DataFetcher pickupType(); + public DataFetcher> previousLegs(); + public DataFetcher realTime(); public DataFetcher realtimeState(); diff --git a/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLTypes.java b/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLTypes.java index 67051444cdf..ed9c25ae5f3 100644 --- a/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLTypes.java +++ b/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLTypes.java @@ -1,6 +1,7 @@ // THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. package org.opentripplanner.apis.gtfs.generated; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -1268,6 +1269,69 @@ public void setGraphQLOriginModesWithParentStation( } } + public static class GraphQLLegPreviousLegsArgs { + + private List destinationModesWithParentStation; + private Integer numberOfLegs; + private List originModesWithParentStation; + + public GraphQLLegPreviousLegsArgs(Map args) { + if (args != null) { + if (args.get("destinationModesWithParentStation") != null) { + this.destinationModesWithParentStation = + ((List) args.get("destinationModesWithParentStation")).stream() + .map(item -> + item instanceof GraphQLTransitMode + ? item + : GraphQLTransitMode.valueOf((String) item) + ) + .map(GraphQLTransitMode.class::cast) + .collect(Collectors.toList()); + } + this.numberOfLegs = (Integer) args.get("numberOfLegs"); + if (args.get("originModesWithParentStation") != null) { + this.originModesWithParentStation = + ((List) args.get("originModesWithParentStation")).stream() + .map(item -> + item instanceof GraphQLTransitMode + ? item + : GraphQLTransitMode.valueOf((String) item) + ) + .map(GraphQLTransitMode.class::cast) + .collect(Collectors.toList()); + } + } + } + + public List getGraphQLDestinationModesWithParentStation() { + return this.destinationModesWithParentStation; + } + + public Integer getGraphQLNumberOfLegs() { + return this.numberOfLegs; + } + + public List getGraphQLOriginModesWithParentStation() { + return this.originModesWithParentStation; + } + + public void setGraphQLDestinationModesWithParentStation( + List destinationModesWithParentStation + ) { + this.destinationModesWithParentStation = destinationModesWithParentStation; + } + + public void setGraphQLNumberOfLegs(Integer numberOfLegs) { + this.numberOfLegs = numberOfLegs; + } + + public void setGraphQLOriginModesWithParentStation( + List originModesWithParentStation + ) { + this.originModesWithParentStation = originModesWithParentStation; + } + } + public static class GraphQLLocalDateRangeInput { private java.time.LocalDate end; diff --git a/src/main/resources/org/opentripplanner/apis/gtfs/schema.graphqls b/src/main/resources/org/opentripplanner/apis/gtfs/schema.graphqls index 927af19f8b1..90b40cfe9a6 100644 --- a/src/main/resources/org/opentripplanner/apis/gtfs/schema.graphqls +++ b/src/main/resources/org/opentripplanner/apis/gtfs/schema.graphqls @@ -717,6 +717,24 @@ type Leg { pickupBookingInfo: BookingInfo "This is used to indicate if boarding this leg is possible only with special arrangements." pickupType: PickupDropoffType + "Previous legs with same origin and destination stops or stations" + previousLegs( + """ + Transportation modes for which all stops in the parent station are used as possible destination stops + for the previous legs. For modes not listed, only the exact destination stop of the leg is considered. + """ + destinationModesWithParentStation: [TransitMode!], + """ + The number of alternative legs searched. If fewer than the requested number are found, + then only the found legs are returned. + """ + numberOfLegs: Int!, + """ + Transportation modes for which all stops in the parent station are used as possible origin stops + for the previous legs. For modes not listed, only the exact origin stop of the leg is considered. + """ + originModesWithParentStation: [TransitMode!] + ): [Leg!] "Whether there is real-time data about this Leg" realTime: Boolean "State of real-time data" From 364a085cc09367ec8a86fac57f78e6d46d13b0ca Mon Sep 17 00:00:00 2001 From: Michael Tsang Date: Fri, 11 Oct 2024 15:30:55 +0100 Subject: [PATCH 2/9] remove duplicate imports from generated files --- .../apis/gtfs/generated/GraphQLDataFetchers.java | 9 --------- .../apis/gtfs/generated/GraphQLTypes.java | 1 - 2 files changed, 10 deletions(-) diff --git a/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLDataFetchers.java b/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLDataFetchers.java index d39be5ed728..d501d2e5cea 100644 --- a/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLDataFetchers.java +++ b/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLDataFetchers.java @@ -1,11 +1,9 @@ //THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. package org.opentripplanner.apis.gtfs.generated; -import graphql.relay.Connection; import graphql.relay.Connection; import graphql.relay.DefaultEdge; import graphql.relay.Edge; -import graphql.relay.Edge; import graphql.schema.DataFetcher; import graphql.schema.TypeResolver; import java.util.Currency; @@ -26,12 +24,8 @@ import org.opentripplanner.apis.gtfs.model.FeedPublisher; import org.opentripplanner.apis.gtfs.model.PlanPageInfo; import org.opentripplanner.apis.gtfs.model.RideHailingProvider; -import org.opentripplanner.apis.gtfs.model.RouteTypeModel; -import org.opentripplanner.apis.gtfs.model.StopOnRouteModel; -import org.opentripplanner.apis.gtfs.model.StopOnTripModel; import org.opentripplanner.apis.gtfs.model.StopPosition; import org.opentripplanner.apis.gtfs.model.TripOccupancy; -import org.opentripplanner.apis.gtfs.model.UnknownModel; import org.opentripplanner.ext.fares.model.FareRuleSet; import org.opentripplanner.ext.ridehailing.model.RideEstimate; import org.opentripplanner.model.StopTimesInPattern; @@ -54,8 +48,6 @@ import org.opentripplanner.routing.graphfinder.PatternAtStop; import org.opentripplanner.routing.graphfinder.PlaceAtDistance; import org.opentripplanner.routing.vehicle_parking.VehicleParking; -import org.opentripplanner.routing.vehicle_parking.VehicleParking; -import org.opentripplanner.routing.vehicle_parking.VehicleParking; import org.opentripplanner.routing.vehicle_parking.VehicleParkingSpaces; import org.opentripplanner.routing.vehicle_parking.VehicleParkingState; import org.opentripplanner.service.realtimevehicles.model.RealtimeVehicle; @@ -66,7 +58,6 @@ import org.opentripplanner.service.vehiclerental.model.VehicleRentalPlace; import org.opentripplanner.service.vehiclerental.model.VehicleRentalStation; import org.opentripplanner.service.vehiclerental.model.VehicleRentalStationUris; -import org.opentripplanner.service.vehiclerental.model.VehicleRentalStationUris; import org.opentripplanner.service.vehiclerental.model.VehicleRentalSystem; import org.opentripplanner.service.vehiclerental.model.VehicleRentalVehicle; import org.opentripplanner.transit.model.basic.Money; diff --git a/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLTypes.java b/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLTypes.java index ed9c25ae5f3..412a8831149 100644 --- a/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLTypes.java +++ b/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLTypes.java @@ -1,7 +1,6 @@ // THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. package org.opentripplanner.apis.gtfs.generated; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; From c715329f7052b82cc6e709b525cdcc8d34ec7a64 Mon Sep 17 00:00:00 2001 From: Michael Tsang Date: Tue, 29 Oct 2024 13:51:23 +0000 Subject: [PATCH 3/9] use an enum instead of boolean to switch next / previous alternative legs --- .../apis/gtfs/datafetchers/LegImpl.java | 8 ++-- .../gtfs/generated/GraphQLDataFetchers.java | 9 +++++ .../apis/gtfs/generated/GraphQLTypes.java | 1 + .../apis/transmodel/model/plan/LegType.java | 5 ++- .../alternativelegs/AlternativeLegs.java | 40 +++++++------------ .../stoptimes/AlternativeLegsTest.java | 8 ++-- 6 files changed, 36 insertions(+), 35 deletions(-) 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 22f9cc3f764..a7e7e16aaa7 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 @@ -277,15 +277,15 @@ private Leg getSource(DataFetchingEnvironment environment) { @Override public DataFetcher> previousLegs() { - return nextOrPreviousLegs(true); + return nextOrPreviousLegs(AlternativeLegs.SearchMode.PREVIOUS); } @Override public DataFetcher> nextLegs() { - return nextOrPreviousLegs(false); + return nextOrPreviousLegs(AlternativeLegs.SearchMode.NEXT); } - private DataFetcher> nextOrPreviousLegs(boolean includeDepartBefore) { + private DataFetcher> nextOrPreviousLegs(AlternativeLegs.SearchMode searchMode) { return environment -> { if (environment.getSource() instanceof ScheduledTransitLeg originalLeg) { var args = new GraphQLTypes.GraphQLLegNextLegsArgs(environment.getArguments()); @@ -320,7 +320,7 @@ private DataFetcher> nextOrPreviousLegs(boolean includeDepartBefor environment.getSource(), numberOfLegs, environment.getContext().transitService(), - includeDepartBefore, + searchMode, AlternativeLegsFilter.NO_FILTER, limitToExactOriginStop, limitToExactDestinationStop diff --git a/application/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLDataFetchers.java b/application/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLDataFetchers.java index 235b1d2bb14..ad686dec9a9 100644 --- a/application/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLDataFetchers.java +++ b/application/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLDataFetchers.java @@ -1,9 +1,11 @@ //THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. package org.opentripplanner.apis.gtfs.generated; +import graphql.relay.Connection; import graphql.relay.Connection; import graphql.relay.DefaultEdge; import graphql.relay.Edge; +import graphql.relay.Edge; import graphql.schema.DataFetcher; import graphql.schema.TypeResolver; import java.util.Currency; @@ -25,8 +27,12 @@ import org.opentripplanner.apis.gtfs.model.FeedPublisher; import org.opentripplanner.apis.gtfs.model.PlanPageInfo; import org.opentripplanner.apis.gtfs.model.RideHailingProvider; +import org.opentripplanner.apis.gtfs.model.RouteTypeModel; +import org.opentripplanner.apis.gtfs.model.StopOnRouteModel; +import org.opentripplanner.apis.gtfs.model.StopOnTripModel; import org.opentripplanner.apis.gtfs.model.StopPosition; import org.opentripplanner.apis.gtfs.model.TripOccupancy; +import org.opentripplanner.apis.gtfs.model.UnknownModel; import org.opentripplanner.ext.fares.model.FareRuleSet; import org.opentripplanner.ext.ridehailing.model.RideEstimate; import org.opentripplanner.model.StopTimesInPattern; @@ -49,6 +55,8 @@ import org.opentripplanner.routing.graphfinder.PatternAtStop; import org.opentripplanner.routing.graphfinder.PlaceAtDistance; import org.opentripplanner.routing.vehicle_parking.VehicleParking; +import org.opentripplanner.routing.vehicle_parking.VehicleParking; +import org.opentripplanner.routing.vehicle_parking.VehicleParking; import org.opentripplanner.routing.vehicle_parking.VehicleParkingSpaces; import org.opentripplanner.routing.vehicle_parking.VehicleParkingState; import org.opentripplanner.service.realtimevehicles.model.RealtimeVehicle; @@ -59,6 +67,7 @@ import org.opentripplanner.service.vehiclerental.model.VehicleRentalPlace; import org.opentripplanner.service.vehiclerental.model.VehicleRentalStation; import org.opentripplanner.service.vehiclerental.model.VehicleRentalStationUris; +import org.opentripplanner.service.vehiclerental.model.VehicleRentalStationUris; import org.opentripplanner.service.vehiclerental.model.VehicleRentalSystem; import org.opentripplanner.service.vehiclerental.model.VehicleRentalVehicle; import org.opentripplanner.transit.model.basic.Money; diff --git a/application/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLTypes.java b/application/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLTypes.java index 83d052ccb7b..a47ee0ab063 100644 --- a/application/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLTypes.java +++ b/application/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLTypes.java @@ -1,6 +1,7 @@ // THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. package org.opentripplanner.apis.gtfs.generated; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; 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 5bf56f75e4b..f511ca37e38 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,6 +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.SearchMode; public class LegType { @@ -485,7 +486,7 @@ public static GraphQLObjectType create( leg, env.getArgument("previous"), GqlUtil.getTransitService(env), - true, + SearchMode.PREVIOUS, env.getArgument("filter") ); }) @@ -525,7 +526,7 @@ public static GraphQLObjectType create( leg, env.getArgument("next"), GqlUtil.getTransitService(env), - false, + SearchMode.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 465ed230884..6c12fafe59f 100644 --- a/application/src/main/java/org/opentripplanner/routing/alternativelegs/AlternativeLegs.java +++ b/application/src/main/java/org/opentripplanner/routing/alternativelegs/AlternativeLegs.java @@ -39,24 +39,21 @@ */ public class AlternativeLegs { + public enum SearchMode { + NEXT, + PREVIOUS, + } + public static final int ZERO_COST = 0; public static List getAlternativeLegs( Leg leg, Integer numberLegs, TransitService transitService, - boolean searchBackward, + SearchMode searchMode, AlternativeLegsFilter filter ) { - return getAlternativeLegs( - leg, - numberLegs, - transitService, - searchBackward, - filter, - false, - false - ); + return getAlternativeLegs(leg, numberLegs, transitService, searchMode, filter, false, false); } /** @@ -66,9 +63,8 @@ public static List getAlternativeLegs( * @param numberLegs The number of alternative legs requested. If fewer legs are found, * only the found legs are returned. * @param transitService The transit service used for the search - * @param includeDepartBefore Boolean indicating whether the alternative legs should depart - * earlier or later than the original leg True if earlier, false if - * later. + * @param searchMode Indicating whether the alternative legs should depart + * earlier (PREVIOUS) or later (NEXT) than the original. * @param filter AlternativeLegsFilter indicating which properties of the original * leg should not change in the alternative legs * @param exactOriginStop Boolean indicating whether the exact departure stop of the original @@ -82,7 +78,7 @@ public static List getAlternativeLegs( Leg leg, Integer numberLegs, TransitService transitService, - boolean includeDepartBefore, + SearchMode searchMode, AlternativeLegsFilter filter, boolean exactOriginStop, boolean exactDestinationStop @@ -105,7 +101,7 @@ public static List getAlternativeLegs( ScheduledTransitLeg::getStartTime ); - if (includeDepartBefore) { + if (searchMode == SearchMode.PREVIOUS) { legComparator = legComparator.reversed(); } @@ -119,13 +115,7 @@ public static List getAlternativeLegs( .distinct() .flatMap(tripPattern -> withBoardingAlightingPositions(origins, destinations, tripPattern)) .flatMap(t -> - generateLegs( - transitService, - t, - leg.getStartTime(), - leg.getServiceDate(), - includeDepartBefore - ) + generateLegs(transitService, t, leg.getStartTime(), leg.getServiceDate(), searchMode) ) .filter(Predicate.not(leg::isPartiallySameTransitLeg)) .sorted(legComparator) @@ -142,7 +132,7 @@ private static Stream generateLegs( TripPatternBetweenStops tripPatternBetweenStops, ZonedDateTime departureTime, LocalDate originalDate, - boolean includeDepartBefore + SearchMode searchMode ) { TripPattern pattern = tripPatternBetweenStops.tripPattern; int boardingPosition = tripPatternBetweenStops.positions.boardingPosition; @@ -155,7 +145,7 @@ private static Stream generateLegs( tts.getServiceDayMidnight() + tts.getRealtimeDeparture() ); - if (includeDepartBefore) { + if (searchMode == SearchMode.PREVIOUS) { comparator = comparator.reversed(); } @@ -185,7 +175,7 @@ private static Stream generateLegs( continue; } - boolean departureTimeInRange = includeDepartBefore + boolean departureTimeInRange = searchMode == SearchMode.PREVIOUS ? tripTimes.getDepartureTime(boardingPosition) <= secondsSinceMidnight : tripTimes.getDepartureTime(boardingPosition) >= secondsSinceMidnight; 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 055fba784a9..aedb98725d7 100644 --- a/application/src/test/java/org/opentripplanner/routing/stoptimes/AlternativeLegsTest.java +++ b/application/src/test/java/org/opentripplanner/routing/stoptimes/AlternativeLegsTest.java @@ -51,7 +51,7 @@ void testPreviousLegs() { originalLeg, 3, transitService, - true, + AlternativeLegs.SearchMode.PREVIOUS, AlternativeLegsFilter.NO_FILTER ); @@ -85,7 +85,7 @@ void testNextLegs() { originalLeg, 3, transitService, - false, + AlternativeLegs.SearchMode.NEXT, AlternativeLegsFilter.NO_FILTER ); @@ -119,7 +119,7 @@ void testCircularRoutes() { originalLeg, 2, transitService, - false, + AlternativeLegs.SearchMode.NEXT, AlternativeLegsFilter.NO_FILTER ); @@ -147,7 +147,7 @@ void testComplexCircularRoutes() { originalLeg, 2, transitService, - false, + AlternativeLegs.SearchMode.NEXT, AlternativeLegsFilter.NO_FILTER ); var legs = toString(alternativeLegs); From 22c1f73d5b697d6516a1f0c56b85671834576854 Mon Sep 17 00:00:00 2001 From: Michael Tsang Date: Tue, 29 Oct 2024 15:20:12 +0000 Subject: [PATCH 4/9] rename nextOrPreviousLegs to alternativeLegs --- .../org/opentripplanner/apis/gtfs/datafetchers/LegImpl.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 a7e7e16aaa7..235de3ebf55 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 @@ -277,15 +277,15 @@ private Leg getSource(DataFetchingEnvironment environment) { @Override public DataFetcher> previousLegs() { - return nextOrPreviousLegs(AlternativeLegs.SearchMode.PREVIOUS); + return alternativeLegs(AlternativeLegs.SearchMode.PREVIOUS); } @Override public DataFetcher> nextLegs() { - return nextOrPreviousLegs(AlternativeLegs.SearchMode.NEXT); + return alternativeLegs(AlternativeLegs.SearchMode.NEXT); } - private DataFetcher> nextOrPreviousLegs(AlternativeLegs.SearchMode searchMode) { + private DataFetcher> alternativeLegs(AlternativeLegs.SearchMode searchMode) { return environment -> { if (environment.getSource() instanceof ScheduledTransitLeg originalLeg) { var args = new GraphQLTypes.GraphQLLegNextLegsArgs(environment.getArguments()); From 30c787b86c0a2729cc3b79ab5fe42bf22dfffab7 Mon Sep 17 00:00:00 2001 From: Michael Tsang Date: Tue, 29 Oct 2024 15:23:04 +0000 Subject: [PATCH 5/9] rename SearchMode to SearchDirection --- .../apis/gtfs/datafetchers/LegImpl.java | 10 ++++--- .../apis/transmodel/model/plan/LegType.java | 6 ++-- .../alternativelegs/AlternativeLegs.java | 28 ++++++++++++------- .../stoptimes/AlternativeLegsTest.java | 8 +++--- 4 files changed, 31 insertions(+), 21 deletions(-) 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 235de3ebf55..5548ca5ff59 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 @@ -277,15 +277,17 @@ private Leg getSource(DataFetchingEnvironment environment) { @Override public DataFetcher> previousLegs() { - return alternativeLegs(AlternativeLegs.SearchMode.PREVIOUS); + return alternativeLegs(AlternativeLegs.SearchDirection.PREVIOUS); } @Override public DataFetcher> nextLegs() { - return alternativeLegs(AlternativeLegs.SearchMode.NEXT); + return alternativeLegs(AlternativeLegs.SearchDirection.NEXT); } - private DataFetcher> alternativeLegs(AlternativeLegs.SearchMode searchMode) { + private DataFetcher> alternativeLegs( + AlternativeLegs.SearchDirection searchDirection + ) { return environment -> { if (environment.getSource() instanceof ScheduledTransitLeg originalLeg) { var args = new GraphQLTypes.GraphQLLegNextLegsArgs(environment.getArguments()); @@ -320,7 +322,7 @@ private DataFetcher> alternativeLegs(AlternativeLegs.SearchMode se environment.getSource(), numberOfLegs, environment.getContext().transitService(), - searchMode, + searchDirection, AlternativeLegsFilter.NO_FILTER, limitToExactOriginStop, limitToExactDestinationStop 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 f511ca37e38..6ba90ea8b09 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.SearchMode; +import org.opentripplanner.routing.alternativelegs.AlternativeLegs.SearchDirection; public class LegType { @@ -486,7 +486,7 @@ public static GraphQLObjectType create( leg, env.getArgument("previous"), GqlUtil.getTransitService(env), - SearchMode.PREVIOUS, + SearchDirection.PREVIOUS, env.getArgument("filter") ); }) @@ -526,7 +526,7 @@ public static GraphQLObjectType create( leg, env.getArgument("next"), GqlUtil.getTransitService(env), - SearchMode.NEXT, + SearchDirection.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 6c12fafe59f..10ae389894f 100644 --- a/application/src/main/java/org/opentripplanner/routing/alternativelegs/AlternativeLegs.java +++ b/application/src/main/java/org/opentripplanner/routing/alternativelegs/AlternativeLegs.java @@ -39,7 +39,7 @@ */ public class AlternativeLegs { - public enum SearchMode { + public enum SearchDirection { NEXT, PREVIOUS, } @@ -50,10 +50,18 @@ public static List getAlternativeLegs( Leg leg, Integer numberLegs, TransitService transitService, - SearchMode searchMode, + SearchDirection searchDirection, AlternativeLegsFilter filter ) { - return getAlternativeLegs(leg, numberLegs, transitService, searchMode, filter, false, false); + return getAlternativeLegs( + leg, + numberLegs, + transitService, + searchDirection, + filter, + false, + false + ); } /** @@ -63,7 +71,7 @@ public static List getAlternativeLegs( * @param numberLegs The number of alternative legs requested. If fewer legs are found, * only the found legs are returned. * @param transitService The transit service used for the search - * @param searchMode Indicating whether the alternative legs should depart + * @param searchDirection Indicating whether the alternative legs should depart * earlier (PREVIOUS) or later (NEXT) than the original. * @param filter AlternativeLegsFilter indicating which properties of the original * leg should not change in the alternative legs @@ -78,7 +86,7 @@ public static List getAlternativeLegs( Leg leg, Integer numberLegs, TransitService transitService, - SearchMode searchMode, + SearchDirection searchDirection, AlternativeLegsFilter filter, boolean exactOriginStop, boolean exactDestinationStop @@ -101,7 +109,7 @@ public static List getAlternativeLegs( ScheduledTransitLeg::getStartTime ); - if (searchMode == SearchMode.PREVIOUS) { + if (searchDirection == SearchDirection.PREVIOUS) { legComparator = legComparator.reversed(); } @@ -115,7 +123,7 @@ public static List getAlternativeLegs( .distinct() .flatMap(tripPattern -> withBoardingAlightingPositions(origins, destinations, tripPattern)) .flatMap(t -> - generateLegs(transitService, t, leg.getStartTime(), leg.getServiceDate(), searchMode) + generateLegs(transitService, t, leg.getStartTime(), leg.getServiceDate(), searchDirection) ) .filter(Predicate.not(leg::isPartiallySameTransitLeg)) .sorted(legComparator) @@ -132,7 +140,7 @@ private static Stream generateLegs( TripPatternBetweenStops tripPatternBetweenStops, ZonedDateTime departureTime, LocalDate originalDate, - SearchMode searchMode + SearchDirection searchDirection ) { TripPattern pattern = tripPatternBetweenStops.tripPattern; int boardingPosition = tripPatternBetweenStops.positions.boardingPosition; @@ -145,7 +153,7 @@ private static Stream generateLegs( tts.getServiceDayMidnight() + tts.getRealtimeDeparture() ); - if (searchMode == SearchMode.PREVIOUS) { + if (searchDirection == SearchDirection.PREVIOUS) { comparator = comparator.reversed(); } @@ -175,7 +183,7 @@ private static Stream generateLegs( continue; } - boolean departureTimeInRange = searchMode == SearchMode.PREVIOUS + boolean departureTimeInRange = searchDirection == SearchDirection.PREVIOUS ? tripTimes.getDepartureTime(boardingPosition) <= secondsSinceMidnight : tripTimes.getDepartureTime(boardingPosition) >= secondsSinceMidnight; 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 aedb98725d7..c9833eae3a5 100644 --- a/application/src/test/java/org/opentripplanner/routing/stoptimes/AlternativeLegsTest.java +++ b/application/src/test/java/org/opentripplanner/routing/stoptimes/AlternativeLegsTest.java @@ -51,7 +51,7 @@ void testPreviousLegs() { originalLeg, 3, transitService, - AlternativeLegs.SearchMode.PREVIOUS, + AlternativeLegs.SearchDirection.PREVIOUS, AlternativeLegsFilter.NO_FILTER ); @@ -85,7 +85,7 @@ void testNextLegs() { originalLeg, 3, transitService, - AlternativeLegs.SearchMode.NEXT, + AlternativeLegs.SearchDirection.NEXT, AlternativeLegsFilter.NO_FILTER ); @@ -119,7 +119,7 @@ void testCircularRoutes() { originalLeg, 2, transitService, - AlternativeLegs.SearchMode.NEXT, + AlternativeLegs.SearchDirection.NEXT, AlternativeLegsFilter.NO_FILTER ); @@ -147,7 +147,7 @@ void testComplexCircularRoutes() { originalLeg, 2, transitService, - AlternativeLegs.SearchMode.NEXT, + AlternativeLegs.SearchDirection.NEXT, AlternativeLegsFilter.NO_FILTER ); var legs = toString(alternativeLegs); From 0482fb74645c2c2701ab0eac35e6de01029a1d99 Mon Sep 17 00:00:00 2001 From: Michael Tsang Date: Tue, 5 Nov 2024 14:29:18 +0000 Subject: [PATCH 6/9] move SearchDirection to a separate class and rename to SearchTime --- .../apis/gtfs/datafetchers/LegImpl.java | 7 ++++--- .../apis/transmodel/model/plan/LegType.java | 6 +++--- .../alternativelegs/AlternativeLegs.java | 17 ++++++----------- .../routing/alternativelegs/SearchTime.java | 6 ++++++ .../routing/stoptimes/AlternativeLegsTest.java | 9 +++++---- 5 files changed, 24 insertions(+), 21 deletions(-) create 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 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); From e1299348356e0f57f53ef418322506c92a3e10ab Mon Sep 17 00:00:00 2001 From: Michael Tsang Date: Tue, 5 Nov 2024 14:33:35 +0000 Subject: [PATCH 7/9] move SearchDirection to a separate class and rename to SearchTime --- .../apis/gtfs/datafetchers/LegImpl.java | 6 ++-- .../gtfs/generated/GraphQLDataFetchers.java | 9 ------ .../apis/gtfs/generated/GraphQLTypes.java | 1 - .../alternativelegs/AlternativeLegs.java | 28 +++++++------------ 4 files changed, 12 insertions(+), 32 deletions(-) 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 3f1255d9985..54a40cef843 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 @@ -286,9 +286,7 @@ public DataFetcher> nextLegs() { return alternativeLegs(SearchTime.AFTER); } - private DataFetcher> alternativeLegs( - SearchTime searchDirection - ) { + private DataFetcher> alternativeLegs(SearchTime timeLine) { return environment -> { if (environment.getSource() instanceof ScheduledTransitLeg originalLeg) { var args = new GraphQLTypes.GraphQLLegNextLegsArgs(environment.getArguments()); @@ -323,7 +321,7 @@ private DataFetcher> alternativeLegs( environment.getSource(), numberOfLegs, environment.getContext().transitService(), - searchDirection, + timeLine, AlternativeLegsFilter.NO_FILTER, limitToExactOriginStop, limitToExactDestinationStop diff --git a/application/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLDataFetchers.java b/application/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLDataFetchers.java index ad686dec9a9..235b1d2bb14 100644 --- a/application/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLDataFetchers.java +++ b/application/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLDataFetchers.java @@ -1,11 +1,9 @@ //THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. package org.opentripplanner.apis.gtfs.generated; -import graphql.relay.Connection; import graphql.relay.Connection; import graphql.relay.DefaultEdge; import graphql.relay.Edge; -import graphql.relay.Edge; import graphql.schema.DataFetcher; import graphql.schema.TypeResolver; import java.util.Currency; @@ -27,12 +25,8 @@ import org.opentripplanner.apis.gtfs.model.FeedPublisher; import org.opentripplanner.apis.gtfs.model.PlanPageInfo; import org.opentripplanner.apis.gtfs.model.RideHailingProvider; -import org.opentripplanner.apis.gtfs.model.RouteTypeModel; -import org.opentripplanner.apis.gtfs.model.StopOnRouteModel; -import org.opentripplanner.apis.gtfs.model.StopOnTripModel; import org.opentripplanner.apis.gtfs.model.StopPosition; import org.opentripplanner.apis.gtfs.model.TripOccupancy; -import org.opentripplanner.apis.gtfs.model.UnknownModel; import org.opentripplanner.ext.fares.model.FareRuleSet; import org.opentripplanner.ext.ridehailing.model.RideEstimate; import org.opentripplanner.model.StopTimesInPattern; @@ -55,8 +49,6 @@ import org.opentripplanner.routing.graphfinder.PatternAtStop; import org.opentripplanner.routing.graphfinder.PlaceAtDistance; import org.opentripplanner.routing.vehicle_parking.VehicleParking; -import org.opentripplanner.routing.vehicle_parking.VehicleParking; -import org.opentripplanner.routing.vehicle_parking.VehicleParking; import org.opentripplanner.routing.vehicle_parking.VehicleParkingSpaces; import org.opentripplanner.routing.vehicle_parking.VehicleParkingState; import org.opentripplanner.service.realtimevehicles.model.RealtimeVehicle; @@ -67,7 +59,6 @@ import org.opentripplanner.service.vehiclerental.model.VehicleRentalPlace; import org.opentripplanner.service.vehiclerental.model.VehicleRentalStation; import org.opentripplanner.service.vehiclerental.model.VehicleRentalStationUris; -import org.opentripplanner.service.vehiclerental.model.VehicleRentalStationUris; import org.opentripplanner.service.vehiclerental.model.VehicleRentalSystem; import org.opentripplanner.service.vehiclerental.model.VehicleRentalVehicle; import org.opentripplanner.transit.model.basic.Money; diff --git a/application/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLTypes.java b/application/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLTypes.java index 5b55ff01fb7..675230876dc 100644 --- a/application/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLTypes.java +++ b/application/src/main/java/org/opentripplanner/apis/gtfs/generated/GraphQLTypes.java @@ -1,7 +1,6 @@ // THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. package org.opentripplanner.apis.gtfs.generated; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; 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 7a1c45684cd..b71287a1c0e 100644 --- a/application/src/main/java/org/opentripplanner/routing/alternativelegs/AlternativeLegs.java +++ b/application/src/main/java/org/opentripplanner/routing/alternativelegs/AlternativeLegs.java @@ -45,18 +45,10 @@ public static List getAlternativeLegs( Leg leg, Integer numberLegs, TransitService transitService, - SearchTime searchDirection, + SearchTime timeLine, AlternativeLegsFilter filter ) { - return getAlternativeLegs( - leg, - numberLegs, - transitService, - searchDirection, - filter, - false, - false - ); + return getAlternativeLegs(leg, numberLegs, transitService, timeLine, filter, false, false); } /** @@ -66,8 +58,8 @@ public static List getAlternativeLegs( * @param numberLegs The number of alternative legs requested. If fewer legs are found, * only the found legs are returned. * @param transitService The transit service used for the search - * @param searchDirection Indicating whether the alternative legs should depart - * earlier (PREVIOUS) or later (NEXT) than the original. + * @param timeLine Indicating whether the alternative legs should depart before or + * after than the original. * @param filter AlternativeLegsFilter indicating which properties of the original * leg should not change in the alternative legs * @param exactOriginStop Boolean indicating whether the exact departure stop of the original @@ -81,7 +73,7 @@ public static List getAlternativeLegs( Leg leg, Integer numberLegs, TransitService transitService, - SearchTime searchDirection, + SearchTime timeLine, AlternativeLegsFilter filter, boolean exactOriginStop, boolean exactDestinationStop @@ -104,7 +96,7 @@ public static List getAlternativeLegs( ScheduledTransitLeg::getStartTime ); - if (searchDirection == SearchTime.BEFORE) { + if (timeLine == SearchTime.BEFORE) { legComparator = legComparator.reversed(); } @@ -118,7 +110,7 @@ public static List getAlternativeLegs( .distinct() .flatMap(tripPattern -> withBoardingAlightingPositions(origins, destinations, tripPattern)) .flatMap(t -> - generateLegs(transitService, t, leg.getStartTime(), leg.getServiceDate(), searchDirection) + generateLegs(transitService, t, leg.getStartTime(), leg.getServiceDate(), timeLine) ) .filter(Predicate.not(leg::isPartiallySameTransitLeg)) .sorted(legComparator) @@ -135,7 +127,7 @@ private static Stream generateLegs( TripPatternBetweenStops tripPatternBetweenStops, ZonedDateTime departureTime, LocalDate originalDate, - SearchTime searchDirection + SearchTime timeLine ) { TripPattern pattern = tripPatternBetweenStops.tripPattern; int boardingPosition = tripPatternBetweenStops.positions.boardingPosition; @@ -148,7 +140,7 @@ private static Stream generateLegs( tts.getServiceDayMidnight() + tts.getRealtimeDeparture() ); - if (searchDirection == SearchTime.BEFORE) { + if (timeLine == SearchTime.BEFORE) { comparator = comparator.reversed(); } @@ -178,7 +170,7 @@ private static Stream generateLegs( continue; } - boolean departureTimeInRange = searchDirection == SearchTime.BEFORE + boolean departureTimeInRange = timeLine == SearchTime.BEFORE ? tripTimes.getDepartureTime(boardingPosition) <= secondsSinceMidnight : tripTimes.getDepartureTime(boardingPosition) >= secondsSinceMidnight; From 64d39784663e3539d58b9d55c0c175c96ce6a1cc Mon Sep 17 00:00:00 2001 From: Michael Tsang Date: Mon, 11 Nov 2024 15:02:03 +0000 Subject: [PATCH 8/9] 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 | 16 ++++++++++++++++ .../routing/alternativelegs/SearchTime.java | 6 ------ .../routing/stoptimes/AlternativeLegsTest.java | 10 +++++----- 6 files changed, 34 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..8254e3e28b7 --- /dev/null +++ b/application/src/main/java/org/opentripplanner/routing/alternativelegs/NavigationDirection.java @@ -0,0 +1,16 @@ +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); From d437d6632c69ba49865584dc923492f79153175c Mon Sep 17 00:00:00 2001 From: Michael Tsang Date: Wed, 13 Nov 2024 15:21:29 +0000 Subject: [PATCH 9/9] rename parameters --- .../apis/gtfs/datafetchers/LegImpl.java | 4 ++-- .../alternativelegs/AlternativeLegs.java | 18 +++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) 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 b02ea12e525..5e892c06368 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 @@ -286,7 +286,7 @@ public DataFetcher> nextLegs() { return alternativeLegs(NavigationDirection.NEXT); } - private DataFetcher> alternativeLegs(NavigationDirection timeLine) { + private DataFetcher> alternativeLegs(NavigationDirection direction) { return environment -> { if (environment.getSource() instanceof ScheduledTransitLeg originalLeg) { var args = new GraphQLTypes.GraphQLLegNextLegsArgs(environment.getArguments()); @@ -321,7 +321,7 @@ private DataFetcher> alternativeLegs(NavigationDirection timeLine) environment.getSource(), numberOfLegs, environment.getContext().transitService(), - timeLine, + direction, AlternativeLegsFilter.NO_FILTER, limitToExactOriginStop, limitToExactDestinationStop 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 7b685cf8193..51af4a27f79 100644 --- a/application/src/main/java/org/opentripplanner/routing/alternativelegs/AlternativeLegs.java +++ b/application/src/main/java/org/opentripplanner/routing/alternativelegs/AlternativeLegs.java @@ -45,10 +45,10 @@ public static List getAlternativeLegs( Leg leg, Integer numberLegs, TransitService transitService, - NavigationDirection timeLine, + NavigationDirection direction, AlternativeLegsFilter filter ) { - return getAlternativeLegs(leg, numberLegs, transitService, timeLine, filter, false, false); + return getAlternativeLegs(leg, numberLegs, transitService, direction, filter, false, false); } /** @@ -58,7 +58,7 @@ public static List getAlternativeLegs( * @param numberLegs The number of alternative legs requested. If fewer legs are found, * only the found legs are returned. * @param transitService The transit service used for the search - * @param timeLine Indicating whether the alternative legs should depart before or + * @param direction Indicating whether the alternative legs should depart before or * after than the original. * @param filter AlternativeLegsFilter indicating which properties of the original * leg should not change in the alternative legs @@ -73,7 +73,7 @@ public static List getAlternativeLegs( Leg leg, Integer numberLegs, TransitService transitService, - NavigationDirection timeLine, + NavigationDirection direction, AlternativeLegsFilter filter, boolean exactOriginStop, boolean exactDestinationStop @@ -96,7 +96,7 @@ public static List getAlternativeLegs( ScheduledTransitLeg::getStartTime ); - if (timeLine == NavigationDirection.PREVIOUS) { + if (direction == NavigationDirection.PREVIOUS) { legComparator = legComparator.reversed(); } @@ -110,7 +110,7 @@ public static List getAlternativeLegs( .distinct() .flatMap(tripPattern -> withBoardingAlightingPositions(origins, destinations, tripPattern)) .flatMap(t -> - generateLegs(transitService, t, leg.getStartTime(), leg.getServiceDate(), timeLine) + generateLegs(transitService, t, leg.getStartTime(), leg.getServiceDate(), direction) ) .filter(Predicate.not(leg::isPartiallySameTransitLeg)) .sorted(legComparator) @@ -127,7 +127,7 @@ private static Stream generateLegs( TripPatternBetweenStops tripPatternBetweenStops, ZonedDateTime departureTime, LocalDate originalDate, - NavigationDirection timeLine + NavigationDirection direction ) { TripPattern pattern = tripPatternBetweenStops.tripPattern; int boardingPosition = tripPatternBetweenStops.positions.boardingPosition; @@ -140,7 +140,7 @@ private static Stream generateLegs( tts.getServiceDayMidnight() + tts.getRealtimeDeparture() ); - if (timeLine == NavigationDirection.PREVIOUS) { + if (direction == NavigationDirection.PREVIOUS) { comparator = comparator.reversed(); } @@ -170,7 +170,7 @@ private static Stream generateLegs( continue; } - boolean departureTimeInRange = timeLine == NavigationDirection.PREVIOUS + boolean departureTimeInRange = direction == NavigationDirection.PREVIOUS ? tripTimes.getDepartureTime(boardingPosition) <= secondsSinceMidnight : tripTimes.getDepartureTime(boardingPosition) >= secondsSinceMidnight;