@@ -50,8 +50,7 @@ class TimetableRepositoryIndex {
5050 private final Multimap <Route , TripPattern > patternsForRoute = ArrayListMultimap .create ();
5151 private final Multimap <StopLocation , TripPattern > patternsForStop = ArrayListMultimap .create ();
5252
53- private final Map <StopLocation , LocalDate > endOfServiceDateForStop = new HashMap <>();
54- private final Map <FeedScopedId , LocalDate > endOfServiceDateForService = new HashMap <>();
53+ private Map <StopLocation , LocalDate > endOfServiceDateForStop = new HashMap <>();
5554 private final Map <LocalDate , TIntSet > serviceCodesRunningForDate = new HashMap <>();
5655 private final Map <TripIdAndServiceDate , TripOnServiceDate > tripOnServiceDateForTripAndDay =
5756 new HashMap <>();
@@ -104,8 +103,7 @@ class TimetableRepositoryIndex {
104103 );
105104 }
106105
107- initalizeServiceCodesForDate (timetableRepository );
108- initializeTheEndOfServiceDateForStop ();
106+ initializeServiceData (timetableRepository );
109107
110108 if (OTPFeature .FlexRouting .isOn ()) {
111109 flexIndex = new FlexIndex (timetableRepository );
@@ -154,16 +152,17 @@ Collection<Trip> getTripsForStop(StopLocation stop) {
154152 }
155153
156154 /**
157- * Checks if the last scheduled service date for the stop is today or in the future.
155+ * Checks if the last scheduled service date for the stop is on or after the given date.
156+ * This does not include real-time updates, so it only checks the scheduled service dates.
158157 *
158+ * @param date the date to check against
159159 * @param stop the stop to check
160- * @return true if the stop is in service today or later , false otherwise
160+ * @return true if the stop has scheduled services after the given date , false otherwise
161161 */
162- boolean isStopInService ( StopLocation stop ) {
162+ boolean hasScheduledServicesAfter ( LocalDate date , StopLocation stop ) {
163163 LocalDate endOfServiceDate = endOfServiceDateForStop .get (stop );
164164 return (
165- endOfServiceDate != null &&
166- (endOfServiceDate .isAfter (LocalDate .now ()) || endOfServiceDate .isEqual (LocalDate .now ()))
165+ endOfServiceDate != null && (endOfServiceDate .isAfter (date ) || endOfServiceDate .isEqual (date ))
167166 );
168167 }
169168
@@ -213,7 +212,7 @@ FlexIndex getFlexIndex() {
213212 return flexIndex ;
214213 }
215214
216- private void initalizeServiceCodesForDate (TimetableRepository timetableRepository ) {
215+ private void initializeServiceData (TimetableRepository timetableRepository ) {
217216 CalendarService calendarService = timetableRepository .getCalendarService ();
218217
219218 if (calendarService == null ) {
@@ -232,6 +231,7 @@ private void initalizeServiceCodesForDate(TimetableRepository timetableRepositor
232231 // Reconstruct set of all dates where service is defined, keeping track of which services
233232 // run on which days.
234233 Multimap <LocalDate , FeedScopedId > serviceIdsForServiceDate = HashMultimap .create ();
234+ Map <FeedScopedId , LocalDate > endOfServiceDateForService = new HashMap <>();
235235
236236 for (FeedScopedId serviceId : calendarService .getServiceIds ()) {
237237 Set <LocalDate > serviceDatesForService = calendarService .getServiceDatesForServiceId (
@@ -256,25 +256,31 @@ private void initalizeServiceCodesForDate(TimetableRepository timetableRepositor
256256 }
257257 serviceCodesRunningForDate .put (serviceDate , serviceCodesRunning );
258258 }
259+
260+ initializeTheEndOfServiceDateForStop (endOfServiceDateForService );
259261 }
260262
261- private void initializeTheEndOfServiceDateForStop () {
263+ private void initializeTheEndOfServiceDateForStop (
264+ Map <FeedScopedId , LocalDate > endOfServiceDateForService
265+ ) {
266+ Map <StopLocation , LocalDate > endOfServiceDates = new HashMap <>();
262267 for (StopLocation stop : patternsForStop .keySet ()) {
263268 for (TripPattern pattern : patternsForStop .get (stop )) {
264269 pattern
265270 .scheduledTripsAsStream ()
266271 .forEach (trip -> {
267272 LocalDate tripEndDate = endOfServiceDateForService .get (trip .getServiceId ());
268- LocalDate endOfServiceDate = endOfServiceDateForStop .get (stop );
273+ LocalDate endOfServiceDate = endOfServiceDates .get (stop );
269274 if (
270275 tripEndDate != null &&
271276 (endOfServiceDate == null || tripEndDate .isAfter (endOfServiceDate ))
272277 ) {
273- endOfServiceDateForStop .put (stop , tripEndDate );
278+ endOfServiceDates .put (stop , tripEndDate );
274279 }
275280 });
276281 }
277282 }
283+ endOfServiceDateForStop = Map .copyOf (endOfServiceDates );
278284 }
279285
280286 Collection <GroupOfRoutes > getAllGroupOfRoutes () {
0 commit comments