-
Notifications
You must be signed in to change notification settings - Fork 117
RouteOptions and MapboxDirections refactoring #1118
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
Conversation
services-core/src/main/java/com/mapbox/core/utils/TextUtils.java
Outdated
Show resolved
Hide resolved
services-directions-models/src/main/java/com/mapbox/api/directions/v5/models/RouteOptions.java
Outdated
Show resolved
Hide resolved
|
Also, maybe I should make all list params in |
LukasPaczos
left a comment
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 you drop changes from #1115? We don't actually want to merge them into master.
services-core/src/main/java/com/mapbox/core/utils/TextUtils.java
Outdated
Show resolved
Hide resolved
services-core/src/main/java/com/mapbox/core/utils/TextUtils.java
Outdated
Show resolved
Hide resolved
| approaches[i] = ""; | ||
| } else if (!approaches[i].equals("unrestricted") | ||
| && !approaches[i].equals("curb") && !approaches[i].isEmpty()) { | ||
| public static String formatApproaches(List<String> approaches) { |
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.
Same as above.
services-core/src/main/java/com/mapbox/core/utils/TextUtils.java
Outdated
Show resolved
Hide resolved
services-directions-models/src/main/java/com/mapbox/api/directions/v5/models/RouteOptions.java
Outdated
Show resolved
Hide resolved
services-directions-models/src/main/java/com/mapbox/api/directions/v5/models/RouteOptions.java
Outdated
Show resolved
Hide resolved
Guardiola31337
left a comment
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.
Left a couple of minor comments.
services-core/src/main/java/com/mapbox/core/utils/TextUtils.java
Outdated
Show resolved
Hide resolved
services-core/src/main/java/com/mapbox/core/utils/TextUtils.java
Outdated
Show resolved
Hide resolved
4beac8c to
3414cde
Compare
services-directions-models/src/main/java/com/mapbox/api/directions/v5/models/RouteOptions.java
Outdated
Show resolved
Hide resolved
services-directions-models/src/main/java/com/mapbox/api/directions/v5/models/RouteOptions.java
Outdated
Show resolved
Hide resolved
c38d662 to
76de915
Compare
services-directions-models/src/main/java/com/mapbox/api/directions/v5/utils/FormatUtils.java
Outdated
Show resolved
Hide resolved
fe0b214 to
1d4d6e6
Compare
Yeah, as indicated in the docs (👀 at the * @param waypointIndices which input coordinates should be treated as waypoints/separate legs
* Note: coordinate indices not added here act as silent waypointswe can skip them. But we need to be careful in this particular case because the valid formatting that the Directions API is expecting (imagine we have 3 waypoints) would be
Walking parameters are optional 👀 https://docs.mapbox.com/api/navigation/#optional-parameters-for-the-mapboxwalking-profile so |
|
In any case, in order to verify all these "unknowns" / questions and make sure everything is working as expected, it'd be 💯 if we can create a |
services-directions-models/src/main/java/com/mapbox/api/directions/v5/models/RouteOptions.java
Outdated
Show resolved
Hide resolved
...es-directions-models/src/test/java/com/mapbox/api/directions/v5/models/RouteOptionsTest.java
Outdated
Show resolved
Hide resolved
...es-directions-models/src/test/java/com/mapbox/api/directions/v5/models/RouteOptionsTest.java
Show resolved
Hide resolved
services-directions-models/src/main/java/com/mapbox/api/directions/v5/models/RouteOptions.java
Outdated
Show resolved
Hide resolved
services-directions-models/src/main/java/com/mapbox/api/directions/v5/models/RouteOptions.java
Outdated
Show resolved
Hide resolved
services-directions-models/src/main/java/com/mapbox/api/directions/v5/models/RouteOptions.java
Outdated
Show resolved
Hide resolved
services-directions-models/src/main/java/com/mapbox/api/directions/v5/models/RouteOptions.java
Outdated
Show resolved
Hide resolved
| return null; | ||
| } | ||
|
|
||
| // trailing nulls should be dropped |
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.
Are we sure that this is correct @korshaknn @Guardiola31337 @danpaz?
If I understand correctly, the nulls/empty strings should only be avoided for waypoints. For fields like bearings or radiuses we still want to have all of the nulls/empty strings be represented, even if they are trailing because the number of arguments has to match the number of coordinates.
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.
current code works with Strings and split is used to parse input string.
split method removes trailing empty strings, so I just implemented the same logic, but with Lists
please check MapboxDirectionsUtils, to parse Strings we use Kotlin
someString.split(SEMICOLON.toRegex()).dropLastWhile { it.isEmpty() }
so, we drop empty strings. (it works exactly as java split does).
@LukasPaczos @Guardiola31337
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.
Is that what Directions API expects though? The number of input values is going to differ in comparison to the size of the coordinate, isn't it?
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.
Yeah @LukasPaczos is right here 👇
If I understand correctly, the nulls/empty strings should only be avoided for waypoints. For fields like
bearingsorradiuseswe still want to have all of thenulls/empty strings be represented, even if they are trailing because the number of arguments has to match the number of coordinates.
We need to make sure the number of coordinates match with the number of coordinates (except for waypointIndices as discussed above).
cc @danpaz
...es-directions-models/src/test/java/com/mapbox/api/directions/v5/models/RouteOptionsTest.java
Outdated
Show resolved
Hide resolved
Guardiola31337
left a comment
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.
Left some minor comments.
services-directions-models/src/main/java/com/mapbox/api/directions/v5/utils/FormatUtils.java
Outdated
Show resolved
Hide resolved
services-directions-models/src/main/java/com/mapbox/api/directions/v5/utils/FormatUtils.java
Show resolved
Hide resolved
services-directions-models/src/main/java/com/mapbox/api/directions/v5/utils/ParseUtils.java
Outdated
Show resolved
Hide resolved
LukasPaczos
left a comment
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.
LGTM. Did you have a chance to verify if snapshot works in the Nav SDK?
| */ | ||
| @Nullable | ||
| public static String join(@NonNull CharSequence delimiter, @Nullable List<?> tokens, | ||
| boolean removeTrailingNulls) { |
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.
is removeTrailingNulls always false? Maybe we can remove it if that's the case? One less thing to test and maintain.
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.
it is true for waypointIndices
waypointIndices(FormatUtils.join(";", waypointIndices, true));
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.
Do we need it though? The docs are clear that we are looking for indices and passing nulls will be invalid, and the response error will point it out probably. Removing values under the hood might just introduce unexpected behavior.
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 added it just to try to handle customers invalid input String (or list with trailing nulls).
But maybe you are right and we should not do it under the hood.
|
Awesome work! |
beab146 to
b717d11
Compare
Guardiola31337
left a comment
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.
Great work @korshaknn 💪
Left a minor comment and noticed that we're not adding @NonNull annotation to fromJson 👀
Line 507 in d466d1d
| public static RouteOptions fromJson(String json) { |
Other than that ![]()
circle.yml
Outdated
| name: Publish Java libraries to Bintray | ||
| command: | | ||
| if [[ $CIRCLE_BRANCH == master ]] || [[ $CIRCLE_TAG == v* ]]; then | ||
| if [[ $CIRCLE_BRANCH == knn-options-refactoring ]] || [[ $CIRCLE_TAG == v* ]]; then |
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.
Revert this before merging.
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 still applies.
2256359 to
1ebcd68
Compare
|
@LukasPaczos @Guardiola31337 during snapshot testing I found some issues with Also I removed methods from |
services-directions/src/main/java/com/mapbox/api/directions/v5/MapboxDirections.java
Show resolved
Hide resolved
services-directions/src/main/java/com/mapbox/api/directions/v5/MapboxDirections.java
Show resolved
Hide resolved
services-directions/src/main/java/com/mapbox/api/directions/v5/MapboxDirections.java
Show resolved
Hide resolved
services-directions/src/main/java/com/mapbox/api/directions/v5/MapboxDirections.java
Show resolved
Hide resolved
services-directions/src/main/java/com/mapbox/api/directions/v5/MapboxDirections.java
Show resolved
Hide resolved
services-directions/src/main/java/com/mapbox/api/directions/v5/MapboxDirections.java
Show resolved
Hide resolved
services-directions-models/src/main/java/com/mapbox/api/directions/v5/utils/FormatUtils.java
Outdated
Show resolved
Hide resolved
...es-directions-models/src/test/java/com/mapbox/api/directions/v5/models/RouteOptionsTest.java
Outdated
Show resolved
Hide resolved
4d8016c to
6b53e5e
Compare
Yeah, before we had mapbox-java/services-directions/src/main/java/com/mapbox/api/directions/v5/MapboxDirections.java Lines 593 to 596 in 6b53e5e
List<String> unless we create an Annotation type. But yeah, as you mentioned for now it's fine as it's properly documented.
|
Guardiola31337
left a comment
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.
Thanks for addressing the feedback @korshaknn
I left some minor comments but not necessarily blocking the PR.
Let's see if these new APIs make sense when used from a client e.g. the Navigation SDK mapbox/mapbox-navigation-android#2477 and iterate if not 🚀
circle.yml
Outdated
| name: Publish Java libraries to Bintray | ||
| command: | | ||
| if [[ $CIRCLE_BRANCH == master ]] || [[ $CIRCLE_TAG == v* ]]; then | ||
| if [[ $CIRCLE_BRANCH == knn-options-refactoring ]] || [[ $CIRCLE_TAG == v* ]]; then |
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 still applies.
services-directions-models/src/main/java/com/mapbox/api/directions/v5/utils/FormatUtils.java
Outdated
Show resolved
Hide resolved
| annotations.add(ANNOTATION_DISTANCE); | ||
| annotations.add(ANNOTATION_MAXSPEED); | ||
| annotations.add(ANNOTATION_SPEED); | ||
| annotations.add(null); |
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.
Not sure if we want to accept null and then trim them 🤔 But it's good for now.
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.
passed Annotations List might have null values. I think we can't forbid it, so we need to have logic to remove them. Also we can update docs (in a separate PR) to make it valid params clearer.
|
|
||
| @Test | ||
| public void annotationsString() { | ||
| String annotationsStr = ANNOTATION_MAXSPEED + ";" + ANNOTATION_DURATION + ";" + ";"; |
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.
Same here. Not sure if we want to accept unnecessary ; and then trim them 🤔 In any case, it's good for now 👍
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.
see the comment above
6b53e5e to
1b74523
Compare
Curent PR also has changes from #1115