Skip to content

Commit

Permalink
Use CollectionsView in DefaultTransitService
Browse files Browse the repository at this point in the history
  • Loading branch information
vpaturet committed Aug 21, 2024
1 parent 9baf38b commit f34b32d
Showing 1 changed file with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.locationtech.jts.geom.Envelope;
import org.opentripplanner.ext.flex.FlexIndex;
import org.opentripplanner.framework.application.OTPRequestTimeoutException;
import org.opentripplanner.framework.collection.CollectionsView;
import org.opentripplanner.model.FeedInfo;
import org.opentripplanner.model.PathTransfer;
import org.opentripplanner.model.StopTimesInPattern;
Expand Down Expand Up @@ -298,23 +299,27 @@ public Trip getScheduledTripForId(FeedScopedId id) {
@Override
public Collection<Trip> getAllTrips() {
OTPRequestTimeoutException.checkForTimeout();
Collection<Trip> trips = new HashSet<>(transitModelIndex.getTripForId().values());
TimetableSnapshot currentSnapshot = lazyGetTimeTableSnapShot();
if (currentSnapshot != null) {
trips.addAll(currentSnapshot.getAllRealTimeAddedTrips());
return new CollectionsView<>(
transitModelIndex.getTripForId().values(),
currentSnapshot.getAllRealTimeAddedTrips()
);
}
return trips;
return Collections.unmodifiableCollection(transitModelIndex.getTripForId().values());
}

@Override
public Collection<Route> getAllRoutes() {
OTPRequestTimeoutException.checkForTimeout();
Collection<Route> routes = new HashSet<>(transitModelIndex.getAllRoutes());
TimetableSnapshot currentSnapshot = lazyGetTimeTableSnapShot();
if (currentSnapshot != null) {
routes.addAll(currentSnapshot.getAllRealTimeAddedRoutes());
return new CollectionsView<>(
transitModelIndex.getAllRoutes(),
currentSnapshot.getAllRealTimeAddedRoutes()
);
}
return routes;
return Collections.unmodifiableCollection(transitModelIndex.getAllRoutes());
}

@Override
Expand Down Expand Up @@ -558,14 +563,16 @@ public TripOnServiceDate getTripOnServiceDateById(FeedScopedId datedServiceJourn

@Override
public Collection<TripOnServiceDate> getAllTripOnServiceDates() {
Collection<TripOnServiceDate> tripOnServiceDates = new HashSet<>(
transitModelIndex.getTripOnServiceDateForTripAndDay().values()
);
TimetableSnapshot currentSnapshot = lazyGetTimeTableSnapShot();
if (currentSnapshot != null) {
tripOnServiceDates.addAll(currentSnapshot.getAllRealTimeAddedTripOnServiceDate());
return new CollectionsView<>(
transitModelIndex.getTripOnServiceDateForTripAndDay().values(),
currentSnapshot.getAllRealTimeAddedTripOnServiceDate()
);
}
return tripOnServiceDates;
return Collections.unmodifiableCollection(
transitModelIndex.getTripOnServiceDateForTripAndDay().values()
);
}

@Override
Expand Down

0 comments on commit f34b32d

Please sign in to comment.