Skip to content

Commit

Permalink
move SearchDirection to a separate class and rename to SearchTime
Browse files Browse the repository at this point in the history
  • Loading branch information
miklcct committed Nov 5, 2024
1 parent 0482fb7 commit a3f752d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,7 @@ public DataFetcher<Iterable<Leg>> nextLegs() {
return alternativeLegs(SearchTime.AFTER);
}

private DataFetcher<Iterable<Leg>> alternativeLegs(
SearchTime searchDirection
) {
private DataFetcher<Iterable<Leg>> alternativeLegs(SearchTime timeLine) {
return environment -> {
if (environment.getSource() instanceof ScheduledTransitLeg originalLeg) {
var args = new GraphQLTypes.GraphQLLegNextLegsArgs(environment.getArguments());
Expand Down Expand Up @@ -323,7 +321,7 @@ private DataFetcher<Iterable<Leg>> alternativeLegs(
environment.getSource(),
numberOfLegs,
environment.<GraphQLRequestContext>getContext().transitService(),
searchDirection,
timeLine,
AlternativeLegsFilter.NO_FILTER,
limitToExactOriginStop,
limitToExactDestinationStop
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ public static List<ScheduledTransitLeg> getAlternativeLegs(
Leg leg,
Integer numberLegs,
TransitService transitService,
SearchTime searchDirection,
SearchTime timeLine,
AlternativeLegsFilter filter
) {
return getAlternativeLegs(
leg,
numberLegs,
transitService,
searchDirection,
timeLine,
filter,
false,
false
Expand All @@ -66,8 +66,8 @@ public static List<ScheduledTransitLeg> 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
Expand All @@ -81,7 +81,7 @@ public static List<ScheduledTransitLeg> getAlternativeLegs(
Leg leg,
Integer numberLegs,
TransitService transitService,
SearchTime searchDirection,
SearchTime timeLine,
AlternativeLegsFilter filter,
boolean exactOriginStop,
boolean exactDestinationStop
Expand All @@ -104,7 +104,7 @@ public static List<ScheduledTransitLeg> getAlternativeLegs(
ScheduledTransitLeg::getStartTime
);

if (searchDirection == SearchTime.BEFORE) {
if (timeLine == SearchTime.BEFORE) {
legComparator = legComparator.reversed();
}

Expand All @@ -118,7 +118,7 @@ public static List<ScheduledTransitLeg> 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)
Expand All @@ -135,7 +135,7 @@ private static Stream<ScheduledTransitLeg> generateLegs(
TripPatternBetweenStops tripPatternBetweenStops,
ZonedDateTime departureTime,
LocalDate originalDate,
SearchTime searchDirection
SearchTime timeLine
) {
TripPattern pattern = tripPatternBetweenStops.tripPattern;
int boardingPosition = tripPatternBetweenStops.positions.boardingPosition;
Expand All @@ -148,7 +148,7 @@ private static Stream<ScheduledTransitLeg> generateLegs(
tts.getServiceDayMidnight() + tts.getRealtimeDeparture()
);

if (searchDirection == SearchTime.BEFORE) {
if (timeLine == SearchTime.BEFORE) {
comparator = comparator.reversed();
}

Expand Down Expand Up @@ -178,7 +178,7 @@ private static Stream<ScheduledTransitLeg> generateLegs(
continue;
}

boolean departureTimeInRange = searchDirection == SearchTime.BEFORE
boolean departureTimeInRange = timeLine == SearchTime.BEFORE
? tripTimes.getDepartureTime(boardingPosition) <= secondsSinceMidnight
: tripTimes.getDepartureTime(boardingPosition) >= secondsSinceMidnight;

Expand Down

0 comments on commit a3f752d

Please sign in to comment.