-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make Timetable immutable #6017
Make Timetable immutable #6017
Conversation
All trip-times in a Timetable should be ordered by the first departure-time for the first stop in the trip pattern. This was not enforced in the Timetable <-> TimetableBuilder, but relied on the "outside" to do it. This PR enforces this and provides two methods for adding trip-times to a Timetable (add & addOrUpdate).
34cceb3
to
4b6a019
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev-2.x #6017 +/- ##
=============================================
+ Coverage 69.82% 69.84% +0.02%
- Complexity 17419 17451 +32
=============================================
Files 1974 1975 +1
Lines 74545 74600 +55
Branches 7633 7634 +1
=============================================
+ Hits 52048 52106 +58
+ Misses 19847 19843 -4
- Partials 2650 2651 +1 ☔ View full report in Codecov by Sentry. |
As detailed in #6067, changing the order in which GTFS trips are imported changes the results of the speed test. This is most likely the reason why the speed test fails in this PR: while the order Trips are iterated over is the same, the order in which TripPatterns are built is different. Investigating and fixing this issue is not in the scope of this PR, but we should at least make sure that test results are stable/reproducible. |
src/main/java/org/opentripplanner/transit/model/network/TripPatternBuilder.java
Show resolved
Hide resolved
src/test/java/org/opentripplanner/gtfs/GenerateTripPatternsOperationTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/opentripplanner/gtfs/GenerateTripPatternsOperationTest.java
Show resolved
Hide resolved
Thanks for the call where you explained the PR. I will give this a second review once @t2gran's issued have been resolve. Also, there are merge conflicts. |
# Conflicts: # src/test/java/org/opentripplanner/transit/service/PatternByServiceDatesFilterTest.java # src/test/java/org/opentripplanner/updater/trip/RealtimeTestEnvironment.java
Oops, this PR should have been tagged with Line 96 in a3d0e67
|
Summary
This PR refactors the
Timetable
class to make it immutable after construction.The PR introduces a
TimetableBuilder
.The builder enforces 2 business rules:
In addition, the TripTimes sorting logic is removed from the TransitLayerMapper, since this is now redundant.
Implementation notes:
Most of the refactoring consists in deferring the creation of the Timetable and TripPattern instances by accumulating changes in their respective builders.
There are 3 notable difficulties:
TripPattern
contains a scheduledTimetable
that must be created at the same time as theTripPattern
itself, the 2 builders (TripPatternBuilder
andTimetableBuilder
) must be nested.TimetableSnapshot
:Implementing copy-on-write in
TimetableSnapshot
induces some extra work, with entities and collections being repeatedly re-created. When profiling this does not seem to impact performance significantly.GenerateTripPatternsOperation
:GTFS trips are grouped by direction in a given TripPattern. When using a builder, the direction of a Timetable must be evaluated before the Timetable is built, which adds some complexity.
Issue
No
Unit tests
Added unit tests.
Updated unit tests.
Documentation
No