Skip to content
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

Updated DirectionsWaypoint object #1360

Merged
merged 2 commits into from
Feb 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mapbox.api.directions.v5.models;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.google.auto.value.AutoValue;
import com.google.gson.Gson;
Expand Down Expand Up @@ -33,31 +34,32 @@ public static Builder builder() {
* @return string with the name of the way the coordinate snapped to
* @since 1.0.0
*/
@Nullable
@NonNull
Copy link
Contributor

Choose a reason for hiding this comment

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

This is technically SemVer although we could treat it as a bug.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's my thinking, not a semver for the getter only for the setter, but more of a bug nonetheless.

public abstract String name();

/**
* A {@link Point} representing this waypoint location.
* A {@link Point} representing this waypoint location. This point is snapped to the road network.
*
* @return GeoJson Point representing this waypoint location
* @since 3.0.0
*/
@Nullable
@NonNull
public Point location() {
return Point.fromLngLat(rawLocation()[0], rawLocation()[1]);
}

/**
* A {@link Point} representing this waypoint location.
*
* @return GeoJson Point representing this waypoint location
* @since 3.0.0
*/
@Nullable
@NonNull
@SerializedName("location")
@SuppressWarnings("mutable")
abstract double[] rawLocation();

/**
* The straight-line distance from the coordinate specified in the query
* to the location it was snapped to.
*/
@Nullable
public abstract Double distance();

/**
* Convert the current {@link DirectionsWaypoint} to its builder holding the currently assigned
* values. This allows you to modify a single property and then rebuild the object resulting in
Expand Down Expand Up @@ -109,10 +111,11 @@ public abstract static class Builder {
* @return this builder for chaining options together
* @since 3.0.0
*/
public abstract Builder name(@Nullable String name);
public abstract Builder name(@NonNull String name);

/**
* The rawLocation as a double array. Once the {@link DirectionsWaypoint} objects created,
* The rawLocation as a double array representing a location snapped to the road network.
* Once the {@link DirectionsWaypoint} objects created,
* this raw location gets converted into a {@link Point} object and is public exposed as such.
* The double array should have a length of two, index 0 being the longitude and index 1 being
* latitude.
Expand All @@ -122,7 +125,16 @@ public abstract static class Builder {
* @return this builder for chaining options together
* @since 3.0.0
*/
public abstract Builder rawLocation(@Nullable double[] rawLocation);
public abstract Builder rawLocation(@NonNull double[] rawLocation);

/**
* The straight-line distance from the coordinate specified in the query
* to the location it was snapped to.
*
* @param distance distance from original requested location
*/
@Nullable
public abstract Builder distance(@Nullable Double distance);

/**
* Build a new {@link DirectionsWaypoint} object.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,15 @@ public void tearDown() throws IOException {
public void sanity() throws Exception {
DirectionsWaypoint waypoint = DirectionsWaypoint.builder()
.name("foobar")
.rawLocation(new double[] {1.0, 2.0})
.build();
assertNotNull(waypoint);
}

@Test
public void location_doesGetConvertedToGeoJsonPoint() throws Exception {
DirectionsWaypoint waypoint = DirectionsWaypoint.builder()
.name("name")
.rawLocation(new double[] {1.0, 2.0})
.build();
assertNotNull(waypoint.location());
Expand Down