Skip to content

Commit 33168e3

Browse files
Use a more consistent handling of includes
1 parent 98e1fd4 commit 33168e3

File tree

2 files changed

+40
-19
lines changed

2 files changed

+40
-19
lines changed

application/src/ext/java/org/opentripplanner/ext/trias/service/OjpService.java

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,19 +100,27 @@ private List<CallAtStop> findCallsAtStop(
100100
"Number of departures must be less than " + MAX_DEPARTURES
101101
);
102102
}
103-
var request = TripTimeOnDateRequest.of(stopLocations)
103+
var builder = TripTimeOnDateRequest.of(stopLocations)
104104
.withTime(params.time)
105105
.withArrivalDeparture(params.arrivalDeparture)
106106
.withTimeWindow(params.timeWindow)
107107
.withNumberOfDepartures(params.numDepartures)
108-
.withIncludeAgencies(params.includedAgencies)
109-
.withIncludeRoutes(params.includedRoutes)
110108
.withExcludeAgencies(params.excludedAgencies)
111109
.withExcludeRoutes(params.excludedRoutes)
112-
.withIncludeModes(params.includedModes)
113110
.withExcludeModes(params.excludedModes)
114-
.withSortOrder(TripTimeOnDate.compareByScheduledDeparture())
115-
.build();
111+
.withSortOrder(TripTimeOnDate.compareByScheduledDeparture());
112+
113+
if (params.includesAgencies()) {
114+
builder.withIncludeAgencies(params.includedAgencies);
115+
}
116+
if (params.includesRoutes()) {
117+
builder.withIncludeRoutes(params.includedRoutes);
118+
}
119+
if (params.includesModes()) {
120+
builder.withIncludeModes(params.includedModes);
121+
}
122+
123+
var request = builder.build();
116124
return transitService.findTripTimesOnDate(request).stream().map(CallAtStop::noWalking).toList();
117125
}
118126

@@ -128,5 +136,15 @@ public record StopEventRequestParams(
128136
Set<FeedScopedId> excludedRoutes,
129137
Set<TransitMode> includedModes,
130138
Set<TransitMode> excludedModes
131-
) {}
139+
) {
140+
public boolean includesAgencies() {
141+
return !includedAgencies.isEmpty();
142+
}
143+
public boolean includesRoutes() {
144+
return !includedAgencies.isEmpty();
145+
}
146+
public boolean includesModes() {
147+
return !includedModes.isEmpty();
148+
}
149+
}
132150
}

application/src/main/java/org/opentripplanner/transit/api/request/TripTimeOnDateRequestBuilder.java

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.util.Collection;
66
import java.util.Comparator;
77
import java.util.List;
8+
import javax.annotation.Nullable;
89
import org.opentripplanner.model.TripTimeOnDate;
910
import org.opentripplanner.transit.api.model.FilterValues;
1011
import org.opentripplanner.transit.model.basic.TransitMode;
@@ -21,13 +22,13 @@ public class TripTimeOnDateRequestBuilder {
2122
private static final String EXCLUDE_ROUTES = "excludeRoutes";
2223
private static final String EXCLUDE_MODES = "excludeModes";
2324
private final Collection<StopLocation> stopLocations;
24-
private FilterValues<FeedScopedId> includeAgencies = FilterValues.ofEmptyIsEverything(
25+
private FilterValues<FeedScopedId> includeAgencies = FilterValues.ofNullIsEverything(
2526
INCLUDE_AGENCIES,
26-
List.of()
27+
null
2728
);
28-
private FilterValues<FeedScopedId> includeRoutes = FilterValues.ofEmptyIsEverything(
29+
private FilterValues<FeedScopedId> includeRoutes = FilterValues.ofNullIsEverything(
2930
INCLUDE_ROUTES,
30-
List.of()
31+
null
3132
);
3233
private FilterValues<FeedScopedId> excludeAgencies = FilterValues.ofEmptyIsEverything(
3334
EXCLUDE_AGENCIES,
@@ -37,9 +38,9 @@ public class TripTimeOnDateRequestBuilder {
3738
EXCLUDE_ROUTES,
3839
List.of()
3940
);
40-
private FilterValues<TransitMode> includeModes = FilterValues.ofEmptyIsEverything(
41+
private FilterValues<TransitMode> includeModes = FilterValues.ofNullIsEverything(
4142
INCLUDE_MODES,
42-
List.of()
43+
null
4344
);
4445
private FilterValues<TransitMode> excludeModes = FilterValues.ofEmptyIsEverything(
4546
EXCLUDE_MODES,
@@ -60,13 +61,15 @@ public TripTimeOnDateRequestBuilder withTime(Instant time) {
6061
return this;
6162
}
6263

63-
public TripTimeOnDateRequestBuilder withIncludeAgencies(Collection<FeedScopedId> agencies) {
64-
this.includeAgencies = FilterValues.ofEmptyIsEverything(INCLUDE_AGENCIES, agencies);
64+
public TripTimeOnDateRequestBuilder withIncludeAgencies(
65+
@Nullable Collection<FeedScopedId> agencies
66+
) {
67+
this.includeAgencies = FilterValues.ofNullIsEverything(INCLUDE_AGENCIES, agencies);
6568
return this;
6669
}
6770

68-
public TripTimeOnDateRequestBuilder withIncludeRoutes(Collection<FeedScopedId> routes) {
69-
this.includeRoutes = FilterValues.ofEmptyIsEverything(INCLUDE_ROUTES, routes);
71+
public TripTimeOnDateRequestBuilder withIncludeRoutes(@Nullable Collection<FeedScopedId> routes) {
72+
this.includeRoutes = FilterValues.ofNullIsEverything(INCLUDE_ROUTES, routes);
7073
return this;
7174
}
7275

@@ -80,8 +83,8 @@ public TripTimeOnDateRequestBuilder withExcludeRoutes(Collection<FeedScopedId> r
8083
return this;
8184
}
8285

83-
public TripTimeOnDateRequestBuilder withIncludeModes(Collection<TransitMode> modes) {
84-
this.includeModes = FilterValues.ofEmptyIsEverything(INCLUDE_MODES, modes);
86+
public TripTimeOnDateRequestBuilder withIncludeModes(@Nullable Collection<TransitMode> modes) {
87+
this.includeModes = FilterValues.ofNullIsEverything(INCLUDE_MODES, modes);
8588
return this;
8689
}
8790

0 commit comments

Comments
 (0)