|
1 | 1 | package org.mobilitydata.gtfsvalidator.reportsummary.model; |
2 | 2 |
|
3 | | -import static java.util.Collections.emptySet; |
4 | 3 | import static java.util.stream.Collectors.*; |
5 | 4 |
|
6 | | -import com.google.common.collect.Sets; |
7 | 5 | import java.time.LocalDate; |
8 | 6 | import java.util.*; |
9 | 7 | import org.mobilitydata.gtfsvalidator.table.GtfsCalendar; |
10 | 8 | import org.mobilitydata.gtfsvalidator.table.GtfsCalendarDate; |
11 | 9 | import org.mobilitydata.gtfsvalidator.table.GtfsCalendarDateExceptionType; |
12 | 10 | import org.mobilitydata.gtfsvalidator.table.GtfsTrip; |
| 11 | +import org.mobilitydata.gtfsvalidator.util.FuncUtil; |
13 | 12 |
|
14 | 13 | record ServiceWindow(LocalDate startDate, LocalDate endDate) { |
15 | 14 | static Optional<ServiceWindow> fromCalendars( |
@@ -58,21 +57,19 @@ static Optional<ServiceWindow> fromCalendarsAndCalendarDates( |
58 | 57 |
|
59 | 58 | Set<String> serviceIds = new HashSet<>(trips.stream().map(GtfsTrip::serviceId).toList()); |
60 | 59 |
|
61 | | - // We compute the set of days that are removed across all services in |
62 | | - // order to shift the start and end dates. |
63 | | - Set<LocalDate> removedDays = |
| 60 | + Map<String, Set<LocalDate>> removedDaysByServiceId = |
64 | 61 | calendarDates.stream() |
65 | 62 | .filter( |
66 | 63 | d -> |
67 | | - serviceIds.contains(d.serviceId()) |
68 | | - && d.exceptionType() == GtfsCalendarDateExceptionType.SERVICE_REMOVED) |
| 64 | + d.exceptionType() == GtfsCalendarDateExceptionType.SERVICE_REMOVED |
| 65 | + && serviceIds.contains(d.serviceId())) |
69 | 66 | .collect( |
70 | 67 | groupingBy( |
71 | | - GtfsCalendarDate::serviceId, mapping(d -> d.date().getLocalDate(), toSet()))) |
72 | | - .values() |
73 | | - .stream() |
74 | | - .reduce(Sets::intersection) |
75 | | - .orElse(emptySet()); |
| 68 | + GtfsCalendarDate::serviceId, mapping(d -> d.date().getLocalDate(), toSet()))); |
| 69 | + |
| 70 | + // We compute the set of days that are removed across all services in |
| 71 | + // order to shift the start and end dates. |
| 72 | + Set<LocalDate> removedDays = FuncUtil.intersectAll(removedDaysByServiceId.values()); |
76 | 73 |
|
77 | 74 | LocalDate startDate = serviceWindowFromCalendars.get().startDate(); |
78 | 75 | LocalDate endDate = serviceWindowFromCalendars.get().endDate(); |
|
0 commit comments