From 1e8b0f5ec079bd8fea5c4ccdb4de407c39cd434f Mon Sep 17 00:00:00 2001 From: eibakke Date: Tue, 5 Nov 2024 12:07:25 +0100 Subject: [PATCH 01/14] Implements a RegularStop matcher that can be used for filtering RegularStops. Also moves the envelope filtering that used to happen on the client side of the findRegularStops call into the StopModelIndex. --- .../ext/restapi/resources/IndexAPI.java | 1 - .../apis/gtfs/datafetchers/QueryTypeImpl.java | 3 +- .../transmodel/TransmodelGraphQLSchema.java | 52 +++++++++---------- .../transmodel/model/stop/StopPlaceType.java | 1 - .../api/request/RegularStopRequest.java | 39 ++++++++++++++ .../request/RegularStopRequestBuilder.java | 32 ++++++++++++ .../filter/expr/GenericUnaryMatcher.java | 33 ++++++++++++ .../transit/RegularStopMatcherFactory.java | 39 ++++++++++++++ .../service/DefaultTransitService.java | 16 ++++++ .../transit/service/StopModelIndex.java | 11 +++- .../transit/service/TransitService.java | 19 +++++-- .../apis/transmodel/schema.graphql | 1 + .../filter/expr/GenericUnaryMatcherTest.java | 15 ++++++ .../RegularStopMatcherFactoryTest.java | 44 ++++++++++++++++ 14 files changed, 268 insertions(+), 38 deletions(-) create mode 100644 application/src/main/java/org/opentripplanner/transit/api/request/RegularStopRequest.java create mode 100644 application/src/main/java/org/opentripplanner/transit/api/request/RegularStopRequestBuilder.java create mode 100644 application/src/main/java/org/opentripplanner/transit/model/filter/expr/GenericUnaryMatcher.java create mode 100644 application/src/main/java/org/opentripplanner/transit/model/filter/transit/RegularStopMatcherFactory.java create mode 100644 application/src/test/java/org/opentripplanner/transit/model/filter/expr/GenericUnaryMatcherTest.java create mode 100644 application/src/test/java/org/opentripplanner/transit/model/filter/transit/RegularStopMatcherFactoryTest.java diff --git a/application/src/ext/java/org/opentripplanner/ext/restapi/resources/IndexAPI.java b/application/src/ext/java/org/opentripplanner/ext/restapi/resources/IndexAPI.java index 7dbfabed156..c7bba3cbe27 100644 --- a/application/src/ext/java/org/opentripplanner/ext/restapi/resources/IndexAPI.java +++ b/application/src/ext/java/org/opentripplanner/ext/restapi/resources/IndexAPI.java @@ -224,7 +224,6 @@ public List getStopsInRadius( var stops = transitService().findRegularStops(envelope); return stops .stream() - .filter(stop -> envelope.contains(stop.getCoordinate().asJtsCoordinate())) .map(StopMapper::mapToApiShort) .toList(); } diff --git a/application/src/main/java/org/opentripplanner/apis/gtfs/datafetchers/QueryTypeImpl.java b/application/src/main/java/org/opentripplanner/apis/gtfs/datafetchers/QueryTypeImpl.java index d02d7b59ffa..b10680aded1 100644 --- a/application/src/main/java/org/opentripplanner/apis/gtfs/datafetchers/QueryTypeImpl.java +++ b/application/src/main/java/org/opentripplanner/apis/gtfs/datafetchers/QueryTypeImpl.java @@ -750,8 +750,7 @@ public DataFetcher> stopsByBbox() { Stream stopStream = getTransitService(environment) .findRegularStops(envelope) - .stream() - .filter(stop -> envelope.contains(stop.getCoordinate().asJtsCoordinate())); + .stream(); if (args.getGraphQLFeeds() != null) { List feedIds = args.getGraphQLFeeds(); diff --git a/application/src/main/java/org/opentripplanner/apis/transmodel/TransmodelGraphQLSchema.java b/application/src/main/java/org/opentripplanner/apis/transmodel/TransmodelGraphQLSchema.java index 922f9f5244b..ecd1bb6b2ad 100644 --- a/application/src/main/java/org/opentripplanner/apis/transmodel/TransmodelGraphQLSchema.java +++ b/application/src/main/java/org/opentripplanner/apis/transmodel/TransmodelGraphQLSchema.java @@ -3,6 +3,7 @@ import static java.lang.Boolean.TRUE; import static java.util.Collections.emptyList; import static org.opentripplanner.apis.transmodel.mapping.SeverityMapper.getTransmodelSeverity; +import static org.opentripplanner.apis.transmodel.mapping.TransitIdMapper.mapIDToDomain; import static org.opentripplanner.apis.transmodel.mapping.TransitIdMapper.mapIDsToDomainNullSafe; import static org.opentripplanner.apis.transmodel.model.EnumTypes.FILTER_PLACE_TYPE_ENUM; import static org.opentripplanner.apis.transmodel.model.EnumTypes.MULTI_MODAL_MODE; @@ -115,6 +116,7 @@ import org.opentripplanner.routing.graphfinder.PlaceType; import org.opentripplanner.service.vehiclerental.model.VehicleRentalPlace; import org.opentripplanner.transit.api.model.FilterValues; +import org.opentripplanner.transit.api.request.RegularStopRequest; import org.opentripplanner.transit.api.request.TripRequest; import org.opentripplanner.transit.model.basic.TransitMode; import org.opentripplanner.transit.model.framework.FeedScopedId; @@ -439,10 +441,7 @@ private GraphQLSchema create() { .build() ) .dataFetcher(env -> - StopPlaceType.fetchStopPlaceById( - TransitIdMapper.mapIDToDomain(env.getArgument("id")), - env - ) + StopPlaceType.fetchStopPlaceById(mapIDToDomain(env.getArgument("id")), env) ) .build() ) @@ -576,7 +575,7 @@ private GraphQLSchema create() { .dataFetcher(environment -> GqlUtil .getTransitService(environment) - .getStopLocation(TransitIdMapper.mapIDToDomain(environment.getArgument("id"))) + .getStopLocation(mapIDToDomain(environment.getArgument("id"))) ) .build() ) @@ -610,7 +609,7 @@ private GraphQLSchema create() { } TransitService transitService = GqlUtil.getTransitService(environment); return ((List) environment.getArgument("ids")).stream() - .map(id -> transitService.getStopLocation(TransitIdMapper.mapIDToDomain(id))) + .map(id -> transitService.getStopLocation(mapIDToDomain(id))) .collect(Collectors.toList()); } if (environment.getArgument("name") == null) { @@ -661,7 +660,12 @@ private GraphQLSchema create() { .build() ) .argument( - GraphQLArgument.newArgument().name("authority").type(Scalars.GraphQLString).build() + GraphQLArgument + .newArgument() + .name("authority") + .description("The ID of the authority to fetch stops for.") + .type(Scalars.GraphQLString) + .build() ) .argument( GraphQLArgument @@ -683,24 +687,18 @@ private GraphQLSchema create() { environment.getArgument("maximumLatitude") ) ); - return GqlUtil - .getTransitService(environment) - .findRegularStops(envelope) - .stream() - .filter(stop -> envelope.contains(stop.getCoordinate().asJtsCoordinate())) - .filter(stop -> - environment.getArgument("authority") == null || - stop.getId().getFeedId().equalsIgnoreCase(environment.getArgument("authority")) - ) - .filter(stop -> { - boolean filterByInUse = TRUE.equals(environment.getArgument("filterByInUse")); - boolean inUse = !GqlUtil - .getTransitService(environment) - .findPatterns(stop, true) - .isEmpty(); - return !filterByInUse || inUse; - }) - .collect(Collectors.toList()); + + var authority = environment.getArgument("authority"); + var filterInUse = environment.getArgument("filterByInUse"); + + RegularStopRequest regularStopRequest = RegularStopRequest + .of() + .withEnvelope(envelope) + .withFeeds(List.of(authority)) + .filterByInUse(filterInUse) + .build(); + + return GqlUtil.getTransitService(environment).findRegularStops(regularStopRequest); }) .build() ) @@ -1438,7 +1436,7 @@ private GraphQLSchema create() { .build() ) .dataFetcher(environment -> { - var bikeParkId = TransitIdMapper.mapIDToDomain(environment.getArgument("id")); + var bikeParkId = mapIDToDomain(environment.getArgument("id")); return GqlUtil .getVehicleParkingService(environment) .listBikeParks() @@ -1573,7 +1571,7 @@ private GraphQLSchema create() { return GqlUtil .getTransitService(environment) .getTransitAlertService() - .getAlertById(TransitIdMapper.mapIDToDomain(situationNumber)); + .getAlertById(mapIDToDomain(situationNumber)); }) .build() ) diff --git a/application/src/main/java/org/opentripplanner/apis/transmodel/model/stop/StopPlaceType.java b/application/src/main/java/org/opentripplanner/apis/transmodel/model/stop/StopPlaceType.java index fa755e8c6f7..197e928f954 100644 --- a/application/src/main/java/org/opentripplanner/apis/transmodel/model/stop/StopPlaceType.java +++ b/application/src/main/java/org/opentripplanner/apis/transmodel/model/stop/StopPlaceType.java @@ -548,7 +548,6 @@ public static Collection fetchStopPlaces( Stream stations = transitService .findRegularStops(envelope) .stream() - .filter(stop -> envelope.contains(stop.getCoordinate().asJtsCoordinate())) .map(StopLocation::getParentStation) .filter(Objects::nonNull) .distinct(); diff --git a/application/src/main/java/org/opentripplanner/transit/api/request/RegularStopRequest.java b/application/src/main/java/org/opentripplanner/transit/api/request/RegularStopRequest.java new file mode 100644 index 00000000000..6073c1396e6 --- /dev/null +++ b/application/src/main/java/org/opentripplanner/transit/api/request/RegularStopRequest.java @@ -0,0 +1,39 @@ +package org.opentripplanner.transit.api.request; + +import java.util.List; +import org.locationtech.jts.geom.Envelope; +import org.opentripplanner.transit.model.site.RegularStop; + +/** + * A request for {@link RegularStop}s. + * + * This request is used to retrieve {@link RegularStop}s that match the provided criteria. + */ +public class RegularStopRequest { + + private final Envelope envelope; + private final List feedIds; + private final boolean filterByInUse; + + protected RegularStopRequest(Envelope envelope, List feedIds, boolean filterByInUse) { + this.envelope = envelope; + this.feedIds = feedIds; + this.filterByInUse = filterByInUse; + } + + public static RegularStopRequestBuilder of() { + return new RegularStopRequestBuilder(); + } + + public Envelope envelope() { + return envelope; + } + + public List feedIds() { + return feedIds; + } + + public boolean filterByInUse() { + return filterByInUse; + } +} diff --git a/application/src/main/java/org/opentripplanner/transit/api/request/RegularStopRequestBuilder.java b/application/src/main/java/org/opentripplanner/transit/api/request/RegularStopRequestBuilder.java new file mode 100644 index 00000000000..12def063afe --- /dev/null +++ b/application/src/main/java/org/opentripplanner/transit/api/request/RegularStopRequestBuilder.java @@ -0,0 +1,32 @@ +package org.opentripplanner.transit.api.request; + +import java.util.List; +import org.locationtech.jts.geom.Envelope; + +public class RegularStopRequestBuilder { + + private Envelope envelope; + private List feedIds; + private boolean filterByInUse; + + protected RegularStopRequestBuilder() {} + + public RegularStopRequestBuilder withEnvelope(Envelope envelope) { + this.envelope = envelope; + return this; + } + + public RegularStopRequestBuilder withFeeds(List feedIds) { + this.feedIds = feedIds; + return this; + } + + public RegularStopRequestBuilder filterByInUse(boolean filterByInUse) { + this.filterByInUse = filterByInUse; + return this; + } + + public RegularStopRequest build() { + return new RegularStopRequest(envelope, feedIds, filterByInUse); + } +} diff --git a/application/src/main/java/org/opentripplanner/transit/model/filter/expr/GenericUnaryMatcher.java b/application/src/main/java/org/opentripplanner/transit/model/filter/expr/GenericUnaryMatcher.java new file mode 100644 index 00000000000..0ac6c5f17ee --- /dev/null +++ b/application/src/main/java/org/opentripplanner/transit/model/filter/expr/GenericUnaryMatcher.java @@ -0,0 +1,33 @@ +package org.opentripplanner.transit.model.filter.expr; + +import java.util.function.Predicate; + +/** + * A generic matcher that takes a predicate function that returns a boolean given the matched type. + *

+ * @param The type of the entity being matched. + */ +public class GenericUnaryMatcher implements Matcher { + + private final String typeName; + private final Predicate matchPredicate; + + /** + * @param typeName The typeName appears in the toString for easier debugging. + * @param matchPredicate The predicate that will be used to test the entity being matched. + */ + public GenericUnaryMatcher(String typeName, Predicate matchPredicate) { + this.typeName = typeName; + this.matchPredicate = matchPredicate; + } + + @Override + public boolean match(T entity) { + return matchPredicate.test(entity); + } + + @Override + public String toString() { + return "GenericUnaryMatcher: " + typeName; + } +} diff --git a/application/src/main/java/org/opentripplanner/transit/model/filter/transit/RegularStopMatcherFactory.java b/application/src/main/java/org/opentripplanner/transit/model/filter/transit/RegularStopMatcherFactory.java new file mode 100644 index 00000000000..2c21497c569 --- /dev/null +++ b/application/src/main/java/org/opentripplanner/transit/model/filter/transit/RegularStopMatcherFactory.java @@ -0,0 +1,39 @@ +package org.opentripplanner.transit.model.filter.transit; + +import java.util.function.Predicate; +import org.opentripplanner.transit.api.request.RegularStopRequest; +import org.opentripplanner.transit.model.filter.expr.EqualityMatcher; +import org.opentripplanner.transit.model.filter.expr.ExpressionBuilder; +import org.opentripplanner.transit.model.filter.expr.GenericUnaryMatcher; +import org.opentripplanner.transit.model.filter.expr.Matcher; +import org.opentripplanner.transit.model.site.RegularStop; + +/** + * A factory for creating matchers for {@link RegularStop} objects. + *

+ * This factory is used to create matchers for {@link RegularStop} objects based on a request. The + * resulting matcher can be used to filter a list of {@link RegularStop} objects. + */ +public class RegularStopMatcherFactory { + + public static Matcher of( + RegularStopRequest request, + Predicate inUseProvider + ) { + ExpressionBuilder expr = ExpressionBuilder.of(); + + expr.atLeastOneMatch(request.feedIds(), RegularStopMatcherFactory::feedIds); + if (request.filterByInUse()) { + expr.matches(inUseMatcher(inUseProvider)); + } + return expr.build(); + } + + static Matcher feedIds(String feedIds) { + return new EqualityMatcher<>("feedId", feedIds, stop -> stop.getId().getFeedId()); + } + + static Matcher inUseMatcher(Predicate inUseProvider) { + return new GenericUnaryMatcher<>("inUse", inUseProvider); + } +} diff --git a/application/src/main/java/org/opentripplanner/transit/service/DefaultTransitService.java b/application/src/main/java/org/opentripplanner/transit/service/DefaultTransitService.java index d35977cae74..4e50a7b59fb 100644 --- a/application/src/main/java/org/opentripplanner/transit/service/DefaultTransitService.java +++ b/application/src/main/java/org/opentripplanner/transit/service/DefaultTransitService.java @@ -34,11 +34,13 @@ import org.opentripplanner.routing.services.TransitAlertService; import org.opentripplanner.routing.stoptimes.ArrivalDeparture; import org.opentripplanner.routing.stoptimes.StopTimesHelper; +import org.opentripplanner.transit.api.request.RegularStopRequest; import org.opentripplanner.transit.api.request.TripOnServiceDateRequest; import org.opentripplanner.transit.api.request.TripRequest; import org.opentripplanner.transit.model.basic.Notice; import org.opentripplanner.transit.model.basic.TransitMode; import org.opentripplanner.transit.model.filter.expr.Matcher; +import org.opentripplanner.transit.model.filter.transit.RegularStopMatcherFactory; import org.opentripplanner.transit.model.filter.transit.TripMatcherFactory; import org.opentripplanner.transit.model.filter.transit.TripOnServiceDateMatcherFactory; import org.opentripplanner.transit.model.framework.AbstractTransitEntity; @@ -687,6 +689,20 @@ public Collection findRegularStops(Envelope envelope) { return timetableRepository.getSiteRepository().findRegularStops(envelope); } + @Override + public Collection findRegularStops(RegularStopRequest request) { + OTPRequestTimeoutException.checkForTimeout(); + Collection stops = timetableRepository + .getSiteRepository() + .findRegularStops(request.envelope()); + + Matcher matcher = RegularStopMatcherFactory.of( + request, + stop -> !getPatternsForStop(stop, true).isEmpty() + ); + return stops.stream().filter(matcher::match).toList(); + } + @Override public Collection findAreaStops(Envelope envelope) { OTPRequestTimeoutException.checkForTimeout(); diff --git a/application/src/main/java/org/opentripplanner/transit/service/StopModelIndex.java b/application/src/main/java/org/opentripplanner/transit/service/StopModelIndex.java index 13a8c0d278d..effa8f95f7e 100644 --- a/application/src/main/java/org/opentripplanner/transit/service/StopModelIndex.java +++ b/application/src/main/java/org/opentripplanner/transit/service/StopModelIndex.java @@ -71,10 +71,17 @@ class SiteRepositoryIndex { } /** - * Find a regular stop in the spatial index + * Find a regular stop in the spatial index, where the stop is inside of the passed Envelope. + * + * @param envelope - The {@link Envelope} to search for stops in. + * @return A collection of {@link RegularStop}s that are inside of the passed envelope. */ Collection findRegularStops(Envelope envelope) { - return regularStopSpatialIndex.query(envelope); + return regularStopSpatialIndex + .query(envelope) + .stream() + .filter(stop -> envelope.contains(stop.getCoordinate().asJtsCoordinate())) + .toList(); } MultiModalStation getMultiModalStationForStation(Station station) { diff --git a/application/src/main/java/org/opentripplanner/transit/service/TransitService.java b/application/src/main/java/org/opentripplanner/transit/service/TransitService.java index c1bba355cdf..09ad54a5c99 100644 --- a/application/src/main/java/org/opentripplanner/transit/service/TransitService.java +++ b/application/src/main/java/org/opentripplanner/transit/service/TransitService.java @@ -24,6 +24,7 @@ import org.opentripplanner.routing.algorithm.raptoradapter.transit.TransitLayer; import org.opentripplanner.routing.services.TransitAlertService; import org.opentripplanner.routing.stoptimes.ArrivalDeparture; +import org.opentripplanner.transit.api.request.RegularStopRequest; import org.opentripplanner.transit.api.request.TripOnServiceDateRequest; import org.opentripplanner.transit.api.request.TripRequest; import org.opentripplanner.transit.model.basic.Notice; @@ -304,16 +305,16 @@ List findTripTimeOnDate( /** * Returns a list of TripOnServiceDates that match the filtering defined in the request. * - * @param request - A TripOnServiceDateRequest object with filtering defined. - * @return - A list of TripOnServiceDates + * @param request - A {@link TripOnServiceDateRequest} object with filtering defined. + * @return - A list of {@link TripOnServiceDate}s */ List findTripsOnServiceDate(TripOnServiceDateRequest request); /** * Returns a list of Trips that match the filtering defined in the request. * - * @param request - A TripRequest object with filtering defined. - * @return - A list of Trips + * @param request - A {@link TripRequest} object with filtering defined. + * @return - A list of {@link Trip}s */ List getTrips(TripRequest request); @@ -324,4 +325,12 @@ List findTripTimeOnDate( * @return true if the trip exists, false otherwise */ boolean containsTrip(FeedScopedId id); -} + + /** + * Returns a list of RegularStops that match the filtering defined in the request. + * + * @param request - A {@link RegularStopRequest} object with filtering defined. + * @return - A list of {@link RegularStop}s + */ + Collection findRegularStops(RegularStopRequest request); +} \ No newline at end of file diff --git a/application/src/main/resources/org/opentripplanner/apis/transmodel/schema.graphql b/application/src/main/resources/org/opentripplanner/apis/transmodel/schema.graphql index 783cc3e7948..9900f842250 100644 --- a/application/src/main/resources/org/opentripplanner/apis/transmodel/schema.graphql +++ b/application/src/main/resources/org/opentripplanner/apis/transmodel/schema.graphql @@ -702,6 +702,7 @@ type QueryType { quays(ids: [String], name: String): [Quay]! @timingData "Get all quays within the specified bounding box" quaysByBbox( + "The ID of the authority to fetch stops for." authority: String, "If true only quays with at least one visiting line are included." filterByInUse: Boolean = false, diff --git a/application/src/test/java/org/opentripplanner/transit/model/filter/expr/GenericUnaryMatcherTest.java b/application/src/test/java/org/opentripplanner/transit/model/filter/expr/GenericUnaryMatcherTest.java new file mode 100644 index 00000000000..ef93df53dbd --- /dev/null +++ b/application/src/test/java/org/opentripplanner/transit/model/filter/expr/GenericUnaryMatcherTest.java @@ -0,0 +1,15 @@ +package org.opentripplanner.transit.model.filter.expr; + +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + +class GenericUnaryMatcherTest { + + @Test + void testMatches() { + var matcher = new GenericUnaryMatcher<>("int", i -> i.equals(42)); + assertTrue(matcher.match(42)); + assertFalse(matcher.match(43)); + } +} diff --git a/application/src/test/java/org/opentripplanner/transit/model/filter/transit/RegularStopMatcherFactoryTest.java b/application/src/test/java/org/opentripplanner/transit/model/filter/transit/RegularStopMatcherFactoryTest.java new file mode 100644 index 00000000000..10e27abcb31 --- /dev/null +++ b/application/src/test/java/org/opentripplanner/transit/model/filter/transit/RegularStopMatcherFactoryTest.java @@ -0,0 +1,44 @@ +package org.opentripplanner.transit.model.filter.transit; + +import static org.junit.jupiter.api.Assertions.*; + +import java.util.concurrent.atomic.AtomicInteger; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.opentripplanner.transit.model.framework.FeedScopedId; +import org.opentripplanner.transit.model.site.RegularStop; + +class RegularStopMatcherFactoryTest { + + private static RegularStop stop1; + private static RegularStop stop2; + + @BeforeAll + static void setup() { + stop1 = + RegularStop + .of(new FeedScopedId("feedId", "stopId"), new AtomicInteger()::getAndIncrement) + .build(); + + stop2 = + RegularStop + .of(new FeedScopedId("otherFeedId", "otherStopId"), new AtomicInteger()::getAndIncrement) + .build(); + } + + @Test + void testFeedIds() { + var matcher = RegularStopMatcherFactory.feedIds("feedId"); + assertTrue(matcher.match(stop1)); + assertFalse(matcher.match(stop2)); + } + + @Test + void testInUseMatcher() { + var matcher = RegularStopMatcherFactory.inUseMatcher(stop -> + stop.getId().getFeedId().equals("feedId") + ); + assertTrue(matcher.match(stop1)); + assertFalse(matcher.match(stop2)); + } +} From b104b5d926e83589c8553300dfcc20333be9371e Mon Sep 17 00:00:00 2001 From: eibakke Date: Tue, 3 Dec 2024 14:57:17 +0100 Subject: [PATCH 02/14] Updates the RegularStopRequest to latest concepts. --- .../transmodel/TransmodelGraphQLSchema.java | 2 +- .../transit/api/request/RegularStopRequest.java | 12 ++++++------ .../api/request/RegularStopRequestBuilder.java | 9 ++++----- .../model/filter/expr/ExpressionBuilder.java | 5 +++++ .../transit/RegularStopMatcherFactory.java | 17 ++++++++++++++--- .../transit/service/DefaultTransitService.java | 2 +- .../transit/service/TransitService.java | 2 +- .../transit/RegularStopMatcherFactoryTest.java | 2 +- 8 files changed, 33 insertions(+), 18 deletions(-) diff --git a/application/src/main/java/org/opentripplanner/apis/transmodel/TransmodelGraphQLSchema.java b/application/src/main/java/org/opentripplanner/apis/transmodel/TransmodelGraphQLSchema.java index ecd1bb6b2ad..ced71e17943 100644 --- a/application/src/main/java/org/opentripplanner/apis/transmodel/TransmodelGraphQLSchema.java +++ b/application/src/main/java/org/opentripplanner/apis/transmodel/TransmodelGraphQLSchema.java @@ -694,7 +694,7 @@ private GraphQLSchema create() { RegularStopRequest regularStopRequest = RegularStopRequest .of() .withEnvelope(envelope) - .withFeeds(List.of(authority)) + .withFeed(authority) .filterByInUse(filterInUse) .build(); diff --git a/application/src/main/java/org/opentripplanner/transit/api/request/RegularStopRequest.java b/application/src/main/java/org/opentripplanner/transit/api/request/RegularStopRequest.java index 6073c1396e6..ddacc03e701 100644 --- a/application/src/main/java/org/opentripplanner/transit/api/request/RegularStopRequest.java +++ b/application/src/main/java/org/opentripplanner/transit/api/request/RegularStopRequest.java @@ -6,18 +6,18 @@ /** * A request for {@link RegularStop}s. - * + *

* This request is used to retrieve {@link RegularStop}s that match the provided criteria. */ public class RegularStopRequest { private final Envelope envelope; - private final List feedIds; + private final String feedId; private final boolean filterByInUse; - protected RegularStopRequest(Envelope envelope, List feedIds, boolean filterByInUse) { + protected RegularStopRequest(Envelope envelope, String feedId, boolean filterByInUse) { this.envelope = envelope; - this.feedIds = feedIds; + this.feedId = feedId; this.filterByInUse = filterByInUse; } @@ -29,8 +29,8 @@ public Envelope envelope() { return envelope; } - public List feedIds() { - return feedIds; + public String feedId() { + return feedId; } public boolean filterByInUse() { diff --git a/application/src/main/java/org/opentripplanner/transit/api/request/RegularStopRequestBuilder.java b/application/src/main/java/org/opentripplanner/transit/api/request/RegularStopRequestBuilder.java index 12def063afe..b44c3612429 100644 --- a/application/src/main/java/org/opentripplanner/transit/api/request/RegularStopRequestBuilder.java +++ b/application/src/main/java/org/opentripplanner/transit/api/request/RegularStopRequestBuilder.java @@ -1,12 +1,11 @@ package org.opentripplanner.transit.api.request; -import java.util.List; import org.locationtech.jts.geom.Envelope; public class RegularStopRequestBuilder { private Envelope envelope; - private List feedIds; + private String feedId; private boolean filterByInUse; protected RegularStopRequestBuilder() {} @@ -16,8 +15,8 @@ public RegularStopRequestBuilder withEnvelope(Envelope envelope) { return this; } - public RegularStopRequestBuilder withFeeds(List feedIds) { - this.feedIds = feedIds; + public RegularStopRequestBuilder withFeed(String feedId) { + this.feedId = feedId; return this; } @@ -27,6 +26,6 @@ public RegularStopRequestBuilder filterByInUse(boolean filterByInUse) { } public RegularStopRequest build() { - return new RegularStopRequest(envelope, feedIds, filterByInUse); + return new RegularStopRequest(envelope, feedId, filterByInUse); } } diff --git a/application/src/main/java/org/opentripplanner/transit/model/filter/expr/ExpressionBuilder.java b/application/src/main/java/org/opentripplanner/transit/model/filter/expr/ExpressionBuilder.java index f2910a4c8d2..87533ab1b5e 100644 --- a/application/src/main/java/org/opentripplanner/transit/model/filter/expr/ExpressionBuilder.java +++ b/application/src/main/java/org/opentripplanner/transit/model/filter/expr/ExpressionBuilder.java @@ -22,6 +22,11 @@ public static ExpressionBuilder of() { return new ExpressionBuilder<>(); } + public ExpressionBuilder matches(Matcher matcher) { + matchers.add(matcher); + return this; + } + public ExpressionBuilder atLeastOneMatch( FilterValues filterValues, Function> matcherProvider diff --git a/application/src/main/java/org/opentripplanner/transit/model/filter/transit/RegularStopMatcherFactory.java b/application/src/main/java/org/opentripplanner/transit/model/filter/transit/RegularStopMatcherFactory.java index 2c21497c569..dab90cb07e5 100644 --- a/application/src/main/java/org/opentripplanner/transit/model/filter/transit/RegularStopMatcherFactory.java +++ b/application/src/main/java/org/opentripplanner/transit/model/filter/transit/RegularStopMatcherFactory.java @@ -16,21 +16,32 @@ */ public class RegularStopMatcherFactory { + /** + * Creates a matcher that filters {@link RegularStop} objects with the provided {@link RegularStopRequest} + * and {@link Predicate}. The {@link Predicate} is used to determine if a {@link RegularStop} is + * in use. Typically the inUseProvider is a function that checks if the {@link RegularStop} is in + * a set of used stops. + * @param request - {@link RegularStopRequest} to filter {@link RegularStop} objects. + * @param inUseProvider - {@link Predicate} to determine if a {@link RegularStop} is in use. + * @return - {@link Matcher} for {@link RegularStop} objects. + */ public static Matcher of( RegularStopRequest request, Predicate inUseProvider ) { ExpressionBuilder expr = ExpressionBuilder.of(); - expr.atLeastOneMatch(request.feedIds(), RegularStopMatcherFactory::feedIds); + if (request.feedId() != null) { + expr.matches(feedId(request.feedId())); + } if (request.filterByInUse()) { expr.matches(inUseMatcher(inUseProvider)); } return expr.build(); } - static Matcher feedIds(String feedIds) { - return new EqualityMatcher<>("feedId", feedIds, stop -> stop.getId().getFeedId()); + static Matcher feedId(String feedId) { + return new EqualityMatcher<>("feedId", feedId, stop -> stop.getId().getFeedId()); } static Matcher inUseMatcher(Predicate inUseProvider) { diff --git a/application/src/main/java/org/opentripplanner/transit/service/DefaultTransitService.java b/application/src/main/java/org/opentripplanner/transit/service/DefaultTransitService.java index 4e50a7b59fb..893a3f54f94 100644 --- a/application/src/main/java/org/opentripplanner/transit/service/DefaultTransitService.java +++ b/application/src/main/java/org/opentripplanner/transit/service/DefaultTransitService.java @@ -698,7 +698,7 @@ public Collection findRegularStops(RegularStopRequest request) { Matcher matcher = RegularStopMatcherFactory.of( request, - stop -> !getPatternsForStop(stop, true).isEmpty() + stop -> !findPatterns(stop, true).isEmpty() ); return stops.stream().filter(matcher::match).toList(); } diff --git a/application/src/main/java/org/opentripplanner/transit/service/TransitService.java b/application/src/main/java/org/opentripplanner/transit/service/TransitService.java index 09ad54a5c99..741a2848b68 100644 --- a/application/src/main/java/org/opentripplanner/transit/service/TransitService.java +++ b/application/src/main/java/org/opentripplanner/transit/service/TransitService.java @@ -333,4 +333,4 @@ List findTripTimeOnDate( * @return - A list of {@link RegularStop}s */ Collection findRegularStops(RegularStopRequest request); -} \ No newline at end of file +} diff --git a/application/src/test/java/org/opentripplanner/transit/model/filter/transit/RegularStopMatcherFactoryTest.java b/application/src/test/java/org/opentripplanner/transit/model/filter/transit/RegularStopMatcherFactoryTest.java index 10e27abcb31..0ed09b22186 100644 --- a/application/src/test/java/org/opentripplanner/transit/model/filter/transit/RegularStopMatcherFactoryTest.java +++ b/application/src/test/java/org/opentripplanner/transit/model/filter/transit/RegularStopMatcherFactoryTest.java @@ -28,7 +28,7 @@ static void setup() { @Test void testFeedIds() { - var matcher = RegularStopMatcherFactory.feedIds("feedId"); + var matcher = RegularStopMatcherFactory.feedId("feedId"); assertTrue(matcher.match(stop1)); assertFalse(matcher.match(stop2)); } From df1f2beb81d7d7f1e87ff58a26cea4efde5064c2 Mon Sep 17 00:00:00 2001 From: eibakke Date: Tue, 10 Dec 2024 14:50:27 +0100 Subject: [PATCH 03/14] Adds @Nullable to feedId method on the RegularStopRequest. --- .../org/opentripplanner/transit/api/model/FilterValues.java | 2 +- .../transit/api/request/RegularStopRequest.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/application/src/main/java/org/opentripplanner/transit/api/model/FilterValues.java b/application/src/main/java/org/opentripplanner/transit/api/model/FilterValues.java index 391b2531231..78587e5f4fa 100644 --- a/application/src/main/java/org/opentripplanner/transit/api/model/FilterValues.java +++ b/application/src/main/java/org/opentripplanner/transit/api/model/FilterValues.java @@ -1,6 +1,6 @@ package org.opentripplanner.transit.api.model; -import com.beust.jcommander.internal.Nullable; +import javax.annotation.Nullable; import java.util.Collection; import java.util.NoSuchElementException; import org.opentripplanner.transit.model.framework.FeedScopedId; diff --git a/application/src/main/java/org/opentripplanner/transit/api/request/RegularStopRequest.java b/application/src/main/java/org/opentripplanner/transit/api/request/RegularStopRequest.java index ddacc03e701..eb2d6990b38 100644 --- a/application/src/main/java/org/opentripplanner/transit/api/request/RegularStopRequest.java +++ b/application/src/main/java/org/opentripplanner/transit/api/request/RegularStopRequest.java @@ -1,6 +1,6 @@ package org.opentripplanner.transit.api.request; -import java.util.List; +import javax.annotation.Nullable; import org.locationtech.jts.geom.Envelope; import org.opentripplanner.transit.model.site.RegularStop; @@ -29,6 +29,7 @@ public Envelope envelope() { return envelope; } + @Nullable public String feedId() { return feedId; } From 54d80e4dec087c2804f21b1c6a16dee929cce1eb Mon Sep 17 00:00:00 2001 From: eibakke Date: Tue, 10 Dec 2024 15:20:46 +0100 Subject: [PATCH 04/14] Changes feedId to be called agency. --- .../apis/transmodel/TransmodelGraphQLSchema.java | 3 +-- .../transit/api/model/FilterValues.java | 2 +- .../transit/api/request/RegularStopRequest.java | 14 +++++++------- .../api/request/RegularStopRequestBuilder.java | 15 ++++++--------- .../filter/transit/RegularStopMatcherFactory.java | 8 ++++---- .../transit/RegularStopMatcherFactoryTest.java | 2 +- 6 files changed, 20 insertions(+), 24 deletions(-) diff --git a/application/src/main/java/org/opentripplanner/apis/transmodel/TransmodelGraphQLSchema.java b/application/src/main/java/org/opentripplanner/apis/transmodel/TransmodelGraphQLSchema.java index ced71e17943..8b02161b464 100644 --- a/application/src/main/java/org/opentripplanner/apis/transmodel/TransmodelGraphQLSchema.java +++ b/application/src/main/java/org/opentripplanner/apis/transmodel/TransmodelGraphQLSchema.java @@ -692,8 +692,7 @@ private GraphQLSchema create() { var filterInUse = environment.getArgument("filterByInUse"); RegularStopRequest regularStopRequest = RegularStopRequest - .of() - .withEnvelope(envelope) + .of(envelope) .withFeed(authority) .filterByInUse(filterInUse) .build(); diff --git a/application/src/main/java/org/opentripplanner/transit/api/model/FilterValues.java b/application/src/main/java/org/opentripplanner/transit/api/model/FilterValues.java index 78587e5f4fa..63befe3add6 100644 --- a/application/src/main/java/org/opentripplanner/transit/api/model/FilterValues.java +++ b/application/src/main/java/org/opentripplanner/transit/api/model/FilterValues.java @@ -1,8 +1,8 @@ package org.opentripplanner.transit.api.model; -import javax.annotation.Nullable; import java.util.Collection; import java.util.NoSuchElementException; +import javax.annotation.Nullable; import org.opentripplanner.transit.model.framework.FeedScopedId; import org.opentripplanner.transit.service.TransitService; diff --git a/application/src/main/java/org/opentripplanner/transit/api/request/RegularStopRequest.java b/application/src/main/java/org/opentripplanner/transit/api/request/RegularStopRequest.java index eb2d6990b38..2886af3784e 100644 --- a/application/src/main/java/org/opentripplanner/transit/api/request/RegularStopRequest.java +++ b/application/src/main/java/org/opentripplanner/transit/api/request/RegularStopRequest.java @@ -12,17 +12,17 @@ public class RegularStopRequest { private final Envelope envelope; - private final String feedId; + private final String agency; private final boolean filterByInUse; - protected RegularStopRequest(Envelope envelope, String feedId, boolean filterByInUse) { + protected RegularStopRequest(Envelope envelope, String agency, boolean filterByInUse) { this.envelope = envelope; - this.feedId = feedId; + this.agency = agency; this.filterByInUse = filterByInUse; } - public static RegularStopRequestBuilder of() { - return new RegularStopRequestBuilder(); + public static RegularStopRequestBuilder of(Envelope envelope) { + return new RegularStopRequestBuilder(envelope); } public Envelope envelope() { @@ -30,8 +30,8 @@ public Envelope envelope() { } @Nullable - public String feedId() { - return feedId; + public String agency() { + return agency; } public boolean filterByInUse() { diff --git a/application/src/main/java/org/opentripplanner/transit/api/request/RegularStopRequestBuilder.java b/application/src/main/java/org/opentripplanner/transit/api/request/RegularStopRequestBuilder.java index b44c3612429..cd26f25d811 100644 --- a/application/src/main/java/org/opentripplanner/transit/api/request/RegularStopRequestBuilder.java +++ b/application/src/main/java/org/opentripplanner/transit/api/request/RegularStopRequestBuilder.java @@ -5,18 +5,15 @@ public class RegularStopRequestBuilder { private Envelope envelope; - private String feedId; - private boolean filterByInUse; + private String agency; + private boolean filterByInUse = false; - protected RegularStopRequestBuilder() {} - - public RegularStopRequestBuilder withEnvelope(Envelope envelope) { + protected RegularStopRequestBuilder(Envelope envelope) { this.envelope = envelope; - return this; } - public RegularStopRequestBuilder withFeed(String feedId) { - this.feedId = feedId; + public RegularStopRequestBuilder withFeed(String agency) { + this.agency = agency; return this; } @@ -26,6 +23,6 @@ public RegularStopRequestBuilder filterByInUse(boolean filterByInUse) { } public RegularStopRequest build() { - return new RegularStopRequest(envelope, feedId, filterByInUse); + return new RegularStopRequest(envelope, agency, filterByInUse); } } diff --git a/application/src/main/java/org/opentripplanner/transit/model/filter/transit/RegularStopMatcherFactory.java b/application/src/main/java/org/opentripplanner/transit/model/filter/transit/RegularStopMatcherFactory.java index dab90cb07e5..8a86d45bfcf 100644 --- a/application/src/main/java/org/opentripplanner/transit/model/filter/transit/RegularStopMatcherFactory.java +++ b/application/src/main/java/org/opentripplanner/transit/model/filter/transit/RegularStopMatcherFactory.java @@ -31,8 +31,8 @@ public static Matcher of( ) { ExpressionBuilder expr = ExpressionBuilder.of(); - if (request.feedId() != null) { - expr.matches(feedId(request.feedId())); + if (request.agency() != null) { + expr.matches(agency(request.agency())); } if (request.filterByInUse()) { expr.matches(inUseMatcher(inUseProvider)); @@ -40,8 +40,8 @@ public static Matcher of( return expr.build(); } - static Matcher feedId(String feedId) { - return new EqualityMatcher<>("feedId", feedId, stop -> stop.getId().getFeedId()); + static Matcher agency(String agency) { + return new EqualityMatcher<>("agency", agency, stop -> stop.getId().getFeedId()); } static Matcher inUseMatcher(Predicate inUseProvider) { diff --git a/application/src/test/java/org/opentripplanner/transit/model/filter/transit/RegularStopMatcherFactoryTest.java b/application/src/test/java/org/opentripplanner/transit/model/filter/transit/RegularStopMatcherFactoryTest.java index 0ed09b22186..d7ed1522ed8 100644 --- a/application/src/test/java/org/opentripplanner/transit/model/filter/transit/RegularStopMatcherFactoryTest.java +++ b/application/src/test/java/org/opentripplanner/transit/model/filter/transit/RegularStopMatcherFactoryTest.java @@ -28,7 +28,7 @@ static void setup() { @Test void testFeedIds() { - var matcher = RegularStopMatcherFactory.feedId("feedId"); + var matcher = RegularStopMatcherFactory.agency("feedId"); assertTrue(matcher.match(stop1)); assertFalse(matcher.match(stop2)); } From a7a0c724ff94c8bc529d47583311b33acd183e0e Mon Sep 17 00:00:00 2001 From: Eivind Morris Bakke Date: Wed, 11 Dec 2024 08:40:25 +0100 Subject: [PATCH 05/14] Update application/src/test/java/org/opentripplanner/transit/model/filter/transit/RegularStopMatcherFactoryTest.java Co-authored-by: Leonard Ehrenfried --- .../model/filter/transit/RegularStopMatcherFactoryTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/src/test/java/org/opentripplanner/transit/model/filter/transit/RegularStopMatcherFactoryTest.java b/application/src/test/java/org/opentripplanner/transit/model/filter/transit/RegularStopMatcherFactoryTest.java index d7ed1522ed8..d0ba0a246e7 100644 --- a/application/src/test/java/org/opentripplanner/transit/model/filter/transit/RegularStopMatcherFactoryTest.java +++ b/application/src/test/java/org/opentripplanner/transit/model/filter/transit/RegularStopMatcherFactoryTest.java @@ -28,7 +28,7 @@ static void setup() { @Test void testFeedIds() { - var matcher = RegularStopMatcherFactory.agency("feedId"); + var matcher = RegularStopMatcherFactory.agency("agency"); assertTrue(matcher.match(stop1)); assertFalse(matcher.match(stop2)); } From b8f6948555a2233d92c3a8d05bf1f7df91823ec4 Mon Sep 17 00:00:00 2001 From: eibakke Date: Wed, 11 Dec 2024 09:09:42 +0100 Subject: [PATCH 06/14] Fixes test failure. --- .../model/filter/transit/RegularStopMatcherFactoryTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/application/src/test/java/org/opentripplanner/transit/model/filter/transit/RegularStopMatcherFactoryTest.java b/application/src/test/java/org/opentripplanner/transit/model/filter/transit/RegularStopMatcherFactoryTest.java index d0ba0a246e7..100405f6fba 100644 --- a/application/src/test/java/org/opentripplanner/transit/model/filter/transit/RegularStopMatcherFactoryTest.java +++ b/application/src/test/java/org/opentripplanner/transit/model/filter/transit/RegularStopMatcherFactoryTest.java @@ -17,12 +17,12 @@ class RegularStopMatcherFactoryTest { static void setup() { stop1 = RegularStop - .of(new FeedScopedId("feedId", "stopId"), new AtomicInteger()::getAndIncrement) + .of(new FeedScopedId("agency", "stopId"), new AtomicInteger()::getAndIncrement) .build(); stop2 = RegularStop - .of(new FeedScopedId("otherFeedId", "otherStopId"), new AtomicInteger()::getAndIncrement) + .of(new FeedScopedId("otherAgency", "otherStopId"), new AtomicInteger()::getAndIncrement) .build(); } @@ -36,7 +36,7 @@ void testFeedIds() { @Test void testInUseMatcher() { var matcher = RegularStopMatcherFactory.inUseMatcher(stop -> - stop.getId().getFeedId().equals("feedId") + stop.getId().getFeedId().equals("agency") ); assertTrue(matcher.match(stop1)); assertFalse(matcher.match(stop2)); From 7f5f5e390cfa42bd04aafacbfcda356d6d31f568 Mon Sep 17 00:00:00 2001 From: eibakke Date: Mon, 16 Dec 2024 11:50:31 +0100 Subject: [PATCH 07/14] Addresses comments in code review. --- .../parkAndRideApi/ParkAndRideResource.java | 2 +- .../ext/restapi/resources/IndexAPI.java | 4 +- .../layers/stops/StopsLayerBuilder.java | 2 +- .../apis/gtfs/datafetchers/QueryTypeImpl.java | 2 +- .../transmodel/TransmodelGraphQLSchema.java | 16 ++++--- .../transmodel/model/stop/StopPlaceType.java | 2 +- .../GraphInspectorVectorTileResource.java | 2 +- .../StraightLineNearbyStopFinder.java | 2 +- .../api/OtpServerRequestContext.java | 2 +- .../FindRegularStopsByBoundingBoxRequest.java | 48 +++++++++++++++++++ ...gularStopsByBoundingBoxRequestBuilder.java | 32 +++++++++++++ .../api/request/RegularStopRequest.java | 40 ---------------- .../request/RegularStopRequestBuilder.java | 28 ----------- .../transit/RegularStopMatcherFactory.java | 16 +++---- .../service/DefaultTransitService.java | 8 ++-- .../transit/service/TransitService.java | 13 +++-- .../apis/transmodel/schema.graphql | 3 +- .../LegacyRouteRequestMapperTest.java | 2 +- .../routerequest/RouteRequestMapperTest.java | 2 +- .../graph/DefaultRoutingServiceTest.java | 2 +- .../RegularStopMatcherFactoryTest.java | 2 +- 21 files changed, 125 insertions(+), 105 deletions(-) create mode 100644 application/src/main/java/org/opentripplanner/transit/api/request/FindRegularStopsByBoundingBoxRequest.java create mode 100644 application/src/main/java/org/opentripplanner/transit/api/request/FindRegularStopsByBoundingBoxRequestBuilder.java delete mode 100644 application/src/main/java/org/opentripplanner/transit/api/request/RegularStopRequest.java delete mode 100644 application/src/main/java/org/opentripplanner/transit/api/request/RegularStopRequestBuilder.java diff --git a/application/src/ext/java/org/opentripplanner/ext/parkAndRideApi/ParkAndRideResource.java b/application/src/ext/java/org/opentripplanner/ext/parkAndRideApi/ParkAndRideResource.java index 747ba0617ec..611f4d46420 100644 --- a/application/src/ext/java/org/opentripplanner/ext/parkAndRideApi/ParkAndRideResource.java +++ b/application/src/ext/java/org/opentripplanner/ext/parkAndRideApi/ParkAndRideResource.java @@ -42,7 +42,7 @@ public ParkAndRideResource( // - serverContext.graphFinder(). This needs at least a comment! // - This can be replaced with a search done with the SiteRepository // - if we have a radius search there. - this.graphFinder = new DirectGraphFinder(serverContext.transitService()::findRegularStops); + this.graphFinder = new DirectGraphFinder(serverContext.transitService()::findRegularStopsByBoundingBox); } /** Envelopes are in latitude, longitude format */ diff --git a/application/src/ext/java/org/opentripplanner/ext/restapi/resources/IndexAPI.java b/application/src/ext/java/org/opentripplanner/ext/restapi/resources/IndexAPI.java index c7bba3cbe27..b9c049f547e 100644 --- a/application/src/ext/java/org/opentripplanner/ext/restapi/resources/IndexAPI.java +++ b/application/src/ext/java/org/opentripplanner/ext/restapi/resources/IndexAPI.java @@ -200,7 +200,7 @@ public List getStopsInRadius( radius = Math.min(radius, MAX_STOP_SEARCH_RADIUS); - return new DirectGraphFinder(serverContext.transitService()::findRegularStops) + return new DirectGraphFinder(serverContext.transitService()::findRegularStopsByBoundingBox) .findClosestStops(new Coordinate(lon, lat), radius) .stream() .map(it -> StopMapper.mapToApiShort(it.stop, it.distance)) @@ -221,7 +221,7 @@ public List getStopsInRadius( new Coordinate(maxLon, maxLat) ); - var stops = transitService().findRegularStops(envelope); + var stops = transitService().findRegularStopsByBoundingBox(envelope); return stops .stream() .map(StopMapper::mapToApiShort) diff --git a/application/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/StopsLayerBuilder.java b/application/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/StopsLayerBuilder.java index 141157f8f3e..c1e03cdefca 100644 --- a/application/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/StopsLayerBuilder.java +++ b/application/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/StopsLayerBuilder.java @@ -44,7 +44,7 @@ public StopsLayerBuilder( protected List getGeometries(Envelope query) { return transitService - .findRegularStops(query) + .findRegularStopsByBoundingBox(query) .stream() .filter(filter) .map(stop -> { diff --git a/application/src/main/java/org/opentripplanner/apis/gtfs/datafetchers/QueryTypeImpl.java b/application/src/main/java/org/opentripplanner/apis/gtfs/datafetchers/QueryTypeImpl.java index b10680aded1..c04ed6c75ed 100644 --- a/application/src/main/java/org/opentripplanner/apis/gtfs/datafetchers/QueryTypeImpl.java +++ b/application/src/main/java/org/opentripplanner/apis/gtfs/datafetchers/QueryTypeImpl.java @@ -749,7 +749,7 @@ public DataFetcher> stopsByBbox() { ); Stream stopStream = getTransitService(environment) - .findRegularStops(envelope) + .findRegularStopsByBoundingBox(envelope) .stream(); if (args.getGraphQLFeeds() != null) { diff --git a/application/src/main/java/org/opentripplanner/apis/transmodel/TransmodelGraphQLSchema.java b/application/src/main/java/org/opentripplanner/apis/transmodel/TransmodelGraphQLSchema.java index 8b02161b464..0561ec9de85 100644 --- a/application/src/main/java/org/opentripplanner/apis/transmodel/TransmodelGraphQLSchema.java +++ b/application/src/main/java/org/opentripplanner/apis/transmodel/TransmodelGraphQLSchema.java @@ -116,7 +116,7 @@ import org.opentripplanner.routing.graphfinder.PlaceType; import org.opentripplanner.service.vehiclerental.model.VehicleRentalPlace; import org.opentripplanner.transit.api.model.FilterValues; -import org.opentripplanner.transit.api.request.RegularStopRequest; +import org.opentripplanner.transit.api.request.FindRegularStopsByBoundingBoxRequest; import org.opentripplanner.transit.api.request.TripRequest; import org.opentripplanner.transit.model.basic.TransitMode; import org.opentripplanner.transit.model.framework.FeedScopedId; @@ -663,7 +663,9 @@ private GraphQLSchema create() { GraphQLArgument .newArgument() .name("authority") - .description("The ID of the authority to fetch stops for.") + .deprecate( + "This is the Transmodel namespace or the GTFS feedID - avoid using this. Request a new field if necessary." + ) .type(Scalars.GraphQLString) .build() ) @@ -673,7 +675,7 @@ private GraphQLSchema create() { .name("filterByInUse") .description("If true only quays with at least one visiting line are included.") .type(Scalars.GraphQLBoolean) - .defaultValue(Boolean.FALSE) + .defaultValueProgrammatic(Boolean.FALSE) .build() ) .dataFetcher(environment -> { @@ -691,13 +693,15 @@ private GraphQLSchema create() { var authority = environment.getArgument("authority"); var filterInUse = environment.getArgument("filterByInUse"); - RegularStopRequest regularStopRequest = RegularStopRequest + FindRegularStopsByBoundingBoxRequest findRegularStopsByBoundingBoxRequest = FindRegularStopsByBoundingBoxRequest .of(envelope) - .withFeed(authority) + .withFeedId(authority) .filterByInUse(filterInUse) .build(); - return GqlUtil.getTransitService(environment).findRegularStops(regularStopRequest); + return GqlUtil + .getTransitService(environment) + .findRegularStopsByBoundingBox(findRegularStopsByBoundingBoxRequest); }) .build() ) diff --git a/application/src/main/java/org/opentripplanner/apis/transmodel/model/stop/StopPlaceType.java b/application/src/main/java/org/opentripplanner/apis/transmodel/model/stop/StopPlaceType.java index 197e928f954..9b8fd25c68a 100644 --- a/application/src/main/java/org/opentripplanner/apis/transmodel/model/stop/StopPlaceType.java +++ b/application/src/main/java/org/opentripplanner/apis/transmodel/model/stop/StopPlaceType.java @@ -546,7 +546,7 @@ public static Collection fetchStopPlaces( ); Stream stations = transitService - .findRegularStops(envelope) + .findRegularStopsByBoundingBox(envelope) .stream() .map(StopLocation::getParentStation) .filter(Objects::nonNull) diff --git a/application/src/main/java/org/opentripplanner/apis/vectortiles/GraphInspectorVectorTileResource.java b/application/src/main/java/org/opentripplanner/apis/vectortiles/GraphInspectorVectorTileResource.java index d19c25a1f47..2a1ece7d6d4 100644 --- a/application/src/main/java/org/opentripplanner/apis/vectortiles/GraphInspectorVectorTileResource.java +++ b/application/src/main/java/org/opentripplanner/apis/vectortiles/GraphInspectorVectorTileResource.java @@ -182,7 +182,7 @@ private static LayerBuilder createLayerBuilder( case RegularStop -> new StopLayerBuilder<>( layerParameters, locale, - e -> context.transitService().findRegularStops(e) + e -> context.transitService().findRegularStopsByBoundingBox(e) ); case AreaStop -> new StopLayerBuilder<>( layerParameters, diff --git a/application/src/main/java/org/opentripplanner/graph_builder/module/nearbystops/StraightLineNearbyStopFinder.java b/application/src/main/java/org/opentripplanner/graph_builder/module/nearbystops/StraightLineNearbyStopFinder.java index 5b304d0d20c..ccdcb68446b 100644 --- a/application/src/main/java/org/opentripplanner/graph_builder/module/nearbystops/StraightLineNearbyStopFinder.java +++ b/application/src/main/java/org/opentripplanner/graph_builder/module/nearbystops/StraightLineNearbyStopFinder.java @@ -22,7 +22,7 @@ public StraightLineNearbyStopFinder(TransitService transitService, Duration dura // We need to accommodate straight line distance (in meters) but when streets are present we // use an earliest arrival search, which optimizes on time. Ideally we'd specify in meters, // but we don't have much of a choice here. Use the default walking speed to convert. - this.directGraphFinder = new DirectGraphFinder(transitService::findRegularStops); + this.directGraphFinder = new DirectGraphFinder(transitService::findRegularStopsByBoundingBox); } /** diff --git a/application/src/main/java/org/opentripplanner/standalone/api/OtpServerRequestContext.java b/application/src/main/java/org/opentripplanner/standalone/api/OtpServerRequestContext.java index b5b39ddee18..befa8ff9c22 100644 --- a/application/src/main/java/org/opentripplanner/standalone/api/OtpServerRequestContext.java +++ b/application/src/main/java/org/opentripplanner/standalone/api/OtpServerRequestContext.java @@ -120,7 +120,7 @@ public interface OtpServerRequestContext { TraverseVisitor traverseVisitor(); default GraphFinder graphFinder() { - return GraphFinder.getInstance(graph(), transitService()::findRegularStops); + return GraphFinder.getInstance(graph(), transitService()::findRegularStopsByBoundingBox); } FlexParameters flexParameters(); diff --git a/application/src/main/java/org/opentripplanner/transit/api/request/FindRegularStopsByBoundingBoxRequest.java b/application/src/main/java/org/opentripplanner/transit/api/request/FindRegularStopsByBoundingBoxRequest.java new file mode 100644 index 00000000000..6acdc784a08 --- /dev/null +++ b/application/src/main/java/org/opentripplanner/transit/api/request/FindRegularStopsByBoundingBoxRequest.java @@ -0,0 +1,48 @@ +package org.opentripplanner.transit.api.request; + +import javax.annotation.Nullable; +import org.locationtech.jts.geom.Envelope; +import org.opentripplanner.transit.model.site.RegularStop; + +/** + * A request for {@link RegularStop}s within a bounding box. + *

+ * This request is used to retrieve {@link RegularStop}s that are within a provided bounding box and + * match the other criteria. + */ +public class FindRegularStopsByBoundingBoxRequest { + + private final Envelope envelope; + + @Nullable + private final String feedId; + + private final boolean filterByInUse; + + protected FindRegularStopsByBoundingBoxRequest( + Envelope envelope, + @Nullable String feedId, + boolean filterByInUse + ) { + this.envelope = envelope; + this.feedId = feedId; + this.filterByInUse = filterByInUse; + } + + public static FindRegularStopsByBoundingBoxRequestBuilder of(Envelope envelope) { + return new FindRegularStopsByBoundingBoxRequestBuilder(envelope); + } + + public Envelope envelope() { + return envelope; + } + + @Nullable + public String feedId() { + return feedId; + } + + public boolean filterByInUse() { + return filterByInUse; + } +} diff --git a/application/src/main/java/org/opentripplanner/transit/api/request/FindRegularStopsByBoundingBoxRequestBuilder.java b/application/src/main/java/org/opentripplanner/transit/api/request/FindRegularStopsByBoundingBoxRequestBuilder.java new file mode 100644 index 00000000000..9d7413ba77b --- /dev/null +++ b/application/src/main/java/org/opentripplanner/transit/api/request/FindRegularStopsByBoundingBoxRequestBuilder.java @@ -0,0 +1,32 @@ +package org.opentripplanner.transit.api.request; + +import javax.annotation.Nullable; +import org.locationtech.jts.geom.Envelope; + +public class FindRegularStopsByBoundingBoxRequestBuilder { + + private final Envelope envelope; + + @Nullable + private String feedId; + + private boolean filterByInUse = false; + + protected FindRegularStopsByBoundingBoxRequestBuilder(Envelope envelope) { + this.envelope = envelope; + } + + public FindRegularStopsByBoundingBoxRequestBuilder withFeedId(@Nullable String feedId) { + this.feedId = feedId; + return this; + } + + public FindRegularStopsByBoundingBoxRequestBuilder filterByInUse(boolean filterByInUse) { + this.filterByInUse = filterByInUse; + return this; + } + + public FindRegularStopsByBoundingBoxRequest build() { + return new FindRegularStopsByBoundingBoxRequest(envelope, feedId, filterByInUse); + } +} diff --git a/application/src/main/java/org/opentripplanner/transit/api/request/RegularStopRequest.java b/application/src/main/java/org/opentripplanner/transit/api/request/RegularStopRequest.java deleted file mode 100644 index 2886af3784e..00000000000 --- a/application/src/main/java/org/opentripplanner/transit/api/request/RegularStopRequest.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.opentripplanner.transit.api.request; - -import javax.annotation.Nullable; -import org.locationtech.jts.geom.Envelope; -import org.opentripplanner.transit.model.site.RegularStop; - -/** - * A request for {@link RegularStop}s. - *

- * This request is used to retrieve {@link RegularStop}s that match the provided criteria. - */ -public class RegularStopRequest { - - private final Envelope envelope; - private final String agency; - private final boolean filterByInUse; - - protected RegularStopRequest(Envelope envelope, String agency, boolean filterByInUse) { - this.envelope = envelope; - this.agency = agency; - this.filterByInUse = filterByInUse; - } - - public static RegularStopRequestBuilder of(Envelope envelope) { - return new RegularStopRequestBuilder(envelope); - } - - public Envelope envelope() { - return envelope; - } - - @Nullable - public String agency() { - return agency; - } - - public boolean filterByInUse() { - return filterByInUse; - } -} diff --git a/application/src/main/java/org/opentripplanner/transit/api/request/RegularStopRequestBuilder.java b/application/src/main/java/org/opentripplanner/transit/api/request/RegularStopRequestBuilder.java deleted file mode 100644 index cd26f25d811..00000000000 --- a/application/src/main/java/org/opentripplanner/transit/api/request/RegularStopRequestBuilder.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.opentripplanner.transit.api.request; - -import org.locationtech.jts.geom.Envelope; - -public class RegularStopRequestBuilder { - - private Envelope envelope; - private String agency; - private boolean filterByInUse = false; - - protected RegularStopRequestBuilder(Envelope envelope) { - this.envelope = envelope; - } - - public RegularStopRequestBuilder withFeed(String agency) { - this.agency = agency; - return this; - } - - public RegularStopRequestBuilder filterByInUse(boolean filterByInUse) { - this.filterByInUse = filterByInUse; - return this; - } - - public RegularStopRequest build() { - return new RegularStopRequest(envelope, agency, filterByInUse); - } -} diff --git a/application/src/main/java/org/opentripplanner/transit/model/filter/transit/RegularStopMatcherFactory.java b/application/src/main/java/org/opentripplanner/transit/model/filter/transit/RegularStopMatcherFactory.java index 8a86d45bfcf..75ad70a32c9 100644 --- a/application/src/main/java/org/opentripplanner/transit/model/filter/transit/RegularStopMatcherFactory.java +++ b/application/src/main/java/org/opentripplanner/transit/model/filter/transit/RegularStopMatcherFactory.java @@ -1,7 +1,7 @@ package org.opentripplanner.transit.model.filter.transit; import java.util.function.Predicate; -import org.opentripplanner.transit.api.request.RegularStopRequest; +import org.opentripplanner.transit.api.request.FindRegularStopsByBoundingBoxRequest; import org.opentripplanner.transit.model.filter.expr.EqualityMatcher; import org.opentripplanner.transit.model.filter.expr.ExpressionBuilder; import org.opentripplanner.transit.model.filter.expr.GenericUnaryMatcher; @@ -17,22 +17,22 @@ public class RegularStopMatcherFactory { /** - * Creates a matcher that filters {@link RegularStop} objects with the provided {@link RegularStopRequest} + * Creates a matcher that filters {@link RegularStop} objects with the provided {@link FindRegularStopsByBoundingBoxRequest} * and {@link Predicate}. The {@link Predicate} is used to determine if a {@link RegularStop} is * in use. Typically the inUseProvider is a function that checks if the {@link RegularStop} is in * a set of used stops. - * @param request - {@link RegularStopRequest} to filter {@link RegularStop} objects. + * @param request - {@link FindRegularStopsByBoundingBoxRequest} to filter {@link RegularStop} objects. * @param inUseProvider - {@link Predicate} to determine if a {@link RegularStop} is in use. * @return - {@link Matcher} for {@link RegularStop} objects. */ public static Matcher of( - RegularStopRequest request, + FindRegularStopsByBoundingBoxRequest request, Predicate inUseProvider ) { ExpressionBuilder expr = ExpressionBuilder.of(); - if (request.agency() != null) { - expr.matches(agency(request.agency())); + if (request.feedId() != null) { + expr.matches(feedId(request.feedId())); } if (request.filterByInUse()) { expr.matches(inUseMatcher(inUseProvider)); @@ -40,8 +40,8 @@ public static Matcher of( return expr.build(); } - static Matcher agency(String agency) { - return new EqualityMatcher<>("agency", agency, stop -> stop.getId().getFeedId()); + static Matcher feedId(String feedId) { + return new EqualityMatcher<>("feedId", feedId, stop -> stop.getId().getFeedId()); } static Matcher inUseMatcher(Predicate inUseProvider) { diff --git a/application/src/main/java/org/opentripplanner/transit/service/DefaultTransitService.java b/application/src/main/java/org/opentripplanner/transit/service/DefaultTransitService.java index 893a3f54f94..77f63729fd9 100644 --- a/application/src/main/java/org/opentripplanner/transit/service/DefaultTransitService.java +++ b/application/src/main/java/org/opentripplanner/transit/service/DefaultTransitService.java @@ -34,7 +34,7 @@ import org.opentripplanner.routing.services.TransitAlertService; import org.opentripplanner.routing.stoptimes.ArrivalDeparture; import org.opentripplanner.routing.stoptimes.StopTimesHelper; -import org.opentripplanner.transit.api.request.RegularStopRequest; +import org.opentripplanner.transit.api.request.FindRegularStopsByBoundingBoxRequest; import org.opentripplanner.transit.api.request.TripOnServiceDateRequest; import org.opentripplanner.transit.api.request.TripRequest; import org.opentripplanner.transit.model.basic.Notice; @@ -684,13 +684,15 @@ public ZonedDateTime getTransitServiceStarts() { } @Override - public Collection findRegularStops(Envelope envelope) { + public Collection findRegularStopsByBoundingBox(Envelope envelope) { OTPRequestTimeoutException.checkForTimeout(); return timetableRepository.getSiteRepository().findRegularStops(envelope); } @Override - public Collection findRegularStops(RegularStopRequest request) { + public Collection findRegularStopsByBoundingBox( + FindRegularStopsByBoundingBoxRequest request + ) { OTPRequestTimeoutException.checkForTimeout(); Collection stops = timetableRepository .getSiteRepository() diff --git a/application/src/main/java/org/opentripplanner/transit/service/TransitService.java b/application/src/main/java/org/opentripplanner/transit/service/TransitService.java index 741a2848b68..db877b82a6a 100644 --- a/application/src/main/java/org/opentripplanner/transit/service/TransitService.java +++ b/application/src/main/java/org/opentripplanner/transit/service/TransitService.java @@ -24,7 +24,7 @@ import org.opentripplanner.routing.algorithm.raptoradapter.transit.TransitLayer; import org.opentripplanner.routing.services.TransitAlertService; import org.opentripplanner.routing.stoptimes.ArrivalDeparture; -import org.opentripplanner.transit.api.request.RegularStopRequest; +import org.opentripplanner.transit.api.request.FindRegularStopsByBoundingBoxRequest; import org.opentripplanner.transit.api.request.TripOnServiceDateRequest; import org.opentripplanner.transit.api.request.TripRequest; import org.opentripplanner.transit.model.basic.Notice; @@ -267,7 +267,7 @@ List findTripTimeOnDate( boolean transitFeedCovers(Instant dateTime); - Collection findRegularStops(Envelope envelope); + Collection findRegularStopsByBoundingBox(Envelope envelope); Collection findAreaStops(Envelope envelope); @@ -327,10 +327,13 @@ List findTripTimeOnDate( boolean containsTrip(FeedScopedId id); /** - * Returns a list of RegularStops that match the filtering defined in the request. + * Returns a list of RegularStops that lay within a bounding box and match the other criteria in + * the request object. * - * @param request - A {@link RegularStopRequest} object with filtering defined. + * @param request - A {@link FindRegularStopsByBoundingBoxRequest} object with filtering defined. * @return - A list of {@link RegularStop}s */ - Collection findRegularStops(RegularStopRequest request); + Collection findRegularStopsByBoundingBox( + FindRegularStopsByBoundingBoxRequest request + ); } diff --git a/application/src/main/resources/org/opentripplanner/apis/transmodel/schema.graphql b/application/src/main/resources/org/opentripplanner/apis/transmodel/schema.graphql index 9900f842250..46f70cfccd4 100644 --- a/application/src/main/resources/org/opentripplanner/apis/transmodel/schema.graphql +++ b/application/src/main/resources/org/opentripplanner/apis/transmodel/schema.graphql @@ -702,8 +702,7 @@ type QueryType { quays(ids: [String], name: String): [Quay]! @timingData "Get all quays within the specified bounding box" quaysByBbox( - "The ID of the authority to fetch stops for." - authority: String, + authority: String @deprecated(reason : "This is the Transmodel namespace or the GTFS feedID - avoid using this. Request a new field if necessary."), "If true only quays with at least one visiting line are included." filterByInUse: Boolean = false, maximumLatitude: Float!, diff --git a/application/src/test/java/org/opentripplanner/apis/gtfs/mapping/routerequest/LegacyRouteRequestMapperTest.java b/application/src/test/java/org/opentripplanner/apis/gtfs/mapping/routerequest/LegacyRouteRequestMapperTest.java index 43dd10dbdce..17193ad02c1 100644 --- a/application/src/test/java/org/opentripplanner/apis/gtfs/mapping/routerequest/LegacyRouteRequestMapperTest.java +++ b/application/src/test/java/org/opentripplanner/apis/gtfs/mapping/routerequest/LegacyRouteRequestMapperTest.java @@ -65,7 +65,7 @@ class LegacyRouteRequestMapperTest implements PlanTestConstants { new DefaultVehicleRentalService(), new DefaultVehicleParkingService(new DefaultVehicleParkingRepository()), new DefaultRealtimeVehicleService(transitService), - GraphFinder.getInstance(graph, transitService::findRegularStops), + GraphFinder.getInstance(graph, transitService::findRegularStopsByBoundingBox), new RouteRequest() ); } diff --git a/application/src/test/java/org/opentripplanner/apis/gtfs/mapping/routerequest/RouteRequestMapperTest.java b/application/src/test/java/org/opentripplanner/apis/gtfs/mapping/routerequest/RouteRequestMapperTest.java index 34cb865c81a..925e5009e77 100644 --- a/application/src/test/java/org/opentripplanner/apis/gtfs/mapping/routerequest/RouteRequestMapperTest.java +++ b/application/src/test/java/org/opentripplanner/apis/gtfs/mapping/routerequest/RouteRequestMapperTest.java @@ -75,7 +75,7 @@ class RouteRequestMapperTest { new DefaultVehicleRentalService(), new DefaultVehicleParkingService(new DefaultVehicleParkingRepository()), new DefaultRealtimeVehicleService(transitService), - GraphFinder.getInstance(graph, transitService::findRegularStops), + GraphFinder.getInstance(graph, transitService::findRegularStopsByBoundingBox), new RouteRequest() ); } diff --git a/application/src/test/java/org/opentripplanner/routing/graph/DefaultRoutingServiceTest.java b/application/src/test/java/org/opentripplanner/routing/graph/DefaultRoutingServiceTest.java index ab897e3410b..48363a98c88 100644 --- a/application/src/test/java/org/opentripplanner/routing/graph/DefaultRoutingServiceTest.java +++ b/application/src/test/java/org/opentripplanner/routing/graph/DefaultRoutingServiceTest.java @@ -115,7 +115,7 @@ public void testSpatialIndex() { SphericalDistanceLibrary.metersToLonDegrees(100, stopJ.getLat()), SphericalDistanceLibrary.metersToDegrees(100) ); - Collection stops = transitService.findRegularStops(env); + Collection stops = transitService.findRegularStopsByBoundingBox(env); assertTrue(stops.contains(stopJ)); assertTrue(stops.contains(stopL)); assertTrue(stops.contains(stopM)); diff --git a/application/src/test/java/org/opentripplanner/transit/model/filter/transit/RegularStopMatcherFactoryTest.java b/application/src/test/java/org/opentripplanner/transit/model/filter/transit/RegularStopMatcherFactoryTest.java index 100405f6fba..5cfeaf2780f 100644 --- a/application/src/test/java/org/opentripplanner/transit/model/filter/transit/RegularStopMatcherFactoryTest.java +++ b/application/src/test/java/org/opentripplanner/transit/model/filter/transit/RegularStopMatcherFactoryTest.java @@ -28,7 +28,7 @@ static void setup() { @Test void testFeedIds() { - var matcher = RegularStopMatcherFactory.agency("agency"); + var matcher = RegularStopMatcherFactory.feedId("agency"); assertTrue(matcher.match(stop1)); assertFalse(matcher.match(stop2)); } From de3e9c69e5b1e92cf80893b70e3c219c53f76252 Mon Sep 17 00:00:00 2001 From: Eivind Morris Bakke Date: Thu, 19 Dec 2024 15:15:38 +0100 Subject: [PATCH 08/14] Update application/src/main/java/org/opentripplanner/transit/api/request/FindRegularStopsByBoundingBoxRequest.java Co-authored-by: Thomas Gran --- .../api/request/FindRegularStopsByBoundingBoxRequest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/src/main/java/org/opentripplanner/transit/api/request/FindRegularStopsByBoundingBoxRequest.java b/application/src/main/java/org/opentripplanner/transit/api/request/FindRegularStopsByBoundingBoxRequest.java index 6acdc784a08..d7494b2807b 100644 --- a/application/src/main/java/org/opentripplanner/transit/api/request/FindRegularStopsByBoundingBoxRequest.java +++ b/application/src/main/java/org/opentripplanner/transit/api/request/FindRegularStopsByBoundingBoxRequest.java @@ -19,7 +19,7 @@ public class FindRegularStopsByBoundingBoxRequest { private final boolean filterByInUse; - protected FindRegularStopsByBoundingBoxRequest( + FindRegularStopsByBoundingBoxRequest( Envelope envelope, @Nullable String feedId, boolean filterByInUse From 43643889f5f7cd09fe3320adfa63a42b9df8a25b Mon Sep 17 00:00:00 2001 From: Eivind Morris Bakke Date: Thu, 19 Dec 2024 15:15:48 +0100 Subject: [PATCH 09/14] Update application/src/main/java/org/opentripplanner/transit/api/request/FindRegularStopsByBoundingBoxRequestBuilder.java Co-authored-by: Thomas Gran --- .../request/FindRegularStopsByBoundingBoxRequestBuilder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/src/main/java/org/opentripplanner/transit/api/request/FindRegularStopsByBoundingBoxRequestBuilder.java b/application/src/main/java/org/opentripplanner/transit/api/request/FindRegularStopsByBoundingBoxRequestBuilder.java index 9d7413ba77b..baf6df67df4 100644 --- a/application/src/main/java/org/opentripplanner/transit/api/request/FindRegularStopsByBoundingBoxRequestBuilder.java +++ b/application/src/main/java/org/opentripplanner/transit/api/request/FindRegularStopsByBoundingBoxRequestBuilder.java @@ -12,7 +12,7 @@ public class FindRegularStopsByBoundingBoxRequestBuilder { private boolean filterByInUse = false; - protected FindRegularStopsByBoundingBoxRequestBuilder(Envelope envelope) { + FindRegularStopsByBoundingBoxRequestBuilder(Envelope envelope) { this.envelope = envelope; } From 6e37051156758699ae23dda5c988e7f62777cdc1 Mon Sep 17 00:00:00 2001 From: Eivind Morris Bakke Date: Thu, 19 Dec 2024 15:16:52 +0100 Subject: [PATCH 10/14] Update application/src/main/java/org/opentripplanner/transit/model/filter/transit/RegularStopMatcherFactory.java Co-authored-by: Thomas Gran --- .../model/filter/transit/RegularStopMatcherFactory.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/application/src/main/java/org/opentripplanner/transit/model/filter/transit/RegularStopMatcherFactory.java b/application/src/main/java/org/opentripplanner/transit/model/filter/transit/RegularStopMatcherFactory.java index 75ad70a32c9..06b966ef210 100644 --- a/application/src/main/java/org/opentripplanner/transit/model/filter/transit/RegularStopMatcherFactory.java +++ b/application/src/main/java/org/opentripplanner/transit/model/filter/transit/RegularStopMatcherFactory.java @@ -17,8 +17,8 @@ public class RegularStopMatcherFactory { /** - * Creates a matcher that filters {@link RegularStop} objects with the provided {@link FindRegularStopsByBoundingBoxRequest} - * and {@link Predicate}. The {@link Predicate} is used to determine if a {@link RegularStop} is + * Creates a matcher that filters {@link RegularStop} objects with the provided {@code request} + * and {@link inUseProvider}. The {@link inUseProvider} is used to determine if a {@link RegularStop} is * in use. Typically the inUseProvider is a function that checks if the {@link RegularStop} is in * a set of used stops. * @param request - {@link FindRegularStopsByBoundingBoxRequest} to filter {@link RegularStop} objects. From 1c53bbbd30edfb3081a9eff00a6eeb4c3429595f Mon Sep 17 00:00:00 2001 From: Eivind Morris Bakke Date: Thu, 19 Dec 2024 15:18:10 +0100 Subject: [PATCH 11/14] Update application/src/main/java/org/opentripplanner/transit/model/filter/transit/RegularStopMatcherFactory.java Co-authored-by: Thomas Gran --- .../model/filter/transit/RegularStopMatcherFactory.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/application/src/main/java/org/opentripplanner/transit/model/filter/transit/RegularStopMatcherFactory.java b/application/src/main/java/org/opentripplanner/transit/model/filter/transit/RegularStopMatcherFactory.java index 06b966ef210..a9f0132cc15 100644 --- a/application/src/main/java/org/opentripplanner/transit/model/filter/transit/RegularStopMatcherFactory.java +++ b/application/src/main/java/org/opentripplanner/transit/model/filter/transit/RegularStopMatcherFactory.java @@ -21,9 +21,6 @@ public class RegularStopMatcherFactory { * and {@link inUseProvider}. The {@link inUseProvider} is used to determine if a {@link RegularStop} is * in use. Typically the inUseProvider is a function that checks if the {@link RegularStop} is in * a set of used stops. - * @param request - {@link FindRegularStopsByBoundingBoxRequest} to filter {@link RegularStop} objects. - * @param inUseProvider - {@link Predicate} to determine if a {@link RegularStop} is in use. - * @return - {@link Matcher} for {@link RegularStop} objects. */ public static Matcher of( FindRegularStopsByBoundingBoxRequest request, From 46d67ebeec6aa23751aeedef69093ee0355493fe Mon Sep 17 00:00:00 2001 From: Eivind Morris Bakke Date: Thu, 19 Dec 2024 15:18:41 +0100 Subject: [PATCH 12/14] Update application/src/main/java/org/opentripplanner/transit/service/TransitService.java Co-authored-by: Thomas Gran --- .../org/opentripplanner/transit/service/TransitService.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/application/src/main/java/org/opentripplanner/transit/service/TransitService.java b/application/src/main/java/org/opentripplanner/transit/service/TransitService.java index db877b82a6a..86d1d591d8e 100644 --- a/application/src/main/java/org/opentripplanner/transit/service/TransitService.java +++ b/application/src/main/java/org/opentripplanner/transit/service/TransitService.java @@ -313,8 +313,6 @@ List findTripTimeOnDate( /** * Returns a list of Trips that match the filtering defined in the request. * - * @param request - A {@link TripRequest} object with filtering defined. - * @return - A list of {@link Trip}s */ List getTrips(TripRequest request); From b6f389b0836f5d7b3e1d6947fd80cc92aa7dcc85 Mon Sep 17 00:00:00 2001 From: Eivind Morris Bakke Date: Thu, 19 Dec 2024 15:19:01 +0100 Subject: [PATCH 13/14] Update application/src/main/java/org/opentripplanner/transit/service/TransitService.java Co-authored-by: Thomas Gran --- .../org/opentripplanner/transit/service/TransitService.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/application/src/main/java/org/opentripplanner/transit/service/TransitService.java b/application/src/main/java/org/opentripplanner/transit/service/TransitService.java index 86d1d591d8e..052e6c6e91d 100644 --- a/application/src/main/java/org/opentripplanner/transit/service/TransitService.java +++ b/application/src/main/java/org/opentripplanner/transit/service/TransitService.java @@ -327,9 +327,6 @@ List findTripTimeOnDate( /** * Returns a list of RegularStops that lay within a bounding box and match the other criteria in * the request object. - * - * @param request - A {@link FindRegularStopsByBoundingBoxRequest} object with filtering defined. - * @return - A list of {@link RegularStop}s */ Collection findRegularStopsByBoundingBox( FindRegularStopsByBoundingBoxRequest request From 8bd684589d2303f25b4545bb5902ef6f46b17582 Mon Sep 17 00:00:00 2001 From: eibakke Date: Thu, 19 Dec 2024 15:49:43 +0100 Subject: [PATCH 14/14] Addresses comments in code review. --- .../FindRegularStopsByBoundingBoxRequest.java | 2 +- .../FindRegularStopsByBoundingBoxRequestBuilder.java | 2 +- .../api/request/TripOnServiceDateRequest.java | 4 ++-- .../api/request/TripOnServiceDateRequestBuilder.java | 4 ++-- .../transit/api/request/TripRequest.java | 2 +- .../transit/api/request/TripRequestBuilder.java | 2 +- .../filter/transit/RegularStopMatcherFactory.java | 6 +++--- .../transit/service/TransitService.java | 12 +++++------- 8 files changed, 16 insertions(+), 18 deletions(-) diff --git a/application/src/main/java/org/opentripplanner/transit/api/request/FindRegularStopsByBoundingBoxRequest.java b/application/src/main/java/org/opentripplanner/transit/api/request/FindRegularStopsByBoundingBoxRequest.java index d7494b2807b..476e23d7cd8 100644 --- a/application/src/main/java/org/opentripplanner/transit/api/request/FindRegularStopsByBoundingBoxRequest.java +++ b/application/src/main/java/org/opentripplanner/transit/api/request/FindRegularStopsByBoundingBoxRequest.java @@ -19,7 +19,7 @@ public class FindRegularStopsByBoundingBoxRequest { private final boolean filterByInUse; - FindRegularStopsByBoundingBoxRequest( + FindRegularStopsByBoundingBoxRequest( Envelope envelope, @Nullable String feedId, boolean filterByInUse diff --git a/application/src/main/java/org/opentripplanner/transit/api/request/FindRegularStopsByBoundingBoxRequestBuilder.java b/application/src/main/java/org/opentripplanner/transit/api/request/FindRegularStopsByBoundingBoxRequestBuilder.java index baf6df67df4..49d31c33db9 100644 --- a/application/src/main/java/org/opentripplanner/transit/api/request/FindRegularStopsByBoundingBoxRequestBuilder.java +++ b/application/src/main/java/org/opentripplanner/transit/api/request/FindRegularStopsByBoundingBoxRequestBuilder.java @@ -12,7 +12,7 @@ public class FindRegularStopsByBoundingBoxRequestBuilder { private boolean filterByInUse = false; - FindRegularStopsByBoundingBoxRequestBuilder(Envelope envelope) { + FindRegularStopsByBoundingBoxRequestBuilder(Envelope envelope) { this.envelope = envelope; } diff --git a/application/src/main/java/org/opentripplanner/transit/api/request/TripOnServiceDateRequest.java b/application/src/main/java/org/opentripplanner/transit/api/request/TripOnServiceDateRequest.java index c61bb8ad107..54dd1c7aea6 100644 --- a/application/src/main/java/org/opentripplanner/transit/api/request/TripOnServiceDateRequest.java +++ b/application/src/main/java/org/opentripplanner/transit/api/request/TripOnServiceDateRequest.java @@ -23,7 +23,7 @@ public class TripOnServiceDateRequest { private final FilterValues netexInternalPlanningCodes; private final FilterValues alterations; - protected TripOnServiceDateRequest( + TripOnServiceDateRequest( RequiredFilterValues serviceDates, FilterValues agencies, FilterValues routes, @@ -41,7 +41,7 @@ protected TripOnServiceDateRequest( this.alterations = alterations; } - public static TripOnServiceDateRequestBuilder of(RequiredFilterValues serviceDates) { + public static TripOnServiceDateRequestBuilder of(RequiredFilterValues serviceDates) { return new TripOnServiceDateRequestBuilder(serviceDates); } diff --git a/application/src/main/java/org/opentripplanner/transit/api/request/TripOnServiceDateRequestBuilder.java b/application/src/main/java/org/opentripplanner/transit/api/request/TripOnServiceDateRequestBuilder.java index 534557c15d8..3181819a400 100644 --- a/application/src/main/java/org/opentripplanner/transit/api/request/TripOnServiceDateRequestBuilder.java +++ b/application/src/main/java/org/opentripplanner/transit/api/request/TripOnServiceDateRequestBuilder.java @@ -30,9 +30,9 @@ public class TripOnServiceDateRequestBuilder { "alterations", List.of() ); - private RequiredFilterValues serviceDates; + private final RequiredFilterValues serviceDates; - protected TripOnServiceDateRequestBuilder(RequiredFilterValues serviceDates) { + TripOnServiceDateRequestBuilder(RequiredFilterValues serviceDates) { this.serviceDates = serviceDates; } diff --git a/application/src/main/java/org/opentripplanner/transit/api/request/TripRequest.java b/application/src/main/java/org/opentripplanner/transit/api/request/TripRequest.java index c73e800582b..5e05b472937 100644 --- a/application/src/main/java/org/opentripplanner/transit/api/request/TripRequest.java +++ b/application/src/main/java/org/opentripplanner/transit/api/request/TripRequest.java @@ -17,7 +17,7 @@ public class TripRequest { private final FilterValues netexInternalPlanningCodes; private final FilterValues serviceDates; - protected TripRequest( + TripRequest( FilterValues agencies, FilterValues routes, FilterValues netexInternalPlanningCodes, diff --git a/application/src/main/java/org/opentripplanner/transit/api/request/TripRequestBuilder.java b/application/src/main/java/org/opentripplanner/transit/api/request/TripRequestBuilder.java index 3a2f80a3e34..32ca31d5cd6 100644 --- a/application/src/main/java/org/opentripplanner/transit/api/request/TripRequestBuilder.java +++ b/application/src/main/java/org/opentripplanner/transit/api/request/TripRequestBuilder.java @@ -21,7 +21,7 @@ public class TripRequestBuilder { List.of() ); - protected TripRequestBuilder() {} + TripRequestBuilder() {} public TripRequestBuilder withAgencies(FilterValues agencies) { this.agencies = agencies; diff --git a/application/src/main/java/org/opentripplanner/transit/model/filter/transit/RegularStopMatcherFactory.java b/application/src/main/java/org/opentripplanner/transit/model/filter/transit/RegularStopMatcherFactory.java index a9f0132cc15..261e7057d95 100644 --- a/application/src/main/java/org/opentripplanner/transit/model/filter/transit/RegularStopMatcherFactory.java +++ b/application/src/main/java/org/opentripplanner/transit/model/filter/transit/RegularStopMatcherFactory.java @@ -18,9 +18,9 @@ public class RegularStopMatcherFactory { /** * Creates a matcher that filters {@link RegularStop} objects with the provided {@code request} - * and {@link inUseProvider}. The {@link inUseProvider} is used to determine if a {@link RegularStop} is - * in use. Typically the inUseProvider is a function that checks if the {@link RegularStop} is in - * a set of used stops. + * and {@code inUseProvider}. The {@code inUseProvider} is used to determine if a {@link RegularStop} is + * in use. The inUseProvider is an injected function, because the check is done by the transit service + * which has access to all stops and routes. A stop is used if it has routes visiting the stop. */ public static Matcher of( FindRegularStopsByBoundingBoxRequest request, diff --git a/application/src/main/java/org/opentripplanner/transit/service/TransitService.java b/application/src/main/java/org/opentripplanner/transit/service/TransitService.java index 052e6c6e91d..c423c18d770 100644 --- a/application/src/main/java/org/opentripplanner/transit/service/TransitService.java +++ b/application/src/main/java/org/opentripplanner/transit/service/TransitService.java @@ -283,6 +283,7 @@ List findTripTimeOnDate( * So, if more patterns of mode BUS than RAIL visit the group, the result will be [BUS,RAIL]. */ List findTransitModes(StopLocationsGroup station); + /** * For a {@link StopLocation} return its modes. *

@@ -303,15 +304,12 @@ List findTripTimeOnDate( Map getServiceCodesRunningForDate(); /** - * Returns a list of TripOnServiceDates that match the filtering defined in the request. - * - * @param request - A {@link TripOnServiceDateRequest} object with filtering defined. - * @return - A list of {@link TripOnServiceDate}s + * Returns a list of {@link TripOnServiceDate}s that match the filtering defined in the request. */ List findTripsOnServiceDate(TripOnServiceDateRequest request); /** - * Returns a list of Trips that match the filtering defined in the request. + * Returns a list of {@link Trip}s that match the filtering defined in the request. * */ List getTrips(TripRequest request); @@ -325,8 +323,8 @@ List findTripTimeOnDate( boolean containsTrip(FeedScopedId id); /** - * Returns a list of RegularStops that lay within a bounding box and match the other criteria in - * the request object. + * Returns a list of {@link RegularStop}s that lay within a bounding box and match the other criteria + * in the request object. */ Collection findRegularStopsByBoundingBox( FindRegularStopsByBoundingBoxRequest request