From c94465f4ad12eea8f47ef4ff38f975424526a7f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Paczos?= Date: Mon, 23 Nov 2020 15:07:44 +0100 Subject: [PATCH] expose `active` and `validIndications` lane information --- .../v5/models/IntersectionLanes.java | 45 +++++++++++++++++++ .../v5/models/IntersectionLanesTest.java | 37 +++++++++++++-- 2 files changed, 78 insertions(+), 4 deletions(-) diff --git a/services-directions-models/src/main/java/com/mapbox/api/directions/v5/models/IntersectionLanes.java b/services-directions-models/src/main/java/com/mapbox/api/directions/v5/models/IntersectionLanes.java index f60063963..a73067f86 100644 --- a/services-directions-models/src/main/java/com/mapbox/api/directions/v5/models/IntersectionLanes.java +++ b/services-directions-models/src/main/java/com/mapbox/api/directions/v5/models/IntersectionLanes.java @@ -5,6 +5,7 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.TypeAdapter; +import com.google.gson.annotations.SerializedName; import com.mapbox.api.directions.v5.DirectionsAdapterFactory; import java.util.List; @@ -39,6 +40,33 @@ public static Builder builder() { @Nullable public abstract Boolean valid(); + /** + * Indicates whether this lane is a preferred lane (true) or not (false). + * A preferred lane is a lane that is recommended if there are multiple lanes available. + * For example, if guidance indicates that the driver must turn left at an intersection and there are multiple + * left turn lanes, the left turn lane that will better prepare the driver for the next maneuver + * will be marked as active. + * Only available on the mapbox/driving profile. + * + * @return Indicates whether this lane is a preferred lane (true) or not (false). + */ + @Nullable + public abstract Boolean active(); + + /** + * When either valid or active is set to true, this property shows which of the lane indications is applicable + * to the current route, when there is more than one. For example, if a lane allows you to go left or straight + * but your current route is guiding you to the left, then this value will be set to left. + * See indications for possible values. + * When both active and valid are false, this property will not be included in the response. + * Only available on the mapbox/driving profile. + * + * @return Array of which of the lane indications is applicable to the current route, when there is more than one + */ + @Nullable + @SerializedName("valid_indication") + public abstract List validIndications(); + /** * Array that can be made up of multiple signs such as {@code left}, {@code right}, etc. * @@ -106,6 +134,23 @@ public abstract static class Builder { */ public abstract Builder valid(@Nullable Boolean valid); + /** + * Indicates whether this lane is a preferred lane (true) or not (false). + * + * @param active Boolean value that indicates whether this lane is a preferred lane (true) or not (false). + * @return this builder for chaining options together + */ + public abstract Builder active(@Nullable Boolean active); + + /** + * Shows which of the lane indications is applicable to the current route, when there is more than one. + * + * @param validIndications list of lane indications that are applicable to the current route, + * when there is more than one. + * @return this builder for chaining options together + */ + public abstract Builder validIndications(@Nullable List validIndications); + /** * list that can be made up of multiple signs such as {@code left}, {@code right}, etc. * diff --git a/services-directions-models/src/test/java/com/mapbox/api/directions/v5/models/IntersectionLanesTest.java b/services-directions-models/src/test/java/com/mapbox/api/directions/v5/models/IntersectionLanesTest.java index d4ef42aeb..1c773f721 100644 --- a/services-directions-models/src/test/java/com/mapbox/api/directions/v5/models/IntersectionLanesTest.java +++ b/services-directions-models/src/test/java/com/mapbox/api/directions/v5/models/IntersectionLanesTest.java @@ -8,6 +8,7 @@ import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; public class IntersectionLanesTest extends TestUtils { @@ -21,20 +22,24 @@ public void sanity() throws Exception { } @Test - public void testSerializable() throws Exception { + public void testSerializableRoundTripping() throws Exception { IntersectionLanes intersectionLanes = IntersectionLanes.builder() - .indications(new ArrayList()) .valid(true) + .active(true) + .validIndications(Collections.singletonList("straight")) + .indications(Arrays.asList("straight","slight left")) .build(); byte[] serialized = TestUtils.serialize(intersectionLanes); assertEquals(intersectionLanes, deserialize(serialized, IntersectionLanes.class)); } @Test - public void testToFromJson() { + public void testJsonRoundTripping() { IntersectionLanes intersectionLanes = IntersectionLanes.builder() - .indications(Arrays.asList("straight","slight left")) .valid(true) + .active(true) + .validIndications(Collections.singletonList("straight")) + .indications(Arrays.asList("straight","slight left")) .build(); String jsonString = intersectionLanes.toJson(); @@ -42,4 +47,28 @@ public void testToFromJson() { assertEquals(intersectionLanes, intersectionLanesFromJson); } + + @Test + public void testFromJson_active() { + IntersectionLanes intersectionLanes = IntersectionLanes.builder() + .active(true) + .build(); + + String jsonString = "{\"active\":true}"; + IntersectionLanes intersectionLanesFromJson = IntersectionLanes.fromJson(jsonString); + + assertEquals(intersectionLanes, intersectionLanesFromJson); + } + + @Test + public void testFromJson_validIndications() { + IntersectionLanes intersectionLanes = IntersectionLanes.builder() + .validIndications(Collections.singletonList("straight")) + .build(); + + String jsonString = "{\"valid_indication\":[\"straight\"]}"; + IntersectionLanes intersectionLanesFromJson = IntersectionLanes.fromJson(jsonString); + + assertEquals(intersectionLanes, intersectionLanesFromJson); + } }