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.
Merge remote-tracking branch 'entur/more_filters' into otp2_entur_dev…
…elop
- Loading branch information
Showing
19 changed files
with
640 additions
and
186 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
50 changes: 50 additions & 0 deletions
50
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,50 @@ | ||
package org.opentripplanner.transit.api.model; | ||
|
||
import com.beust.jcommander.internal.Nullable; | ||
import java.util.Collection; | ||
import java.util.NoSuchElementException; | ||
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> ofEmptyIsEverything(@Nullable Collection<E> criteria) { | ||
return new CriteriaCollection<>(criteria); | ||
} | ||
|
||
public static <E> CriteriaCollection<E> ofEmptyIsEverything( | ||
@Nullable CriteriaCollection<E> criteria | ||
) { | ||
if (criteria == null) { | ||
return new CriteriaCollection<>(null); | ||
} | ||
return criteria; | ||
} | ||
|
||
public boolean includeEverything() { | ||
return criteria == null || criteria.isEmpty(); | ||
} | ||
|
||
public Collection<E> get() { | ||
if (criteria == null) { | ||
throw new NoSuchElementException( | ||
"No values present, use matchesAll() before calling this method." | ||
); | ||
} | ||
return criteria; | ||
} | ||
} |
77 changes: 39 additions & 38 deletions
77
...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,77 +1,78 @@ | ||
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.utils.collection.ListUtils; | ||
import org.opentripplanner.transit.model.timetable.TripOnServiceDate; | ||
|
||
/* | ||
/** | ||
* A request for trips on a specific service date. | ||
* | ||
* This request is used to retrieve TripsOnServiceDates that match the provided criteria. | ||
* </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> operatingDays; | ||
private final List<FeedScopedId> authorities; | ||
private final List<FeedScopedId> lines; | ||
private final List<FeedScopedId> serviceJourneys; | ||
private final List<FeedScopedId> replacementFor; | ||
private final List<String> privateCodes; | ||
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> operatingDays, | ||
List<FeedScopedId> authorities, | ||
List<FeedScopedId> lines, | ||
List<FeedScopedId> serviceJourneys, | ||
List<FeedScopedId> replacementFor, | ||
List<String> privateCodes, | ||
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 (operatingDays == null || operatingDays.isEmpty()) { | ||
if (serviceDates.get() == null || serviceDates.get().isEmpty()) { | ||
throw new IllegalArgumentException("operatingDays must have at least one date"); | ||
} | ||
this.operatingDays = ListUtils.nullSafeImmutableList(operatingDays); | ||
this.authorities = ListUtils.nullSafeImmutableList(authorities); | ||
this.lines = ListUtils.nullSafeImmutableList(lines); | ||
this.serviceJourneys = ListUtils.nullSafeImmutableList(serviceJourneys); | ||
this.replacementFor = ListUtils.nullSafeImmutableList(replacementFor); | ||
this.privateCodes = ListUtils.nullSafeImmutableList(privateCodes); | ||
this.alterations = ListUtils.nullSafeImmutableList(alterations); | ||
this.serviceDates = CriteriaCollection.ofEmptyIsEverything(serviceDates); | ||
this.agencies = CriteriaCollection.ofEmptyIsEverything(agencies); | ||
this.routes = CriteriaCollection.ofEmptyIsEverything(routes); | ||
this.serviceJourneys = CriteriaCollection.ofEmptyIsEverything(serviceJourneys); | ||
this.replacementFor = CriteriaCollection.ofEmptyIsEverything(replacementFor); | ||
this.netexInternalPlanningCodes = | ||
CriteriaCollection.ofEmptyIsEverything(netexInternalPlanningCodes); | ||
this.alterations = CriteriaCollection.ofEmptyIsEverything(alterations); | ||
} | ||
|
||
public static TripOnServiceDateRequestBuilder of() { | ||
return new TripOnServiceDateRequestBuilder(); | ||
} | ||
|
||
public List<FeedScopedId> authorities() { | ||
return authorities; | ||
public CriteriaCollection<FeedScopedId> agencies() { | ||
return agencies; | ||
} | ||
|
||
public List<FeedScopedId> lines() { | ||
return lines; | ||
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> privateCodes() { | ||
return privateCodes; | ||
public CriteriaCollection<String> netexInternalPlanningCodes() { | ||
return netexInternalPlanningCodes; | ||
} | ||
|
||
public List<TripAlteration> alterations() { | ||
public CriteriaCollection<TripAlteration> alterations() { | ||
return alterations; | ||
} | ||
|
||
public List<LocalDate> operatingDays() { | ||
return operatingDays; | ||
public CriteriaCollection<LocalDate> serviceDates() { | ||
return serviceDates; | ||
} | ||
} |
Oops, something went wrong.