diff --git a/src/ext/java/org/opentripplanner/ext/siri/SiriTimetableSnapshotSource.java b/src/ext/java/org/opentripplanner/ext/siri/SiriTimetableSnapshotSource.java index 7746df7d02f..62bacbec11a 100644 --- a/src/ext/java/org/opentripplanner/ext/siri/SiriTimetableSnapshotSource.java +++ b/src/ext/java/org/opentripplanner/ext/siri/SiriTimetableSnapshotSource.java @@ -304,8 +304,7 @@ private Result addTripToGraphAndBuffer(TripUpdate tr pattern = tripUpdate.addedTripPattern(); } else { // Get cached trip pattern or create one if it doesn't exist yet - pattern = - tripPatternCache.getOrCreateTripPattern(tripUpdate.stopPattern(), trip, serviceDate); + pattern = tripPatternCache.getOrCreateTripPattern(tripUpdate.stopPattern(), trip); } // Add new trip times to buffer, making protective copies as needed. Bubble success/error up. diff --git a/src/ext/java/org/opentripplanner/ext/siri/SiriTripPatternCache.java b/src/ext/java/org/opentripplanner/ext/siri/SiriTripPatternCache.java index 40c008d0004..571a0790718 100644 --- a/src/ext/java/org/opentripplanner/ext/siri/SiriTripPatternCache.java +++ b/src/ext/java/org/opentripplanner/ext/siri/SiriTripPatternCache.java @@ -1,6 +1,5 @@ package org.opentripplanner.ext.siri; -import java.time.LocalDate; import java.util.HashMap; import java.util.Map; import java.util.function.Function; @@ -30,10 +29,13 @@ */ public class SiriTripPatternCache { - // TODO RT_AB: Improve documentation. This seems to be the primary collection of added - // TripPatterns, with other collections serving as indexes. Similar to TripPatternCache.cache - // in the GTFS version of this class, but with service date as part of the key. - private final Map cache = new HashMap<>(); + /** + * We cache the trip pattern based on the stop pattern only in order to de-duplicate them. + *

+ * Note that we don't really have a definition which properties are really part of the trip + * pattern and several pattern keys are used in different parts of OTP. + */ + private final Map cache = new HashMap<>(); // TODO RT_AB: generalize this so we can generate IDs for SIRI or GTFS-RT sources. private final SiriTripPatternIdGenerator tripPatternIdGenerator; @@ -72,8 +74,7 @@ public SiriTripPatternCache( */ public synchronized TripPattern getOrCreateTripPattern( @Nonnull final StopPattern stopPattern, - @Nonnull final Trip trip, - @Nonnull LocalDate serviceDate + @Nonnull final Trip trip ) { TripPattern originalTripPattern = getPatternForTrip.apply(trip); @@ -85,8 +86,7 @@ public synchronized TripPattern getOrCreateTripPattern( } // Check cache for trip pattern - StopPatternServiceDateKey key = new StopPatternServiceDateKey(stopPattern, serviceDate); - TripPattern tripPattern = cache.get(key); + TripPattern tripPattern = cache.get(stopPattern); // Create TripPattern if it doesn't exist yet if (tripPattern == null) { @@ -104,44 +104,9 @@ public synchronized TripPattern getOrCreateTripPattern( // TODO: Add pattern to transitModel index? // Add pattern to cache - cache.put(key, tripPattern); + cache.put(stopPattern, tripPattern); } return tripPattern; } } - -// TODO RT_AB: move the below classes inside the above class as private static inner classes. -// Defining these additional classes in the same top-level class file is unconventional. - -/** - * Serves as the key for the collection of TripPatterns added by realtime messages. - * Must define hashcode and equals to confer semantic identity. - * TODO RT_AB: clarify why each date has a different TripPattern instead of a different Timetable. - * It seems like there's a separate TripPattern instance for each StopPattern and service date, - * rather a single TripPattern instance associated with a separate timetable for each date. - */ -class StopPatternServiceDateKey { - - StopPattern stopPattern; - LocalDate serviceDate; - - public StopPatternServiceDateKey(StopPattern stopPattern, LocalDate serviceDate) { - this.stopPattern = stopPattern; - this.serviceDate = serviceDate; - } - - @Override - public int hashCode() { - return stopPattern.hashCode() + serviceDate.hashCode(); - } - - @Override - public boolean equals(Object thatObject) { - if (!(thatObject instanceof StopPatternServiceDateKey)) { - return false; - } - StopPatternServiceDateKey that = (StopPatternServiceDateKey) thatObject; - return (this.stopPattern.equals(that.stopPattern) && this.serviceDate.equals(that.serviceDate)); - } -}