Skip to content

Commit c2cc3cb

Browse files
committed
refactoring, docs, remove unused
1 parent 7886fe2 commit c2cc3cb

5 files changed

Lines changed: 28 additions & 36 deletions

File tree

application/src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/DigitransitRealtimeStopPropertyMapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ protected Collection<KeyValue> map(RegularStop stop) {
3939
.findStopTimesInPattern(stop, serviceDate, ArrivalDeparture.BOTH, true)
4040
.stream()
4141
.anyMatch(stopTime -> stopTime.times.size() > 0);
42-
var inService = transitService.isStopInService(stop);
42+
var inService = transitService.hasScheduledServicesAfter(LocalDate.now(), stop);
4343

4444
Collection<KeyValue> sharedKeyValues = getBaseKeyValues(stop, i18NStringMapper, transitService);
4545
return ListUtils.combine(

application/src/main/java/org/opentripplanner/transit/service/DefaultTransitService.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -815,17 +815,7 @@ public int compare(TripOnServiceDate t1, TripOnServiceDate t2) {
815815
}
816816

817817
@Override
818-
public boolean isStopInService(StopLocation stop) {
819-
return timetableRepositoryIndex.isStopInService(stop);
820-
}
821-
822-
@Override
823-
public boolean isStationInService(Station station) {
824-
for (StopLocation stop : station.getChildStops()) {
825-
if (isStopInService(stop)) {
826-
return true;
827-
}
828-
}
829-
return false;
818+
public boolean hasScheduledServicesAfter(LocalDate date, StopLocation stop) {
819+
return timetableRepositoryIndex.hasScheduledServicesAfter(date, stop);
830820
}
831821
}

application/src/main/java/org/opentripplanner/transit/service/TimetableRepositoryIndex.java

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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() {

application/src/main/java/org/opentripplanner/transit/service/TransitService.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -420,12 +420,8 @@ Collection<RegularStop> findRegularStopsByBoundingBox(
420420
Collection<StopLocation> findStopLocations(FindStopLocationsRequest request);
421421

422422
/**
423-
* Returns boolean indicating if there are trips scheduled for a stop in the future.
423+
* Returns boolean indicating if there are scheduled services on or after the given date.
424+
* This does not include real-time updates, so it only checks the scheduled service dates.
424425
*/
425-
boolean isStopInService(StopLocation stop);
426-
427-
/**
428-
* Returns boolean indicating if there are trips scheduled for any child stop of the station in the future.
429-
*/
430-
boolean isStationInService(Station station);
426+
boolean hasScheduledServicesAfter(LocalDate date, StopLocation stop);
431427
}

application/src/test/java/org/opentripplanner/transit/service/DefaultTransitServiceTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,8 @@ void getRealtimeTripTimesForAddedTripOnNoServiceDay() {
310310

311311
@Test
312312
void hasTripsForStop() {
313-
assertTrue(service.isStopInService(STOP_ONE));
314-
assertFalse(service.isStopInService(STOP_A));
315-
assertFalse(service.isStopInService(STOP_C));
313+
assertTrue(service.hasScheduledServicesAfter(LocalDate.now(), STOP_ONE));
314+
assertFalse(service.hasScheduledServicesAfter(LocalDate.now(), STOP_A));
315+
assertFalse(service.hasScheduledServicesAfter(LocalDate.now(), STOP_C));
316316
}
317317
}

0 commit comments

Comments
 (0)