From 201b240afba27d938f25ce169bf57672e1b3532b Mon Sep 17 00:00:00 2001 From: danesfeder Date: Mon, 26 Mar 2018 16:42:56 -0400 Subject: [PATCH 1/9] Initial annotation work --- .../api/directions/v5/DirectionsCriteria.java | 10 +++++++++- .../api/directions/v5/models/LegAnnotation.java | 12 ++++++++++++ .../mapbox/api/directions/v5/models/MaxSpeed.java | 14 ++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 services-directions/src/main/java/com/mapbox/api/directions/v5/models/MaxSpeed.java diff --git a/services-directions/src/main/java/com/mapbox/api/directions/v5/DirectionsCriteria.java b/services-directions/src/main/java/com/mapbox/api/directions/v5/DirectionsCriteria.java index 665a79f01..a8f0bee6e 100644 --- a/services-directions/src/main/java/com/mapbox/api/directions/v5/DirectionsCriteria.java +++ b/services-directions/src/main/java/com/mapbox/api/directions/v5/DirectionsCriteria.java @@ -115,6 +115,13 @@ public final class DirectionsCriteria { */ public static final String ANNOTATION_CONGESTION = "congestion"; + /** + * The posted speed limit, between each pair of coordinates. + * + * @since 2.1.0 + */ + public static final String ANNOTATION_MAX_SPEED = "maxspeed"; + /** * Exclude all tolls along the returned directions route. * @@ -255,7 +262,8 @@ private DirectionsCriteria() { ANNOTATION_CONGESTION, ANNOTATION_DISTANCE, ANNOTATION_DURATION, - ANNOTATION_SPEED + ANNOTATION_SPEED, + ANNOTATION_MAX_SPEED }) public @interface AnnotationCriteria { } diff --git a/services-directions/src/main/java/com/mapbox/api/directions/v5/models/LegAnnotation.java b/services-directions/src/main/java/com/mapbox/api/directions/v5/models/LegAnnotation.java index bd84e02cb..3add5c988 100644 --- a/services-directions/src/main/java/com/mapbox/api/directions/v5/models/LegAnnotation.java +++ b/services-directions/src/main/java/com/mapbox/api/directions/v5/models/LegAnnotation.java @@ -58,6 +58,18 @@ public static Builder builder() { @Nullable public abstract List speed(); + /** + * The posted speed limit, between each pair of coordinates. + * Maxspeed is only available for the `mapbox/driving` and `mapbox/driving-traffic` + * profiles, other profiles will return `unknown`s only. + * + * @return a list with each entry being a {@link MaxSpeed} value between two of the routeLeg geometry + * coordinates + * @since 3.0.0 + */ + @Nullable + public abstract List maxSpeed(); + /** * The congestion between each pair of coordinates. * diff --git a/services-directions/src/main/java/com/mapbox/api/directions/v5/models/MaxSpeed.java b/services-directions/src/main/java/com/mapbox/api/directions/v5/models/MaxSpeed.java new file mode 100644 index 000000000..cb448f646 --- /dev/null +++ b/services-directions/src/main/java/com/mapbox/api/directions/v5/models/MaxSpeed.java @@ -0,0 +1,14 @@ +package com.mapbox.api.directions.v5.models; + +import android.support.annotation.Nullable; + +import com.google.auto.value.AutoValue; + +import java.io.Serializable; + +@AutoValue +public abstract class MaxSpeed implements Serializable { + + @Nullable + public abstract Integer speed(); +} From b68cb9fa0c7583bd7cdff5d1d89299c16a771b44 Mon Sep 17 00:00:00 2001 From: danesfeder Date: Tue, 27 Mar 2018 10:22:54 -0400 Subject: [PATCH 2/9] Finish maxspeed, add docs, adjust constant --- .../api/directions/v5/DirectionsCriteria.java | 4 +- .../api/directions/v5/models/MaxSpeed.java | 95 +++++++++++++++++++ 2 files changed, 97 insertions(+), 2 deletions(-) diff --git a/services-directions/src/main/java/com/mapbox/api/directions/v5/DirectionsCriteria.java b/services-directions/src/main/java/com/mapbox/api/directions/v5/DirectionsCriteria.java index a8f0bee6e..a0cb9e528 100644 --- a/services-directions/src/main/java/com/mapbox/api/directions/v5/DirectionsCriteria.java +++ b/services-directions/src/main/java/com/mapbox/api/directions/v5/DirectionsCriteria.java @@ -120,7 +120,7 @@ public final class DirectionsCriteria { * * @since 2.1.0 */ - public static final String ANNOTATION_MAX_SPEED = "maxspeed"; + public static final String ANNOTATION_MAXSPEED = "maxspeed"; /** * Exclude all tolls along the returned directions route. @@ -263,7 +263,7 @@ private DirectionsCriteria() { ANNOTATION_DISTANCE, ANNOTATION_DURATION, ANNOTATION_SPEED, - ANNOTATION_MAX_SPEED + ANNOTATION_MAXSPEED }) public @interface AnnotationCriteria { } diff --git a/services-directions/src/main/java/com/mapbox/api/directions/v5/models/MaxSpeed.java b/services-directions/src/main/java/com/mapbox/api/directions/v5/models/MaxSpeed.java index cb448f646..ebac7b2f2 100644 --- a/services-directions/src/main/java/com/mapbox/api/directions/v5/models/MaxSpeed.java +++ b/services-directions/src/main/java/com/mapbox/api/directions/v5/models/MaxSpeed.java @@ -3,12 +3,107 @@ import android.support.annotation.Nullable; import com.google.auto.value.AutoValue; +import com.google.gson.Gson; +import com.google.gson.TypeAdapter; import java.io.Serializable; @AutoValue public abstract class MaxSpeed implements Serializable { + /** + * Number indicating the posted speed limit. + * + * @return number indicating the posted speed limit + * @since 3.0.0 + */ @Nullable public abstract Integer speed(); + + /** + * String indicating the unit of speed, either as `kmh` or `mph`. + * + * @return String unit either as `kmh` or `mph` + * @since 3.0.0 + */ + @Nullable + public abstract String unit(); + + /** + * Boolean is true if the speed limit is not known, otherwise null. + * + * @return Boolean true if speed limit is not known, otherwise null + * @since 3.0.0 + */ + @Nullable + public abstract Boolean unknown(); + + /** + * Boolean is `true` if the speed limit is unlimited, otherwise null. + * + * @return Boolean true if speed limit is unlimited, otherwise null + * @since 3.0.0 + */ + @Nullable + public abstract Boolean none(); + + /** + * Gson type adapter for parsing Gson to this class. + * + * @param gson the built {@link Gson} object + * @return the type adapter for this class + * @since 3.0.0 + */ + public static TypeAdapter typeAdapter(Gson gson) { + return new AutoValue_MaxSpeed.GsonTypeAdapter(gson); + } + + /** + * This builder can be used to set the values describing the {@link MaxSpeed}. + * + * @since 3.0.0 + */ + @AutoValue.Builder + public abstract static class Builder { + + /** + * Number indicating the posted speed limit. + * + * @param speed indicating the posted speed limit + * @since 3.0.0 + */ + public abstract Builder speed(@Nullable Integer speed); + + /** + * String indicating the unit of speed, either as `kmh` or `mph`. + * + * @param unit either as `kmh` or `mph` + * @since 3.0.0 + */ + public abstract Builder unit(@Nullable String unit); + + /** + * Boolean is true if the speed limit is not known, otherwise null. + * + * @param unknown true if speed limit is not known, otherwise null + * @since 3.0.0 + */ + public abstract Builder unknown(@Nullable Boolean unknown); + + /** + * Boolean is `true` if the speed limit is unlimited, otherwise null. + * + * @param none true if speed limit is unlimited, otherwise null + * @since 3.0.0 + */ + public abstract Builder none(@Nullable Boolean none); + + /** + * Build a new {@link MaxSpeed} object. + * + * @return a new {@link MaxSpeed} using the provided values in this builder + * @since 3.0.0 + */ + public abstract MaxSpeed build(); + } } From 36e3b734ef9011417753330f8061f4cd86ee6420 Mon Sep 17 00:00:00 2001 From: danesfeder Date: Wed, 28 Mar 2018 09:25:38 -0400 Subject: [PATCH 3/9] Update javadoc --- .../com/mapbox/api/directions/v5/models/MaxSpeed.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/services-directions/src/main/java/com/mapbox/api/directions/v5/models/MaxSpeed.java b/services-directions/src/main/java/com/mapbox/api/directions/v5/models/MaxSpeed.java index ebac7b2f2..0a2bc8f4d 100644 --- a/services-directions/src/main/java/com/mapbox/api/directions/v5/models/MaxSpeed.java +++ b/services-directions/src/main/java/com/mapbox/api/directions/v5/models/MaxSpeed.java @@ -21,9 +21,9 @@ public abstract class MaxSpeed implements Serializable { public abstract Integer speed(); /** - * String indicating the unit of speed, either as `kmh` or `mph`. + * String indicating the unit of speed, either as `km/h` or `mph`. * - * @return String unit either as `kmh` or `mph` + * @return String unit either as `km/h` or `mph` * @since 3.0.0 */ @Nullable @@ -75,9 +75,9 @@ public abstract static class Builder { public abstract Builder speed(@Nullable Integer speed); /** - * String indicating the unit of speed, either as `kmh` or `mph`. + * String indicating the unit of speed, either as `km/h` or `mph`. * - * @param unit either as `kmh` or `mph` + * @param unit either as `km/h` or `mph` * @since 3.0.0 */ public abstract Builder unit(@Nullable String unit); From 89b97c78a20ae676dd8c8abd70c28b9df1ec8d7e Mon Sep 17 00:00:00 2001 From: danesfeder Date: Wed, 28 Mar 2018 09:31:13 -0400 Subject: [PATCH 4/9] Update type adapter --- .../main/java/com/mapbox/api/directions/v5/models/MaxSpeed.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services-directions/src/main/java/com/mapbox/api/directions/v5/models/MaxSpeed.java b/services-directions/src/main/java/com/mapbox/api/directions/v5/models/MaxSpeed.java index 0a2bc8f4d..9a7542881 100644 --- a/services-directions/src/main/java/com/mapbox/api/directions/v5/models/MaxSpeed.java +++ b/services-directions/src/main/java/com/mapbox/api/directions/v5/models/MaxSpeed.java @@ -54,7 +54,7 @@ public abstract class MaxSpeed implements Serializable { * @return the type adapter for this class * @since 3.0.0 */ - public static TypeAdapter typeAdapter(Gson gson) { + public static TypeAdapter typeAdapter(Gson gson) { return new AutoValue_MaxSpeed.GsonTypeAdapter(gson); } From aa696f6c3a78b93c773f6adca7c4c0ed75a959e5 Mon Sep 17 00:00:00 2001 From: danesfeder Date: Wed, 28 Mar 2018 09:39:15 -0400 Subject: [PATCH 5/9] Add builder --- .../com/mapbox/api/directions/v5/models/MaxSpeed.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/services-directions/src/main/java/com/mapbox/api/directions/v5/models/MaxSpeed.java b/services-directions/src/main/java/com/mapbox/api/directions/v5/models/MaxSpeed.java index 9a7542881..95f8ed4e3 100644 --- a/services-directions/src/main/java/com/mapbox/api/directions/v5/models/MaxSpeed.java +++ b/services-directions/src/main/java/com/mapbox/api/directions/v5/models/MaxSpeed.java @@ -11,6 +11,16 @@ @AutoValue public abstract class MaxSpeed implements Serializable { + /** + * Create a new instance of this class by using the {@link Builder} class. + * + * @return {@link Builder} for creating a new instance + * @since 3.0.0 + */ + public static Builder builder() { + return new AutoValue_MaxSpeed.Builder(); + } + /** * Number indicating the posted speed limit. * From 9e28d3722dc9e2db10aae1984ebe85c785dbc442 Mon Sep 17 00:00:00 2001 From: danesfeder Date: Wed, 28 Mar 2018 09:47:38 -0400 Subject: [PATCH 6/9] Add model tests --- .../directions/v5/models/MaxSpeedTest.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 services-directions/src/test/java/com/mapbox/api/directions/v5/models/MaxSpeedTest.java diff --git a/services-directions/src/test/java/com/mapbox/api/directions/v5/models/MaxSpeedTest.java b/services-directions/src/test/java/com/mapbox/api/directions/v5/models/MaxSpeedTest.java new file mode 100644 index 000000000..ba7576e88 --- /dev/null +++ b/services-directions/src/test/java/com/mapbox/api/directions/v5/models/MaxSpeedTest.java @@ -0,0 +1,29 @@ +package com.mapbox.api.directions.v5.models; + +import com.mapbox.core.TestUtils; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +public class MaxSpeedTest extends TestUtils { + + @Test + public void sanity() throws Exception { + MaxSpeed maxSpeed = MaxSpeed.builder() + .speed(65) + .unit("mph") + .build(); + assertNotNull(maxSpeed); + } + + @Test + public void testSerializable() throws Exception { + MaxSpeed maxSpeed = MaxSpeed.builder() + .unknown(true) + .build(); + byte[] serialized = TestUtils.serialize(maxSpeed); + assertEquals(maxSpeed, deserialize(serialized, MaxSpeed.class)); + } +} From 77104686472256ebdf65f6d423605317c712cb35 Mon Sep 17 00:00:00 2001 From: danesfeder Date: Wed, 28 Mar 2018 09:56:20 -0400 Subject: [PATCH 7/9] Add missing maxspeed builder --- .../api/directions/v5/models/LegAnnotation.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/services-directions/src/main/java/com/mapbox/api/directions/v5/models/LegAnnotation.java b/services-directions/src/main/java/com/mapbox/api/directions/v5/models/LegAnnotation.java index 3add5c988..ed8f5b314 100644 --- a/services-directions/src/main/java/com/mapbox/api/directions/v5/models/LegAnnotation.java +++ b/services-directions/src/main/java/com/mapbox/api/directions/v5/models/LegAnnotation.java @@ -129,6 +129,17 @@ public abstract static class Builder { */ public abstract Builder speed(@Nullable List speed); + /** + * The posted speed limit, between each pair of coordinates. + * Maxspeed is only available for the `mapbox/driving` and `mapbox/driving-traffic` + * profiles, other profiles will return `unknown`s only. + * + * @param maxSpeed list of speeds between each pair of coordinates + * @return this builder for chaining options together + * @since 3.0.0 + */ + public abstract Builder maxSpeed(@Nullable List maxSpeed); + /** * The congestion between each pair of coordinates. * From 50d7425f8a6558a386c5a5c33ccebf4797ead361 Mon Sep 17 00:00:00 2001 From: danesfeder Date: Wed, 28 Mar 2018 10:14:26 -0400 Subject: [PATCH 8/9] Add missing javadoc --- .../java/com/mapbox/api/directions/v5/models/MaxSpeed.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/services-directions/src/main/java/com/mapbox/api/directions/v5/models/MaxSpeed.java b/services-directions/src/main/java/com/mapbox/api/directions/v5/models/MaxSpeed.java index 95f8ed4e3..6776a7ce6 100644 --- a/services-directions/src/main/java/com/mapbox/api/directions/v5/models/MaxSpeed.java +++ b/services-directions/src/main/java/com/mapbox/api/directions/v5/models/MaxSpeed.java @@ -8,6 +8,11 @@ import java.io.Serializable; +/** + * Object representing max speeds along a route. + * + * @since 3.0.0 + */ @AutoValue public abstract class MaxSpeed implements Serializable { From a2b2ddc80f0c31e9a5b71ada690fbe7618d9674c Mon Sep 17 00:00:00 2001 From: danesfeder Date: Wed, 28 Mar 2018 10:26:47 -0400 Subject: [PATCH 9/9] Adjust doc line length --- .../com/mapbox/api/directions/v5/models/LegAnnotation.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services-directions/src/main/java/com/mapbox/api/directions/v5/models/LegAnnotation.java b/services-directions/src/main/java/com/mapbox/api/directions/v5/models/LegAnnotation.java index ed8f5b314..800c8a6a1 100644 --- a/services-directions/src/main/java/com/mapbox/api/directions/v5/models/LegAnnotation.java +++ b/services-directions/src/main/java/com/mapbox/api/directions/v5/models/LegAnnotation.java @@ -63,8 +63,8 @@ public static Builder builder() { * Maxspeed is only available for the `mapbox/driving` and `mapbox/driving-traffic` * profiles, other profiles will return `unknown`s only. * - * @return a list with each entry being a {@link MaxSpeed} value between two of the routeLeg geometry - * coordinates + * @return a list with each entry being a {@link MaxSpeed} value between two of + * the routeLeg geometry coordinates * @since 3.0.0 */ @Nullable