Skip to content
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 ScheduledTransitLeg, FlexibleTransitLeg fully immutable #6386

Merged

Conversation

leonardehrenfried
Copy link
Member

Summary

Right now the ScheduledTransitLeg is mostly immutable apart from a few fields

  • distanceMeters due to testing
  • alerts because they are added later
  • fareProducts they are also added later

Because Aracadis has a few sandbox features that manipulate the legs over the years I had to fix many bugs because of the leg is half immutable and half mutable. I would like to fix all of them at once and therefore I'm making the ScheduledTransitLeg and FlexibleTransitLeg immutable and all fields must now be set via a builder.

There is also the special sandbox leg ConsolidatedStopLeg which also required some special handling but it is now also fully immutable and has a builder.

Unit tests

Lots of tests added and some re-written.

Documentation

Javadoc.

Copy link

codecov bot commented Jan 15, 2025

Codecov Report

Attention: Patch coverage is 93.24324% with 10 lines in your changes missing coverage. Please review.

Project coverage is 69.86%. Comparing base (448ad8f) to head (b2ac81f).
Report is 235 commits behind head on dev-2.x.

Files with missing lines Patch % Lines
...r/ext/fares/impl/CombinedInterlinedTransitLeg.java 0.00% 3 Missing ⚠️
...ntripplanner/ext/fares/FaresToItineraryMapper.java 50.00% 1 Missing and 1 partial ⚠️
...ntripplanner/model/plan/UnknownTransitPathLeg.java 0.00% 2 Missing ⚠️
...tripplanner/model/plan/LegConstructionSupport.java 87.50% 1 Missing ⚠️
...terchain/filters/transit/DecorateTransitAlert.java 83.33% 1 Missing ⚠️
...er/routing/algorithm/mapping/AlertToLegMapper.java 92.85% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##             dev-2.x    #6386      +/-   ##
=============================================
+ Coverage      69.72%   69.86%   +0.14%     
- Complexity     18016    18156     +140     
=============================================
  Files           2057     2072      +15     
  Lines          76967    77324     +357     
  Branches        7844     7851       +7     
=============================================
+ Hits           53666    54026     +360     
+ Misses         20550    20543       -7     
- Partials        2751     2755       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@leonardehrenfried leonardehrenfried changed the title Make ScheduledTransitLeg, FlexibleTransitLeg immutable Make ScheduledTransitLeg, FlexibleTransitLeg fully immutable Jan 17, 2025
Copy link
Contributor

@habrahamsson-skanetrafiken habrahamsson-skanetrafiken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great work. Making these model classes fully immutable makes stuff so much simpler to reason about.

@leonardehrenfried
Copy link
Member Author

I've moved the computation of distanceMeters entirely outside of ScheduledTransitLeg and its builder. This is ready for review again.

Co-authored-by: Henrik Abrahamsson <[email protected]>
Copy link
Member

@t2gran t2gran left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for fixing the "small things" it makes the code easier to read.

@leonardehrenfried leonardehrenfried merged commit 78d4c4b into opentripplanner:dev-2.x Feb 4, 2025
6 checks passed
@leonardehrenfried leonardehrenfried deleted the immutable-leg branch February 4, 2025 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants