-
Notifications
You must be signed in to change notification settings - Fork 318
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
Add NavigationHelper check for valid step points using lineSlice #944
Conversation
@@ -299,7 +300,7 @@ static NavigationIndices increaseIndex(RouteProgress routeProgress, | |||
List<StepIntersection> intersections) { | |||
List<Pair<StepIntersection, Double>> distancesToIntersections = new ArrayList<>(); | |||
List<StepIntersection> stepIntersections = new ArrayList<>(intersections); | |||
if (stepPoints.isEmpty()) { | |||
if (stepPoints.size() < TWO_POINTS) { |
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.
What about consolidating these two guard clauses 👇 (that return the same) extracting the conditional into a explaining variable?
Also what about creating stepIntersections
after the guard clauses?
Source code structure
Variables and methods should be defined close to where they are used.
Local variables should be declared just above their first usage and should
have a small vertical scope.
Clean Code (Robert C. Martin)
That way we avoid allocating it if any of the guard clauses is executed.
eee994e
to
866d52b
Compare
if (stepIntersections.isEmpty()) { | ||
boolean invalidPointList = stepPoints.size() < TWO_POINTS; | ||
boolean emptyIntersectionList = stepIntersections.isEmpty(); | ||
if (invalidPointList || emptyIntersectionList) { | ||
return distancesToIntersections; |
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.
Could we return Collections.emptyList()
to make it more explicit? If so we can move define distancesToIntersections
down, close to where it's used. BTW we should check if there's any implication on returning an immutable list in this case 👀 https://stackoverflow.com/questions/5552258/collections-emptylist-vs-new-instance#answer-5552287
@@ -299,10 +300,9 @@ static NavigationIndices increaseIndex(RouteProgress routeProgress, | |||
List<StepIntersection> intersections) { | |||
List<Pair<StepIntersection, Double>> distancesToIntersections = new ArrayList<>(); | |||
List<StepIntersection> stepIntersections = new ArrayList<>(intersections); |
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.
Why are we creating stepIntersections
here? We could check if intersections
is empty (instead of stepIntersections.isEmpty()
) and define it down (after the guard clause), close to where it's used. Am I missing something?
e7b121e
to
14e083e
Compare
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.
14e083e
to
cd8ce3a
Compare
Closes #932