3
3
import java .time .DayOfWeek ;
4
4
import java .time .LocalDate ;
5
5
import java .time .temporal .TemporalAdjusters ;
6
+ import java .util .Collection ;
7
+ import java .util .List ;
8
+ import java .util .function .Function ;
6
9
import java .util .function .Predicate ;
10
+ import java .util .function .Supplier ;
7
11
import org .opentripplanner .apis .gtfs .PatternByServiceDatesFilter ;
8
12
import org .opentripplanner .apis .gtfs .model .LocalDateRange ;
13
+ import org .opentripplanner .transit .model .network .TripPattern ;
9
14
import org .opentripplanner .transit .model .site .RegularStop ;
15
+ import org .opentripplanner .transit .model .timetable .Trip ;
10
16
import org .opentripplanner .transit .service .TransitService ;
11
17
12
18
/**
@@ -24,17 +30,24 @@ public class LayerFilters {
24
30
* Returns a predicate which only includes stop which are visited by a pattern that is in the current
25
31
* TriMet service week, namely from Sunday to Sunday.
26
32
*/
27
- public static Predicate <RegularStop > currentServiceWeek (TransitService transitService ) {
28
- var serviceDate = LocalDate .now (transitService .getTimeZone ());
33
+ public static Predicate <RegularStop > currentServiceWeek (
34
+ Function <RegularStop , Collection <TripPattern >> getPatternsForStop ,
35
+ Function <Trip , Collection <LocalDate >> getServiceDatesForTrip ,
36
+ Supplier <LocalDate > nowSupplier
37
+ ) {
38
+ var serviceDate = nowSupplier .get ();
29
39
var lastSunday = serviceDate .with (TemporalAdjusters .previousOrSame (DayOfWeek .SUNDAY ));
30
40
var nextSunday = serviceDate .with (TemporalAdjusters .next (DayOfWeek .SUNDAY )).plusDays (1 );
41
+
31
42
var filter = new PatternByServiceDatesFilter (
32
43
new LocalDateRange (lastSunday , nextSunday ),
33
- transitService
44
+ // not used
45
+ route -> List .of (),
46
+ getServiceDatesForTrip
34
47
);
35
48
36
49
return regularStop -> {
37
- var patterns = transitService . getPatternsForStop (regularStop );
50
+ var patterns = getPatternsForStop . apply (regularStop );
38
51
var patternsInCurrentWeek = filter .filterPatterns (patterns );
39
52
return !patternsInCurrentWeek .isEmpty ();
40
53
};
@@ -43,7 +56,12 @@ public static Predicate<RegularStop> currentServiceWeek(TransitService transitSe
43
56
public static Predicate <RegularStop > forType (FilterType type , TransitService transitService ) {
44
57
return switch (type ) {
45
58
case NONE -> NO_FILTER ;
46
- case CURRENT_TRIMET_SERVICE_WEEK -> currentServiceWeek (transitService );
59
+ case CURRENT_TRIMET_SERVICE_WEEK -> currentServiceWeek (
60
+ transitService ::getPatternsForStop ,
61
+ trip ->
62
+ transitService .getCalendarService ().getServiceDatesForServiceId (trip .getServiceId ()),
63
+ () -> LocalDate .now (transitService .getTimeZone ())
64
+ );
47
65
};
48
66
}
49
67
0 commit comments