Skip to content

Conversation

@korshaknn
Copy link
Contributor

@korshaknn korshaknn commented Jan 30, 2020

Curent PR also has changes from #1115

@korshaknn
Copy link
Contributor Author

Also, maybe I should make all list params in MapboxDirections Nullable? to make it possible to remove remove unnecessary ones?

Copy link
Contributor

@LukasPaczos LukasPaczos left a 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.

approaches[i] = "";
} else if (!approaches[i].equals("unrestricted")
&& !approaches[i].equals("curb") && !approaches[i].isEmpty()) {
public static String formatApproaches(List<String> approaches) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above.

Copy link
Contributor

@Guardiola31337 Guardiola31337 left a 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.

@korshaknn korshaknn force-pushed the knn-options-refactoring branch 14 times, most recently from 4beac8c to 3414cde Compare February 3, 2020 07:25
@korshaknn korshaknn force-pushed the knn-options-refactoring branch 2 times, most recently from c38d662 to 76de915 Compare February 3, 2020 12:23
@korshaknn korshaknn force-pushed the knn-options-refactoring branch 2 times, most recently from fe0b214 to 1d4d6e6 Compare February 3, 2020 12:40
@Guardiola31337
Copy link
Contributor

@korshaknn

what about waypointIndices, can we skip them passing an empty string or a null value?

Yeah, as indicated in the docs (👀 at the Note)

   * @param waypointIndices     which input coordinates should be treated as waypoints/separate legs
   *                            Note: coordinate indices not added here act as silent waypoints

we 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 waypoints=0;2 (✅) and not waypoints=0;;2 (❌) - note that "" trail is invalid, while it's needed for other parameters. Does that make sense? Let me know if this example isn't clear enough to understand the subtle difference. cc @danpaz

uuid and walkingOptions are Nullable in DirectionsResponse, but NonNull in RouteOptions. Which one should I use?

uuid it's in the DirectionsResponse and it's not always set so it should be @Nullable.

Walking parameters are optional 👀 https://docs.mapbox.com/api/navigation/#optional-parameters-for-the-mapboxwalking-profile so @Nullable as well.

@Guardiola31337
Copy link
Contributor

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 SNAPSHOT and test downstream from the Navigation SDK side.

return null;
}

// trailing nulls should be dropped
Copy link
Contributor

@LukasPaczos LukasPaczos Feb 12, 2020

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.

Copy link
Contributor Author

@korshaknn korshaknn Feb 12, 2020

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

Copy link
Contributor

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?

Copy link
Contributor

@Guardiola31337 Guardiola31337 Feb 12, 2020

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 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.

We need to make sure the number of coordinates match with the number of coordinates (except for waypointIndices as discussed above).

cc @danpaz

Copy link
Contributor

@Guardiola31337 Guardiola31337 left a 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.

Copy link
Contributor

@LukasPaczos LukasPaczos left a 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) {
Copy link
Contributor

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.

Copy link
Contributor Author

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));

Copy link
Contributor

@LukasPaczos LukasPaczos Feb 13, 2020

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.

Copy link
Contributor Author

@korshaknn korshaknn Feb 13, 2020

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.

@LukasPaczos
Copy link
Contributor

Awesome work!

@korshaknn korshaknn force-pushed the knn-options-refactoring branch from beab146 to b717d11 Compare February 13, 2020 13:02
Copy link
Contributor

@Guardiola31337 Guardiola31337 left a 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 👀

Other than that :shipit:

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
Copy link
Contributor

Choose a reason for hiding this comment

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

Revert this before merging.

Copy link
Contributor

Choose a reason for hiding this comment

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

This still applies.

@korshaknn korshaknn force-pushed the knn-options-refactoring branch 3 times, most recently from 2256359 to 1ebcd68 Compare February 14, 2020 13:12
@korshaknn
Copy link
Contributor Author

korshaknn commented Feb 14, 2020

@LukasPaczos @Guardiola31337 during snapshot testing I found some issues with MapboxDirections and annotations inside RouteOptions. Please check my last commit

Also I removed methods from MapboxDirections which had varargs param, now only methods with Lists available.

@korshaknn korshaknn force-pushed the knn-options-refactoring branch 3 times, most recently from 4d8016c to 6b53e5e Compare February 14, 2020 15:53
@Guardiola31337
Copy link
Contributor

@korshaknn #1118 (comment)

we can't iterate on them, they are just static constants.
I can remove that check, docs have full description according valid params.

Yeah, before we had @AnnotationCriteria

@Deprecated
public Builder annotations(@AnnotationCriteria @NonNull String... annotations) {
return annotations(Arrays.asList(annotations));
}
but now we cannot control that in List<String> unless we create an Annotation type. But yeah, as you mentioned for now it's fine as it's properly documented.

Copy link
Contributor

@Guardiola31337 Guardiola31337 left a 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
Copy link
Contributor

Choose a reason for hiding this comment

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

This still applies.

annotations.add(ANNOTATION_DISTANCE);
annotations.add(ANNOTATION_MAXSPEED);
annotations.add(ANNOTATION_SPEED);
annotations.add(null);
Copy link
Contributor

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.

Copy link
Contributor Author

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 + ";" + ";";
Copy link
Contributor

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 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

see the comment above

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants