-
Notifications
You must be signed in to change notification settings - Fork 117
Routable points support for services-geocoding #1522
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
services-geocoding/src/main/java/com/mapbox/api/geocoding/v5/models/RoutablePoint.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| package com.mapbox.api.geocoding.v5.models; | ||
|
|
||
| import androidx.annotation.Nullable; | ||
|
|
||
| import com.google.auto.value.AutoValue; | ||
| import com.google.gson.Gson; | ||
| import com.google.gson.TypeAdapter; | ||
| import com.google.gson.annotations.SerializedName; | ||
| import com.mapbox.geojson.Point; | ||
|
|
||
| /** | ||
| * Object representing {@link CarmenFeature}'s routable point. | ||
| */ | ||
| @AutoValue | ||
| public abstract class RoutablePoint { | ||
|
|
||
| /** | ||
| * A string representing the routable point name. | ||
| * | ||
| * @return routable point name | ||
| */ | ||
| @Nullable | ||
| @SerializedName("name") | ||
| public abstract String name(); | ||
|
|
||
| /** | ||
| * A {@link Point} object which represents the routable point location. | ||
| * | ||
| * @return a GeoJson {@link Point} which defines the routable point location | ||
| */ | ||
| @Nullable | ||
|
DzmitryFomchyn marked this conversation as resolved.
|
||
| public Point coordinate() { | ||
| final double[] coordinate = rawCoordinate(); | ||
| if (coordinate != null && coordinate.length == 2) { | ||
| return Point.fromLngLat(coordinate[0], coordinate[1]); | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| // No public access thus, we lessen enforcement on mutability here. | ||
| @Nullable | ||
|
DzmitryFomchyn marked this conversation as resolved.
|
||
| @SerializedName("coordinates") | ||
| @SuppressWarnings("mutable") | ||
| abstract double[] rawCoordinate(); | ||
|
|
||
| /** | ||
| * Convert current instance values into another Builder to quickly change one or more values. | ||
| * | ||
| * @return a new instance of {@link Builder} | ||
| */ | ||
| @SuppressWarnings("unused") | ||
| public abstract Builder toBuilder(); | ||
|
|
||
| /** | ||
| * Gson type adapter for parsing Gson to this class. | ||
| * | ||
| * @param gson the built {@link Gson} object | ||
| * @return the type adapter for this class | ||
| */ | ||
| public static TypeAdapter<RoutablePoint> typeAdapter(Gson gson) { | ||
| return new AutoValue_RoutablePoint.GsonTypeAdapter(gson); | ||
| } | ||
|
|
||
| /** | ||
| * This builder can be used to set the values describing the {@link RoutablePoint}. | ||
| */ | ||
| @AutoValue.Builder | ||
| @SuppressWarnings("unused") | ||
| public abstract static class Builder { | ||
|
|
||
| /** | ||
| * A string representing the routable point name. | ||
| * | ||
| * @param name routable point name | ||
| * @return this builder for chaining options together | ||
| */ | ||
| public abstract Builder name(@Nullable String name); | ||
|
DzmitryFomchyn marked this conversation as resolved.
|
||
|
|
||
| /** | ||
| * Raw coordinates (longitude and latitude, order matters) | ||
| * that represent the routable point location. | ||
| * | ||
| * @param coordinate raw coordinates that represent the routable point location | ||
| * @return this builder for chaining options together | ||
| */ | ||
| public abstract Builder rawCoordinate(@Nullable double[] coordinate); | ||
|
DzmitryFomchyn marked this conversation as resolved.
|
||
|
|
||
| /** | ||
| * Build a new {@link RoutablePoint} object. | ||
| * | ||
| * @return a new {@link RoutablePoint} using the provided values in this builder | ||
| */ | ||
| public abstract RoutablePoint build(); | ||
| } | ||
| } | ||
70 changes: 70 additions & 0 deletions
70
services-geocoding/src/main/java/com/mapbox/api/geocoding/v5/models/RoutablePoints.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| package com.mapbox.api.geocoding.v5.models; | ||
|
|
||
| import androidx.annotation.Nullable; | ||
|
|
||
| import com.google.auto.value.AutoValue; | ||
| import com.google.gson.Gson; | ||
| import com.google.gson.TypeAdapter; | ||
| import com.google.gson.annotations.SerializedName; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| /** | ||
| * An object with the routable points for the {@link CarmenFeature}. | ||
| */ | ||
| @AutoValue | ||
| public abstract class RoutablePoints { | ||
|
|
||
| /** | ||
| * A list of routable points for the {@link CarmenFeature}, or null if no points were found. | ||
| * | ||
| * @return a list of routable points for the {@link CarmenFeature}, | ||
| * or null if no points were found | ||
| */ | ||
| @Nullable | ||
| @SerializedName("points") | ||
| public abstract List<RoutablePoint> points(); | ||
|
|
||
| /** | ||
| * Convert current instance values into another Builder to quickly change one or more values. | ||
| * | ||
| * @return a new instance of {@link Builder} | ||
| */ | ||
| @SuppressWarnings("unused") | ||
| public abstract Builder toBuilder(); | ||
|
|
||
| /** | ||
| * Gson type adapter for parsing Gson to this class. | ||
| * | ||
| * @param gson the built {@link Gson} object | ||
| * @return the type adapter for this class | ||
| */ | ||
| public static TypeAdapter<RoutablePoints> typeAdapter(Gson gson) { | ||
| return new AutoValue_RoutablePoints.GsonTypeAdapter(gson); | ||
| } | ||
|
|
||
| /** | ||
| * This builder can be used to set the values describing the {@link RoutablePoints}. | ||
| */ | ||
| @AutoValue.Builder | ||
| @SuppressWarnings("unused") | ||
| public abstract static class Builder { | ||
|
|
||
| /** | ||
| * A list of routable points for the {@link CarmenFeature}, | ||
| * or null if no points were found. | ||
| * | ||
| * @param points a list of routable points for the {@link CarmenFeature}, | ||
| * or null if no points were found | ||
| * @return this builder for chaining options together | ||
| */ | ||
| public abstract Builder points(@Nullable List<RoutablePoint> points); | ||
|
|
||
| /** | ||
| * Build a new {@link RoutablePoints} object. | ||
| * | ||
| * @return a new {@link RoutablePoints} using the provided values in this builder | ||
| */ | ||
| public abstract RoutablePoints build(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 this really nullable? I mean, what I'd expect is
RoutablePointsto be nullable but If they're not, anyRoutablePointfrom the list to have valid values. Does that make sense?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.
@Guardiola31337 Do you mean by duplicating e.g. the rooftop location in
RoutablePoints? If yes, I disagree.I assume the correct distinction would be to leave
RoutablePointsnull if there are none and let the app logic decide how to behave in that case (e.g. fallback to original location). Otherwise it's becoming ambiguous whether the data is actually available for the specific search result.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.
@Guardiola31337 in addition to what @kalbaxa said, I think it's better to leave it as nullable because all the
service-geocoderrelies onAutoValue/GSONserialisation/deserialisation. If we declare any field as non-nullable and for some reason backend don't send the value, the SDK will crash. I don't want this. I think it's better to check for null on customer's side and use alternative fallback. Also, nullable fields are consistent with the current approach.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.
@kalbaxa What I meant was that routable points could be
null(that's totally fine) but if the server emits a routable point, I would expect not to benull(havingnullfields), that's the contract I'd expect from the backend.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.
@DzmitryFomchyn IMO errors in the backend should fail-fast, this approach would hide this type of issues as they'd go unnoticed.
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.
A can agree with that, but we should also be consistent here. All the current code relies on nullability, it won't make any better if we make one field as non-null while everything else remain nullable. Given everything that's written above, I think we should leave as is now and discuss another approach in case of SDK refactoring, if it happen. More likely,
service-geocoderwill be deprecated soon.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.
+++
Event if it's not an error on the backend side, it can be a logic change. For example, we accidentally made waypoints nullable but that played well because after some time they did become nullable because a case was introduced that they can be returned in a different response level.
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.
A logic change like this should mean a major version upgrade of an endpoint. All customers (not only Nav SDK) would be impacted by such an intentional change.
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 necessarily. With waypoints they wouldn't (and weren't). Because it depends on a new request parameter which falls back to old behaviour.
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.
We would have to provide backwards compatibility if that wasn't the case (either on backend or mapbox-java level). We were lucky and needed less work for that specific situation but that shouldn't be the reason to make contracts less strict going forward.