forked from HSLdevcom/OpenTripPlanner
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Importantly this creates the CriteriaCollection type which allows for checking features about collections of criteria independently of the collection type.
- Loading branch information
Showing
12 changed files
with
250 additions
and
134 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
42 changes: 42 additions & 0 deletions
42
application/src/main/java/org/opentripplanner/transit/api/model/CriteriaCollection.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,42 @@ | ||
package org.opentripplanner.transit.api.model; | ||
|
||
import com.beust.jcommander.internal.Nullable; | ||
import java.util.Collection; | ||
import org.opentripplanner.transit.model.framework.FeedScopedId; | ||
import org.opentripplanner.transit.service.TransitService; | ||
|
||
/** | ||
* CriteriaCollection is meant to be used when filtering results from {@link TransitService}. | ||
* </p> | ||
* This abstraction over the Collection type lets us keep filter specific functionality separate | ||
* from interpretation of various states of a collection. For instance in which case the criteria | ||
* should match all entities it's meant to filter. | ||
* @param <E> - The type of the criteria. Typically, String or {@link FeedScopedId}. | ||
*/ | ||
public class CriteriaCollection<E> { | ||
|
||
private Collection<E> criteria; | ||
|
||
CriteriaCollection(Collection<E> criteria) { | ||
this.criteria = criteria; | ||
} | ||
|
||
public static <E> CriteriaCollection<E> of(@Nullable Collection<E> criteria) { | ||
return new CriteriaCollection<>(criteria); | ||
} | ||
|
||
public static <E> CriteriaCollection<E> of(@Nullable CriteriaCollection<E> criteria) { | ||
if (criteria == null) { | ||
return new CriteriaCollection<>(null); | ||
} | ||
return criteria; | ||
} | ||
|
||
public boolean matchesAll() { | ||
return criteria == null || criteria.isEmpty(); | ||
} | ||
|
||
public Collection<E> values() { | ||
return criteria; | ||
} | ||
} |
63 changes: 31 additions & 32 deletions
63
...ation/src/main/java/org/opentripplanner/transit/api/request/TripOnServiceDateRequest.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 |
---|---|---|
@@ -1,78 +1,77 @@ | ||
package org.opentripplanner.transit.api.request; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
import org.opentripplanner.transit.api.model.CriteriaCollection; | ||
import org.opentripplanner.transit.model.framework.FeedScopedId; | ||
import org.opentripplanner.transit.model.timetable.TripAlteration; | ||
import org.opentripplanner.transit.model.timetable.TripOnServiceDate; | ||
import org.opentripplanner.utils.collection.ListUtils; | ||
|
||
/** | ||
* A request for trips on a specific service date. | ||
* | ||
* </p> | ||
* This request is used to retrieve {@link TripOnServiceDate}s that match the provided criteria. | ||
* At least one operatingDay must be provided. | ||
*/ | ||
public class TripOnServiceDateRequest { | ||
|
||
private final List<LocalDate> serviceDates; | ||
private final List<FeedScopedId> agencies; | ||
private final List<FeedScopedId> routes; | ||
private final List<FeedScopedId> serviceJourneys; | ||
private final List<FeedScopedId> replacementFor; | ||
private final List<String> netexInternalPlanningCodes; | ||
private final List<TripAlteration> alterations; | ||
private final CriteriaCollection<LocalDate> serviceDates; | ||
private final CriteriaCollection<FeedScopedId> agencies; | ||
private final CriteriaCollection<FeedScopedId> routes; | ||
private final CriteriaCollection<FeedScopedId> serviceJourneys; | ||
private final CriteriaCollection<FeedScopedId> replacementFor; | ||
private final CriteriaCollection<String> netexInternalPlanningCodes; | ||
private final CriteriaCollection<TripAlteration> alterations; | ||
|
||
protected TripOnServiceDateRequest( | ||
List<LocalDate> serviceDates, | ||
List<FeedScopedId> agencies, | ||
List<FeedScopedId> routes, | ||
List<FeedScopedId> serviceJourneys, | ||
List<FeedScopedId> replacementFor, | ||
List<String> netexInternalPlanningCodes, | ||
List<TripAlteration> alterations | ||
CriteriaCollection<LocalDate> serviceDates, | ||
CriteriaCollection<FeedScopedId> agencies, | ||
CriteriaCollection<FeedScopedId> routes, | ||
CriteriaCollection<FeedScopedId> serviceJourneys, | ||
CriteriaCollection<FeedScopedId> replacementFor, | ||
CriteriaCollection<String> netexInternalPlanningCodes, | ||
CriteriaCollection<TripAlteration> alterations | ||
) { | ||
if (serviceDates == null || serviceDates.isEmpty()) { | ||
if (serviceDates.values() == null || serviceDates.values().isEmpty()) { | ||
throw new IllegalArgumentException("operatingDays must have at least one date"); | ||
} | ||
this.serviceDates = ListUtils.nullSafeImmutableList(serviceDates); | ||
this.agencies = ListUtils.nullSafeImmutableList(agencies); | ||
this.routes = ListUtils.nullSafeImmutableList(routes); | ||
this.serviceJourneys = ListUtils.nullSafeImmutableList(serviceJourneys); | ||
this.replacementFor = ListUtils.nullSafeImmutableList(replacementFor); | ||
this.netexInternalPlanningCodes = ListUtils.nullSafeImmutableList(netexInternalPlanningCodes); | ||
this.alterations = ListUtils.nullSafeImmutableList(alterations); | ||
this.serviceDates = CriteriaCollection.of(serviceDates); | ||
this.agencies = CriteriaCollection.of(agencies); | ||
this.routes = CriteriaCollection.of(routes); | ||
this.serviceJourneys = CriteriaCollection.of(serviceJourneys); | ||
this.replacementFor = CriteriaCollection.of(replacementFor); | ||
this.netexInternalPlanningCodes = CriteriaCollection.of(netexInternalPlanningCodes); | ||
this.alterations = CriteriaCollection.of(alterations); | ||
} | ||
|
||
public static TripOnServiceDateRequestBuilder of() { | ||
return new TripOnServiceDateRequestBuilder(); | ||
} | ||
|
||
public List<FeedScopedId> agencies() { | ||
public CriteriaCollection<FeedScopedId> agencies() { | ||
return agencies; | ||
} | ||
|
||
public List<FeedScopedId> routes() { | ||
public CriteriaCollection<FeedScopedId> routes() { | ||
return routes; | ||
} | ||
|
||
public List<FeedScopedId> serviceJourneys() { | ||
public CriteriaCollection<FeedScopedId> serviceJourneys() { | ||
return serviceJourneys; | ||
} | ||
|
||
public List<FeedScopedId> replacementFor() { | ||
public CriteriaCollection<FeedScopedId> replacementFor() { | ||
return replacementFor; | ||
} | ||
|
||
public List<String> netexInternalPlanningCodes() { | ||
public CriteriaCollection<String> netexInternalPlanningCodes() { | ||
return netexInternalPlanningCodes; | ||
} | ||
|
||
public List<TripAlteration> alterations() { | ||
public CriteriaCollection<TripAlteration> alterations() { | ||
return alterations; | ||
} | ||
|
||
public List<LocalDate> serviceDates() { | ||
public CriteriaCollection<LocalDate> serviceDates() { | ||
return serviceDates; | ||
} | ||
} |
38 changes: 23 additions & 15 deletions
38
...rc/main/java/org/opentripplanner/transit/api/request/TripOnServiceDateRequestBuilder.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
37 changes: 18 additions & 19 deletions
37
application/src/main/java/org/opentripplanner/transit/api/request/TripRequest.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 |
---|---|---|
@@ -1,52 +1,51 @@ | ||
package org.opentripplanner.transit.api.request; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
import org.opentripplanner.transit.api.model.CriteriaCollection; | ||
import org.opentripplanner.transit.model.framework.FeedScopedId; | ||
import org.opentripplanner.transit.model.timetable.Trip; | ||
import org.opentripplanner.utils.collection.ListUtils; | ||
|
||
/** | ||
* A request for {@link Trip}s. | ||
* | ||
* </p> | ||
* This request is used to retrieve {@link Trip}s that match the provided criteria. | ||
*/ | ||
public class TripRequest { | ||
|
||
private final List<FeedScopedId> agencies; | ||
private final List<FeedScopedId> routes; | ||
private final List<String> netexInternalPlanningCodes; | ||
private final List<LocalDate> serviceDates; | ||
private final CriteriaCollection<FeedScopedId> agencies; | ||
private final CriteriaCollection<FeedScopedId> routes; | ||
private final CriteriaCollection<String> netexInternalPlanningCodes; | ||
private final CriteriaCollection<LocalDate> serviceDates; | ||
|
||
protected TripRequest( | ||
List<FeedScopedId> agencies, | ||
List<FeedScopedId> routes, | ||
List<String> netexInternalPlanningCodes, | ||
List<LocalDate> serviceDates | ||
CriteriaCollection<FeedScopedId> agencies, | ||
CriteriaCollection<FeedScopedId> routes, | ||
CriteriaCollection<String> netexInternalPlanningCodes, | ||
CriteriaCollection<LocalDate> serviceDates | ||
) { | ||
this.agencies = ListUtils.nullSafeImmutableList(agencies); | ||
this.routes = ListUtils.nullSafeImmutableList(routes); | ||
this.netexInternalPlanningCodes = ListUtils.nullSafeImmutableList(netexInternalPlanningCodes); | ||
this.serviceDates = ListUtils.nullSafeImmutableList(serviceDates); | ||
this.agencies = CriteriaCollection.of(agencies); | ||
this.routes = CriteriaCollection.of(routes); | ||
this.netexInternalPlanningCodes = CriteriaCollection.of(netexInternalPlanningCodes); | ||
this.serviceDates = CriteriaCollection.of(serviceDates); | ||
} | ||
|
||
public static TripRequestBuilder of() { | ||
return new TripRequestBuilder(); | ||
} | ||
|
||
public List<FeedScopedId> agencies() { | ||
public CriteriaCollection<FeedScopedId> agencies() { | ||
return agencies; | ||
} | ||
|
||
public List<FeedScopedId> routes() { | ||
public CriteriaCollection<FeedScopedId> routes() { | ||
return routes; | ||
} | ||
|
||
public List<String> netexInternalPlanningCodes() { | ||
public CriteriaCollection<String> netexInternalPlanningCodes() { | ||
return netexInternalPlanningCodes; | ||
} | ||
|
||
public List<LocalDate> serviceDates() { | ||
public CriteriaCollection<LocalDate> serviceDates() { | ||
return serviceDates; | ||
} | ||
} |
Oops, something went wrong.