From 92fb66252dde825f88a1faead76f6d0bec2bb8b0 Mon Sep 17 00:00:00 2001 From: Henrik Abrahamsson Date: Thu, 10 Oct 2024 12:46:05 +0200 Subject: [PATCH 1/5] Refactor: small cleanup of TransitModelIndex --- .../opentripplanner/netex/NetexModule.java | 2 +- .../service/DefaultTransitService.java | 23 +++++++------------ .../transit/service/TransitModel.java | 8 +++++-- .../transit/service/TransitModelIndex.java | 14 ++++------- .../ScheduledTransitLegReferenceTest.java | 1 - .../trip/RealtimeTestEnvironmentBuilder.java | 2 +- 6 files changed, 20 insertions(+), 30 deletions(-) diff --git a/src/main/java/org/opentripplanner/netex/NetexModule.java b/src/main/java/org/opentripplanner/netex/NetexModule.java index 2bf3403395c..1d946b33ad5 100644 --- a/src/main/java/org/opentripplanner/netex/NetexModule.java +++ b/src/main/java/org/opentripplanner/netex/NetexModule.java @@ -70,7 +70,7 @@ public void buildGraph() { ); transitBuilder.limitServiceDays(transitPeriodLimit); for (var tripOnServiceDate : transitBuilder.getTripOnServiceDates().values()) { - transitModel.addTripOnServiceDate(tripOnServiceDate.getId(), tripOnServiceDate); + transitModel.addTripOnServiceDate(tripOnServiceDate); } calendarServiceData.add(transitBuilder.buildCalendarServiceData()); diff --git a/src/main/java/org/opentripplanner/transit/service/DefaultTransitService.java b/src/main/java/org/opentripplanner/transit/service/DefaultTransitService.java index 2777feb148f..a6751c7582e 100644 --- a/src/main/java/org/opentripplanner/transit/service/DefaultTransitService.java +++ b/src/main/java/org/opentripplanner/transit/service/DefaultTransitService.java @@ -350,7 +350,7 @@ public TripPattern getPatternForTrip(Trip trip, LocalDate serviceDate) { public Collection getPatternsForRoute(Route route) { OTPRequestTimeoutException.checkForTimeout(); Collection tripPatterns = new HashSet<>( - transitModelIndex.getPatternsForRoute().get(route) + transitModelIndex.getPatternsForRoute(route) ); TimetableSnapshot currentSnapshot = lazyGetTimeTableSnapShot(); if (currentSnapshot != null) { @@ -551,17 +551,17 @@ private TimetableSnapshot lazyGetTimeTableSnapShot() { } @Override - public TripOnServiceDate getTripOnServiceDateById(FeedScopedId datedServiceJourneyId) { + public TripOnServiceDate getTripOnServiceDateById(FeedScopedId tripOnServiceDateId) { TimetableSnapshot currentSnapshot = lazyGetTimeTableSnapShot(); if (currentSnapshot != null) { TripOnServiceDate tripOnServiceDate = currentSnapshot.getRealTimeAddedTripOnServiceDateById( - datedServiceJourneyId + tripOnServiceDateId ); if (tripOnServiceDate != null) { return tripOnServiceDate; } } - return transitModelIndex.getTripOnServiceDateById().get(datedServiceJourneyId); + return transitModel.getTripOnServiceDateById(tripOnServiceDateId); } @Override @@ -569,13 +569,11 @@ public Collection getAllTripOnServiceDates() { TimetableSnapshot currentSnapshot = lazyGetTimeTableSnapShot(); if (currentSnapshot != null) { return new CollectionsView<>( - transitModelIndex.getTripOnServiceDateForTripAndDay().values(), + transitModel.getAllTripOnServiceDates(), currentSnapshot.listRealTimeAddedTripOnServiceDate() ); } - return Collections.unmodifiableCollection( - transitModelIndex.getTripOnServiceDateForTripAndDay().values() - ); + return Collections.unmodifiableCollection(transitModel.getAllTripOnServiceDates()); } @Override @@ -591,7 +589,7 @@ public TripOnServiceDate getTripOnServiceDateForTripAndDay( return tripOnServiceDate; } } - return transitModelIndex.getTripOnServiceDateForTripAndDay().get(tripIdAndServiceDate); + return transitModelIndex.getTripOnServiceDateForTripAndDay(tripIdAndServiceDate); } /** @@ -603,12 +601,7 @@ public TripOnServiceDate getTripOnServiceDateForTripAndDay( @Override public List getTripOnServiceDates(TripOnServiceDateRequest request) { Matcher matcher = TripOnServiceDateMatcherFactory.of(request); - return transitModelIndex - .getTripOnServiceDateForTripAndDay() - .values() - .stream() - .filter(matcher::match) - .collect(Collectors.toList()); + return getAllTripOnServiceDates().stream().filter(matcher::match).toList(); } /** diff --git a/src/main/java/org/opentripplanner/transit/service/TransitModel.java b/src/main/java/org/opentripplanner/transit/service/TransitModel.java index 87380b66b1b..3aae2f851b0 100644 --- a/src/main/java/org/opentripplanner/transit/service/TransitModel.java +++ b/src/main/java/org/opentripplanner/transit/service/TransitModel.java @@ -406,9 +406,9 @@ public TripPattern getTripPatternForId(FeedScopedId id) { return tripPatternForId.get(id); } - public void addTripOnServiceDate(FeedScopedId id, TripOnServiceDate tripOnServiceDate) { + public void addTripOnServiceDate(TripOnServiceDate tripOnServiceDate) { invalidateIndex(); - tripOnServiceDates.put(id, tripOnServiceDate); + tripOnServiceDates.put(tripOnServiceDate.getId(), tripOnServiceDate); } /** @@ -442,6 +442,10 @@ public Collection getAllTripPatterns() { return tripPatternForId.values(); } + public TripOnServiceDate getTripOnServiceDateById(FeedScopedId tripOnServiceDateId) { + return tripOnServiceDates.get(tripOnServiceDateId); + } + public Collection getAllTripOnServiceDates() { return tripOnServiceDates.values(); } diff --git a/src/main/java/org/opentripplanner/transit/service/TransitModelIndex.java b/src/main/java/org/opentripplanner/transit/service/TransitModelIndex.java index 36ab937416c..0b2835f98f8 100644 --- a/src/main/java/org/opentripplanner/transit/service/TransitModelIndex.java +++ b/src/main/java/org/opentripplanner/transit/service/TransitModelIndex.java @@ -50,7 +50,6 @@ class TransitModelIndex { private final Multimap patternsForStopId = ArrayListMultimap.create(); private final Map serviceCodesRunningForDate = new HashMap<>(); - private final Map tripOnServiceDateById = new HashMap<>(); private final Map tripOnServiceDateForTripAndDay = new HashMap<>(); private final Multimap routesForGroupOfRoutes = ArrayListMultimap.create(); @@ -92,7 +91,6 @@ class TransitModelIndex { } for (TripOnServiceDate tripOnServiceDate : transitModel.getAllTripOnServiceDates()) { - tripOnServiceDateById.put(tripOnServiceDate.getId(), tripOnServiceDate); tripOnServiceDateForTripAndDay.put( new TripIdAndServiceDate( tripOnServiceDate.getTrip().getId(), @@ -164,12 +162,8 @@ Map getTripForId() { return tripForId; } - Map getTripOnServiceDateById() { - return tripOnServiceDateById; - } - - Map getTripOnServiceDateForTripAndDay() { - return tripOnServiceDateForTripAndDay; + TripOnServiceDate getTripOnServiceDateForTripAndDay(TripIdAndServiceDate tripIdAndServiceDate) { + return tripOnServiceDateForTripAndDay.get(tripIdAndServiceDate); } Collection getAllRoutes() { @@ -180,8 +174,8 @@ Map getPatternForTrip() { return patternForTrip; } - Multimap getPatternsForRoute() { - return patternsForRoute; + Collection getPatternsForRoute(Route route) { + return patternsForRoute.get(route); } Map getServiceCodesRunningForDate() { diff --git a/src/test/java/org/opentripplanner/model/plan/legreference/ScheduledTransitLegReferenceTest.java b/src/test/java/org/opentripplanner/model/plan/legreference/ScheduledTransitLegReferenceTest.java index 315b12dfefc..277f65cfcae 100644 --- a/src/test/java/org/opentripplanner/model/plan/legreference/ScheduledTransitLegReferenceTest.java +++ b/src/test/java/org/opentripplanner/model/plan/legreference/ScheduledTransitLegReferenceTest.java @@ -87,7 +87,6 @@ static void buildTransitService() { transitModel.updateCalendarServiceData(true, calendarServiceData, DataImportIssueStore.NOOP); transitModel.addTripOnServiceDate( - TRIP_ON_SERVICE_DATE_ID, TripOnServiceDate .of(TRIP_ON_SERVICE_DATE_ID) .withTrip(trip) diff --git a/src/test/java/org/opentripplanner/updater/trip/RealtimeTestEnvironmentBuilder.java b/src/test/java/org/opentripplanner/updater/trip/RealtimeTestEnvironmentBuilder.java index 88f4bf41012..aab71628b03 100644 --- a/src/test/java/org/opentripplanner/updater/trip/RealtimeTestEnvironmentBuilder.java +++ b/src/test/java/org/opentripplanner/updater/trip/RealtimeTestEnvironmentBuilder.java @@ -65,7 +65,7 @@ private Trip createTrip(TripInput tripInput) { .withServiceDate(SERVICE_DATE) .build(); - transitModel.addTripOnServiceDate(tripOnServiceDate.getId(), tripOnServiceDate); + transitModel.addTripOnServiceDate(tripOnServiceDate); if (tripInput.route().getOperator() != null) { transitModel.getOperators().add(tripInput.route().getOperator()); From 0d2c511b7fc6e411168003eef0441cd34dbb954b Mon Sep 17 00:00:00 2001 From: Henrik Abrahamsson Date: Thu, 10 Oct 2024 14:56:23 +0200 Subject: [PATCH 2/5] Refactor: Better encapsulation in transitModelIndex --- .../service/DefaultTransitService.java | 12 +++--- .../transit/service/TransitModelIndex.java | 38 +++++++++---------- .../transit/service/TransitModelTest.java | 4 +- 3 files changed, 26 insertions(+), 28 deletions(-) diff --git a/src/main/java/org/opentripplanner/transit/service/DefaultTransitService.java b/src/main/java/org/opentripplanner/transit/service/DefaultTransitService.java index a6751c7582e..c762db53c3a 100644 --- a/src/main/java/org/opentripplanner/transit/service/DefaultTransitService.java +++ b/src/main/java/org/opentripplanner/transit/service/DefaultTransitService.java @@ -234,12 +234,12 @@ public Collection getTripsForStop(StopLocation stop) { @Override public Collection getAllOperators() { OTPRequestTimeoutException.checkForTimeout(); - return this.transitModelIndex.getAllOperators(); + return this.transitModel.getOperators(); } @Override public Operator getOperatorForId(FeedScopedId id) { - return this.transitModelIndex.getOperatorForId().get(id); + return this.transitModelIndex.getOperatorForId(id); } @Override @@ -334,7 +334,7 @@ public TripPattern getPatternForTrip(Trip trip) { return realtimeAddedTripPattern; } } - return this.transitModelIndex.getPatternForTrip().get(trip); + return this.transitModelIndex.getPatternForTrip(trip); } @Override @@ -491,18 +491,18 @@ public Collection getPatternsForStop( @Override public Collection getGroupsOfRoutes() { OTPRequestTimeoutException.checkForTimeout(); - return transitModelIndex.getRoutesForGroupOfRoutes().keySet(); + return transitModelIndex.getAllGroupOfRoutes(); } @Override public Collection getRoutesForGroupOfRoutes(GroupOfRoutes groupOfRoutes) { OTPRequestTimeoutException.checkForTimeout(); - return transitModelIndex.getRoutesForGroupOfRoutes().get(groupOfRoutes); + return transitModelIndex.getRoutesForGroupOfRoutes(groupOfRoutes); } @Override public GroupOfRoutes getGroupOfRoutesForId(FeedScopedId id) { - return transitModelIndex.getGroupOfRoutesForId().get(id); + return transitModelIndex.getGroupOfRoutesForId(id); } /** diff --git a/src/main/java/org/opentripplanner/transit/service/TransitModelIndex.java b/src/main/java/org/opentripplanner/transit/service/TransitModelIndex.java index 0b2835f98f8..feff5136886 100644 --- a/src/main/java/org/opentripplanner/transit/service/TransitModelIndex.java +++ b/src/main/java/org/opentripplanner/transit/service/TransitModelIndex.java @@ -7,6 +7,7 @@ import gnu.trove.set.hash.TIntHashSet; import java.time.LocalDate; import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Map; @@ -47,7 +48,7 @@ class TransitModelIndex { private final Map patternForTrip = new HashMap<>(); private final Multimap patternsForRoute = ArrayListMultimap.create(); - private final Multimap patternsForStopId = ArrayListMultimap.create(); + private final Multimap patternsForStop = ArrayListMultimap.create(); private final Map serviceCodesRunningForDate = new HashMap<>(); private final Map tripOnServiceDateForTripAndDay = new HashMap<>(); @@ -77,7 +78,7 @@ class TransitModelIndex { tripForId.put(trip.getId(), trip); }); for (StopLocation stop : pattern.getStops()) { - patternsForStopId.put(stop, pattern); + patternsForStop.put(stop, pattern); } } for (Route route : patternsForRoute.asMap().keySet()) { @@ -130,32 +131,25 @@ void addRoutes(Route route) { /** Dynamically generate the set of Routes passing though a Stop on demand. */ Set getRoutesForStop(StopLocation stop) { Set routes = new HashSet<>(); - for (TripPattern p : getPatternsForStop(stop)) { + for (TripPattern p : patternsForStop.get(stop)) { routes.add(p.getRoute()); } return routes; } Collection getPatternsForStop(StopLocation stop) { - return patternsForStopId.get(stop); + return Collections.unmodifiableCollection(patternsForStop.get(stop)); } Collection getTripsForStop(StopLocation stop) { - return getPatternsForStop(stop) + return patternsForStop.get(stop) .stream() .flatMap(TripPattern::scheduledTripsAsStream) .collect(Collectors.toList()); } - /** - * Get a list of all operators spanning across all feeds. - */ - Collection getAllOperators() { - return getOperatorForId().values(); - } - - Map getOperatorForId() { - return operatorForId; + Operator getOperatorForId(FeedScopedId operatorId) { + return operatorForId.get(operatorId); } Map getTripForId() { @@ -170,8 +164,8 @@ Collection getAllRoutes() { return routeForId.values(); } - Map getPatternForTrip() { - return patternForTrip; + TripPattern getPatternForTrip(Trip trip) { + return patternForTrip.get(trip); } Collection getPatternsForRoute(Route route) { @@ -223,11 +217,15 @@ private void initalizeServiceCodesForDate(TransitModel transitModel) { } } - Multimap getRoutesForGroupOfRoutes() { - return routesForGroupOfRoutes; + Collection getAllGroupOfRoutes() { + return Collections.unmodifiableCollection(groupOfRoutesForId.values()); + } + + Collection getRoutesForGroupOfRoutes(GroupOfRoutes groupOfRoutes) { + return Collections.unmodifiableCollection(routesForGroupOfRoutes.get(groupOfRoutes)); } - Map getGroupOfRoutesForId() { - return groupOfRoutesForId; + GroupOfRoutes getGroupOfRoutesForId(FeedScopedId id) { + return groupOfRoutesForId.get(id); } } diff --git a/src/test/java/org/opentripplanner/transit/service/TransitModelTest.java b/src/test/java/org/opentripplanner/transit/service/TransitModelTest.java index 95c20245f9a..bce830f2058 100644 --- a/src/test/java/org/opentripplanner/transit/service/TransitModelTest.java +++ b/src/test/java/org/opentripplanner/transit/service/TransitModelTest.java @@ -43,7 +43,7 @@ void validateTimeZones() { // Then trip times should be same as in input data TransitModelIndex transitModelIndex = transitModel.getTransitModelIndex(); Trip trip = transitModelIndex.getTripForId().get(SAMPLE_TRIP_ID); - Timetable timetable = transitModelIndex.getPatternForTrip().get(trip).getScheduledTimetable(); + Timetable timetable = transitModelIndex.getPatternForTrip(trip).getScheduledTimetable(); assertEquals(20 * 60, timetable.getTripTimes(trip).getDepartureTime(0)); // Should throw on second bundle, with different agency time zone @@ -102,7 +102,7 @@ void validateTimeZonesWithExplicitTimeZone() { // Then trip times should be on hour less than in input data Trip trip = transitModelIndex.getTripForId().get(SAMPLE_TRIP_ID); - Timetable timetable = transitModelIndex.getPatternForTrip().get(trip).getScheduledTimetable(); + Timetable timetable = transitModelIndex.getPatternForTrip(trip).getScheduledTimetable(); assertEquals(20 * 60 - 60 * 60, timetable.getTripTimes(trip).getDepartureTime(0)); } } From 2b405702badeb2a54d6c964c372845194052a623 Mon Sep 17 00:00:00 2001 From: Henrik Abrahamsson Date: Thu, 10 Oct 2024 15:14:47 +0200 Subject: [PATCH 3/5] Refactor: Hide the tripForId map in TransitModelIndex --- .../transit/service/DefaultTransitService.java | 6 +++--- .../transit/service/TransitModelIndex.java | 11 ++++++++--- .../transit/service/TransitModelTest.java | 4 ++-- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/opentripplanner/transit/service/DefaultTransitService.java b/src/main/java/org/opentripplanner/transit/service/DefaultTransitService.java index c762db53c3a..4df4f7beecc 100644 --- a/src/main/java/org/opentripplanner/transit/service/DefaultTransitService.java +++ b/src/main/java/org/opentripplanner/transit/service/DefaultTransitService.java @@ -296,7 +296,7 @@ public Trip getTripForId(FeedScopedId id) { @Nullable @Override public Trip getScheduledTripForId(FeedScopedId id) { - return this.transitModelIndex.getTripForId().get(id); + return this.transitModelIndex.getTripForId(id); } @Override @@ -305,11 +305,11 @@ public Collection getAllTrips() { TimetableSnapshot currentSnapshot = lazyGetTimeTableSnapShot(); if (currentSnapshot != null) { return new CollectionsView<>( - transitModelIndex.getTripForId().values(), + transitModelIndex.getAllTrips(), currentSnapshot.listRealTimeAddedTrips() ); } - return Collections.unmodifiableCollection(transitModelIndex.getTripForId().values()); + return Collections.unmodifiableCollection(transitModelIndex.getAllTrips()); } @Override diff --git a/src/main/java/org/opentripplanner/transit/service/TransitModelIndex.java b/src/main/java/org/opentripplanner/transit/service/TransitModelIndex.java index feff5136886..9fa85ff49c2 100644 --- a/src/main/java/org/opentripplanner/transit/service/TransitModelIndex.java +++ b/src/main/java/org/opentripplanner/transit/service/TransitModelIndex.java @@ -142,7 +142,8 @@ Collection getPatternsForStop(StopLocation stop) { } Collection getTripsForStop(StopLocation stop) { - return patternsForStop.get(stop) + return patternsForStop + .get(stop) .stream() .flatMap(TripPattern::scheduledTripsAsStream) .collect(Collectors.toList()); @@ -152,8 +153,12 @@ Operator getOperatorForId(FeedScopedId operatorId) { return operatorForId.get(operatorId); } - Map getTripForId() { - return tripForId; + Collection getAllTrips() { + return Collections.unmodifiableCollection(tripForId.values()); + } + + Trip getTripForId(FeedScopedId tripId) { + return tripForId.get(tripId); } TripOnServiceDate getTripOnServiceDateForTripAndDay(TripIdAndServiceDate tripIdAndServiceDate) { diff --git a/src/test/java/org/opentripplanner/transit/service/TransitModelTest.java b/src/test/java/org/opentripplanner/transit/service/TransitModelTest.java index bce830f2058..213d1f7b514 100644 --- a/src/test/java/org/opentripplanner/transit/service/TransitModelTest.java +++ b/src/test/java/org/opentripplanner/transit/service/TransitModelTest.java @@ -42,7 +42,7 @@ void validateTimeZones() { // Then trip times should be same as in input data TransitModelIndex transitModelIndex = transitModel.getTransitModelIndex(); - Trip trip = transitModelIndex.getTripForId().get(SAMPLE_TRIP_ID); + Trip trip = transitModelIndex.getTripForId(SAMPLE_TRIP_ID); Timetable timetable = transitModelIndex.getPatternForTrip(trip).getScheduledTimetable(); assertEquals(20 * 60, timetable.getTripTimes(trip).getDepartureTime(0)); @@ -101,7 +101,7 @@ void validateTimeZonesWithExplicitTimeZone() { assertEquals("America/Chicago", transitModel.getTimeZone().getId()); // Then trip times should be on hour less than in input data - Trip trip = transitModelIndex.getTripForId().get(SAMPLE_TRIP_ID); + Trip trip = transitModelIndex.getTripForId(SAMPLE_TRIP_ID); Timetable timetable = transitModelIndex.getPatternForTrip(trip).getScheduledTimetable(); assertEquals(20 * 60 - 60 * 60, timetable.getTripTimes(trip).getDepartureTime(0)); } From f24544215c5c57e35b6d687969e683d41c138168 Mon Sep 17 00:00:00 2001 From: Henrik Abrahamsson Date: Thu, 10 Oct 2024 16:31:46 +0200 Subject: [PATCH 4/5] Make some collections in TransitModelIndex unmodifiable --- .../transit/service/DefaultTransitService.java | 2 +- .../opentripplanner/transit/service/TransitModelIndex.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/opentripplanner/transit/service/DefaultTransitService.java b/src/main/java/org/opentripplanner/transit/service/DefaultTransitService.java index 4df4f7beecc..7450d6ac1f5 100644 --- a/src/main/java/org/opentripplanner/transit/service/DefaultTransitService.java +++ b/src/main/java/org/opentripplanner/transit/service/DefaultTransitService.java @@ -322,7 +322,7 @@ public Collection getAllRoutes() { currentSnapshot.listRealTimeAddedRoutes() ); } - return Collections.unmodifiableCollection(transitModelIndex.getAllRoutes()); + return transitModelIndex.getAllRoutes(); } @Override diff --git a/src/main/java/org/opentripplanner/transit/service/TransitModelIndex.java b/src/main/java/org/opentripplanner/transit/service/TransitModelIndex.java index 9fa85ff49c2..34c84b628d3 100644 --- a/src/main/java/org/opentripplanner/transit/service/TransitModelIndex.java +++ b/src/main/java/org/opentripplanner/transit/service/TransitModelIndex.java @@ -166,7 +166,7 @@ TripOnServiceDate getTripOnServiceDateForTripAndDay(TripIdAndServiceDate tripIdA } Collection getAllRoutes() { - return routeForId.values(); + return Collections.unmodifiableCollection(routeForId.values()); } TripPattern getPatternForTrip(Trip trip) { @@ -174,7 +174,7 @@ TripPattern getPatternForTrip(Trip trip) { } Collection getPatternsForRoute(Route route) { - return patternsForRoute.get(route); + return Collections.unmodifiableCollection(patternsForRoute.get(route)); } Map getServiceCodesRunningForDate() { From 629562b9e7f97df3567a73ec51a3ba9d4b13a261 Mon Sep 17 00:00:00 2001 From: Henrik Abrahamsson Date: Fri, 11 Oct 2024 14:41:06 +0200 Subject: [PATCH 5/5] Address review comment --- .../transit/service/DefaultTransitService.java | 4 ++-- .../org/opentripplanner/transit/service/TransitModel.java | 5 +++-- .../opentripplanner/transit/service/TransitModelIndex.java | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/opentripplanner/transit/service/DefaultTransitService.java b/src/main/java/org/opentripplanner/transit/service/DefaultTransitService.java index 7450d6ac1f5..ad5c6586fe0 100644 --- a/src/main/java/org/opentripplanner/transit/service/DefaultTransitService.java +++ b/src/main/java/org/opentripplanner/transit/service/DefaultTransitService.java @@ -569,11 +569,11 @@ public Collection getAllTripOnServiceDates() { TimetableSnapshot currentSnapshot = lazyGetTimeTableSnapShot(); if (currentSnapshot != null) { return new CollectionsView<>( - transitModel.getAllTripOnServiceDates(), + transitModel.getAllTripsOnServiceDates(), currentSnapshot.listRealTimeAddedTripOnServiceDate() ); } - return Collections.unmodifiableCollection(transitModel.getAllTripOnServiceDates()); + return transitModel.getAllTripsOnServiceDates(); } @Override diff --git a/src/main/java/org/opentripplanner/transit/service/TransitModel.java b/src/main/java/org/opentripplanner/transit/service/TransitModel.java index 3aae2f851b0..c22c69b6b0d 100644 --- a/src/main/java/org/opentripplanner/transit/service/TransitModel.java +++ b/src/main/java/org/opentripplanner/transit/service/TransitModel.java @@ -13,6 +13,7 @@ import java.time.ZonedDateTime; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Map; @@ -446,8 +447,8 @@ public TripOnServiceDate getTripOnServiceDateById(FeedScopedId tripOnServiceDate return tripOnServiceDates.get(tripOnServiceDateId); } - public Collection getAllTripOnServiceDates() { - return tripOnServiceDates.values(); + public Collection getAllTripsOnServiceDates() { + return Collections.unmodifiableCollection(tripOnServiceDates.values()); } /** diff --git a/src/main/java/org/opentripplanner/transit/service/TransitModelIndex.java b/src/main/java/org/opentripplanner/transit/service/TransitModelIndex.java index 34c84b628d3..7f44854eb9a 100644 --- a/src/main/java/org/opentripplanner/transit/service/TransitModelIndex.java +++ b/src/main/java/org/opentripplanner/transit/service/TransitModelIndex.java @@ -91,7 +91,7 @@ class TransitModelIndex { groupOfRoutesForId.put(groupOfRoutes.getId(), groupOfRoutes); } - for (TripOnServiceDate tripOnServiceDate : transitModel.getAllTripOnServiceDates()) { + for (TripOnServiceDate tripOnServiceDate : transitModel.getAllTripsOnServiceDates()) { tripOnServiceDateForTripAndDay.put( new TripIdAndServiceDate( tripOnServiceDate.getTrip().getId(),