-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Move PathTransfer to new transfer module #7115
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
base: dev-2.x
Are you sure you want to change the base?
Move PathTransfer to new transfer module #7115
Conversation
|
This is close, but only the root access points ( |
0abc62a to
e1216dc
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## dev-2.x #7115 +/- ##
=============================================
+ Coverage 72.05% 72.08% +0.02%
- Complexity 20679 20709 +30
=============================================
Files 2242 2250 +8
Lines 83801 83964 +163
Branches 8348 8347 -1
=============================================
+ Hits 60385 60526 +141
- Misses 20488 20510 +22
Partials 2928 2928 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
f4e5ee6 to
4dc2ef3
Compare
application/src/main/java/org/opentripplanner/standalone/configure/ConstructApplication.java
Outdated
Show resolved
Hide resolved
application/src/main/java/org/opentripplanner/transit/service/TimetableRepository.java
Show resolved
Hide resolved
application/src/main/java/org/opentripplanner/transfer/internal/DefaultTransferRepository.java
Outdated
Show resolved
Hide resolved
application/src/main/java/org/opentripplanner/transfer/internal/DefaultTransferRepository.java
Outdated
Show resolved
Hide resolved
application/src/main/java/org/opentripplanner/transfer/internal/DefaultTransferRepository.java
Outdated
Show resolved
Hide resolved
application/src/main/java/org/opentripplanner/transfer/TransferRepository.java
Show resolved
Hide resolved
| if (OTPFeature.FlexRouting.isOn()) { | ||
| // Flex transfers should only use WALK mode transfers. | ||
| for (PathTransfer transfer : transferRepository.findTransfers(StreetMode.WALK)) { | ||
| transfersToStop.put(transfer.to, transfer); | ||
| transfersFromStop.put(transfer.from, transfer); | ||
| } | ||
| } | ||
| LOG.info("Transfer repository index init complete."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the indices in this class are specific to flex I think that should be indicated in the names of the collections and the accessor methods. Now it looks like these are indices of all transfers to and from a specific stop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was a bit hesitant on how to refactor this part. I wanted to make sure that the index is only created when flex is on, so that the memory is conserved when it's off. But you do make a good point. I tried doing it with another abstraction layer now. I also moved the flex index code back to the sandbox package, I do get some Class xxx is not exported from module 'org.opentripplanner.otp' warnings from IntelliJ now though. I'm not a hundred percent sure how the dependencies between the sandbox and the core features should be managed best. Is what I did now in line with what we want to aim for in the future?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using inheritance instead of an interface might be better for future proving this, I can change it if you think that is a better idea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what the cleanest way would be to handle the flex specific indices and I don't really have a strong opinion. We do something similar for the timetable repository with FlexIndex, maybe you could mimic that? Perhaps @t2gran has an opinion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have now changed it to using inheritance. This way any future additions to the normal TransferIndex will be automatically adopted by the FlexTransferIndex. Additionally I put the flex feature toggle condition into the application construction code. The business logic is now free of any sandbox dependencies. I think this is a good goal to aim for, that way we can create an application construction module, a sandbox module and several business logic modules in the future and we'd have no circular dependencies.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The inheritance design looks good for now. It would be nice if we could document why we have this.
I am not sure why an extra index for the Flex is needed. The transit code have a similar index in the Raptor adaptor layer. It might be that the flex index support more stop types - if so this should be documented. Another difference is that the transit uses stopIndex for faster, more compact access. We need to decide what we do with the index in the Raptor adaptor layer as well. So, we can address both of these at the same time. I know there are differences for these indexes, but there is no documentation on "why" - this should be written in the JavaDoc on TransferIndex.
…refactoring # Conflicts: # application/src/ext-test/java/org/opentripplanner/ext/flex/trip/ScheduledDeviatedTripIntegrationTest.java # application/src/ext/java/org/opentripplanner/ext/flex/FlexIndex.java # application/src/test/java/org/opentripplanner/transit/model/_data/TransitTestEnvironmentBuilder.java
… index from normal index
…dex support any future additions to TransferIndex automatically
…not business logic
| * stable over the course of a request. | ||
| */ | ||
| public interface TransferService { | ||
| Collection<PathTransfer> findTransfersByStop(StopLocation stop); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method needs JavaDoc. It is not clear from the definition if the stop is the from or to stop, or both.
| if (!indexed) { | ||
| throw new IllegalStateException("The transfer index is needed but not initialized"); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The if().. can be extracted into a private method and reused below.
| if (OTPFeature.FlexRouting.isOn()) { | ||
| // Flex transfers should only use WALK mode transfers. | ||
| for (PathTransfer transfer : transferRepository.findTransfers(StreetMode.WALK)) { | ||
| transfersToStop.put(transfer.to, transfer); | ||
| transfersFromStop.put(transfer.from, transfer); | ||
| } | ||
| } | ||
| LOG.info("Transfer repository index init complete."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The inheritance design looks good for now. It would be nice if we could document why we have this.
I am not sure why an extra index for the Flex is needed. The transit code have a similar index in the Raptor adaptor layer. It might be that the flex index support more stop types - if so this should be documented. Another difference is that the transit uses stopIndex for faster, more compact access. We need to decide what we do with the index in the Raptor adaptor layer as well. So, we can address both of these at the same time. I know there are differences for these indexes, but there is no documentation on "why" - this should be written in the JavaDoc on TransferIndex.
| /** | ||
| * @param toStop {@code StopLocation} that is set as a to-stop | ||
| * @return all walk mode {@code PathTransfer}s with the specified {@code StopLocation} as a | ||
| * to-stop | ||
| * @throws UnsupportedOperationException if flex routing is not activated | ||
| * @throws IllegalStateException if the index was not initialized | ||
| */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| /** | |
| * @param toStop {@code StopLocation} that is set as a to-stop | |
| * @return all walk mode {@code PathTransfer}s with the specified {@code StopLocation} as a | |
| * to-stop | |
| * @throws UnsupportedOperationException if flex routing is not activated | |
| * @throws IllegalStateException if the index was not initialized | |
| */ |
This is not DRY, do not repeat information that is part of the method signature + return type. In this case I do not think there are any information in the doc at all.
In general we do not document "programming error" exceptions. The pre/post conditions are "runtime" documentation on how to use the methods. If you fail to do the index() the exception document the intention.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By the way, methods used as is by the service should be documented in the service interface, and it is not needed to document them twice - so leaving them without doc in the Repository is fine.
| * Initialize the index. This needs to be called before | ||
| * {@link #findWalkTransfersFromStop(StopLocation)} and {@link #findWalkTransfersToStop(StopLocation)} | ||
| */ | ||
| void index(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Witch methods are backed by the the index is a implementation detail - an abstraction leak.
| import org.opentripplanner.transfer.TransferRepository; | ||
| import org.opentripplanner.transit.model.site.StopLocation; | ||
|
|
||
| public class TransferIndex { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to see some doc on this interface:
- Why do we needed it -> Flex only user
- Why can we not reuse the Raptor Adaptor layer providing similar functionality?
If you find it hard to answer the above questions, you can just add TODOs instead.
Summary
This is a refactoring to enable the runtime modification of transfers. PathTransfers are pulled out of the TransitRepository and moved into their own repository. Constrained transfers will be moved into the same module in a next step.
Issue
It's the first step for the plan detailed in issue #7074
Unit tests
No new features and no new tests
Documentation
Bumping the serialization version id
yes