Repository navigation
Remove GraphExtension interface - #1783
Conversation
| wayGeometry.create(initSize); | ||
| nameIndex.create(initSize); | ||
| extStorage.create(initSize); | ||
| if (supportsTurnCosts()) { |
There was a problem hiding this comment.
These checks are a bit ugly but I don't think its really worth it to have something like NoOpTurnCostExtension extends TurnCostExtension that overrides all the methods with no-op implementations, or have an extra interface for this purpose.
There was a problem hiding this comment.
NoOpTurnCostExtension extends TurnCostExtension that overrides all the methods with no-op implementations
Why not :D ?
There was a problem hiding this comment.
Option 1: create a subclass of turn cost extension and overwrite all methods (with no-ops): I dont like this, because in future whenever turn cost extension changes we need to update this subclass as well (feels redundant)
Option 2: create some interface: I dont like this because we need to put all methods we are using in turn cost extension into this interface, also not sure what type to return in coypTo for example.
The way its done now we have to check every access to turnCostExtension for null (supportsTurnCosts). I don't know, I did both and liked this better :D but of course we can do it another way if you have a preference
There was a problem hiding this comment.
Yes, I don't like option 1 too much either, but I still have a low preference for it due to the better readability inside BaseGraph (the ifs attract too much attention IMO).
turnCostExtension for null
With the NoOp we could introduce an isActive() method and make the public API slightly more readable?
storage.getTurnCostExtension().isActive()
But I have no strong opinion, so please feel free to merge it like it is :)
There was a problem hiding this comment.
Yes now you got me thinking again :) I'll try option 2 again it would be nice to have Graph#getTurnCostExtension return an interface rather than the implementation (TurnCostExtension)
There was a problem hiding this comment.
Now I extracted an interface for TurnCostExtension (see last two commits). I also tried with the no-op implementation. Still dont really like it :)
There was a problem hiding this comment.
Not so sure with the TurnCostExtension interface as we only have a single (real) implementation. But yes, NoOp extending "TurnCostExtensionImpl" also smells. Uhm.
There was a problem hiding this comment.
I thought its a bit of an improvement because this way Graph#getTurnCostExtension does not return something that has implementation specific stuff like setSegmentSize(). NoOp does not extend TurnCostExtensionImpl, but just implements the interface (ah yeah but it did before...). Oh well shall I just go back to my original version for now ? I think with #1775 etc. we will do more changes anyway.
There was a problem hiding this comment.
I like 0d487cd but please do not hesitate to return to your original version as you do not seem convinced :) and as you said we can later improve this.
There was a problem hiding this comment.
Ok I'll go back to the original version and we'll keep this in mind in the upcoming refactorings
GraphHopperStorageandBaseGraphno longer take aGraphExtensionas constructor arguments. Instead,TurnCostExtensionis created (or not created) inBaseGraphdirectly. TheE_ADDITIONALflag is gone (it was never used in core). I renamedN_ADDITIONALtoN_TC, because it is now (solely) used to store the turn cost table index for a node.Graph#getExtensionis now calledGraph#getTurnCostExtensionand returnsnullif the storage was configured without turn costs.I also removed
TurnCostExtension#init()and moved everything to the constructor. This means the error we got in #1398 can no longer happen. However, we still have not implemented graph sorting in the presence of turn costs and I am now throwing a more explicit error in this case.Overall I just moved around code here, any more sophisticated refactorings related to turn cost storage probably will go with #1775 or later PRs.
Fixes #1772