-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a matcher API for filters in the transit service used for regular…
…Stop lookup (#6234) * 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. * Updates the RegularStopRequest to latest concepts. * Adds @nullable to feedId method on the RegularStopRequest. * Changes feedId to be called agency. * Update application/src/test/java/org/opentripplanner/transit/model/filter/transit/RegularStopMatcherFactoryTest.java Co-authored-by: Leonard Ehrenfried <mail@leonard.io> * Fixes test failure. * Addresses comments in code review. * Update application/src/main/java/org/opentripplanner/transit/api/request/FindRegularStopsByBoundingBoxRequest.java Co-authored-by: Thomas Gran <t2gran@gmail.com> * Update application/src/main/java/org/opentripplanner/transit/api/request/FindRegularStopsByBoundingBoxRequestBuilder.java Co-authored-by: Thomas Gran <t2gran@gmail.com> * Update application/src/main/java/org/opentripplanner/transit/model/filter/transit/RegularStopMatcherFactory.java Co-authored-by: Thomas Gran <t2gran@gmail.com> * Update application/src/main/java/org/opentripplanner/transit/model/filter/transit/RegularStopMatcherFactory.java Co-authored-by: Thomas Gran <t2gran@gmail.com> * Update application/src/main/java/org/opentripplanner/transit/service/TransitService.java Co-authored-by: Thomas Gran <t2gran@gmail.com> * Update application/src/main/java/org/opentripplanner/transit/service/TransitService.java Co-authored-by: Thomas Gran <t2gran@gmail.com> * Addresses comments in code review. --------- Co-authored-by: Leonard Ehrenfried <mail@leonard.io> Co-authored-by: Thomas Gran <t2gran@gmail.com>
- Loading branch information
1 parent
d61504a
commit 72019c0
Showing
28 changed files
with
313 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
application/src/main/java/org/opentripplanner/transit/api/model/FilterValues.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...in/java/org/opentripplanner/transit/api/request/FindRegularStopsByBoundingBoxRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||
* <p/> | ||
* 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; | ||
|
||
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; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
.../org/opentripplanner/transit/api/request/FindRegularStopsByBoundingBoxRequestBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
|
||
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...tion/src/main/java/org/opentripplanner/transit/model/filter/expr/GenericUnaryMatcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||
* <p/> | ||
* @param <T> The type of the entity being matched. | ||
*/ | ||
public class GenericUnaryMatcher<T> implements Matcher<T> { | ||
|
||
private final String typeName; | ||
private final Predicate<T> 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<T> matchPredicate) { | ||
this.typeName = typeName; | ||
this.matchPredicate = matchPredicate; | ||
} | ||
|
||
@Override | ||
public boolean match(T entity) { | ||
return matchPredicate.test(entity); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "GenericUnaryMatcher: " + typeName; | ||
} | ||
} |
Oops, something went wrong.