forked from HSLdevcom/OpenTripPlanner
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathDatedServiceJourneyHelper.java
67 lines (60 loc) · 2.2 KB
/
DatedServiceJourneyHelper.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package org.opentripplanner.routing;
import org.opentripplanner.common.model.T2;
import org.opentripplanner.model.FeedScopedId;
import org.opentripplanner.model.TimetableSnapshot;
import org.opentripplanner.model.TripOnServiceDate;
import org.opentripplanner.model.calendar.ServiceDate;
public class DatedServiceJourneyHelper {
/**
* Gets a TripOnServiceDate from a timetable snapshot if it has realtime updates otherwise from
* the graph index
*
* @param routingService
* @param tripId
* @param serviceDate
* @return
*/
public static TripOnServiceDate getTripOnServiceDate(
RoutingService routingService,
FeedScopedId tripId,
ServiceDate serviceDate
) {
var tuple = new T2<>(tripId, serviceDate);
if (routingService.getTimetableSnapshot() != null) {
if (routingService
.getTimetableSnapshot()
.getLastAddedTripOnServiceDateByTripIdAndServiceDate()
.containsKey(tuple)
) {
return routingService
.getTimetableSnapshot()
.getLastAddedTripOnServiceDateByTripIdAndServiceDate()
.get(tuple);
}
}
return routingService.getTripOnServiceDateForTripAndDay().get(tuple);
}
/**
* Gets a TripOnServiceDate from a timetable snapshot if it has realtime updates otherwise from
* the graph index
*
* @param routingService
* @param datedServiceJourneyId
* @return
*/
public static TripOnServiceDate getTripOnServiceDate(
RoutingService routingService,
FeedScopedId datedServiceJourneyId
) {
TimetableSnapshot timetableSnapshot = routingService.getTimetableSnapshot();
if (timetableSnapshot != null && timetableSnapshot
.getLastAddedTripOnServiceDate()
.containsKey(datedServiceJourneyId)
) {
return timetableSnapshot.getLastAddedTripOnServiceDate().get(datedServiceJourneyId);
}
return routingService
.getTripOnServiceDateById()
.get(datedServiceJourneyId);
}
}