Skip to content

Commit

Permalink
expose active and validIndications lane information
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasPaczos committed Nov 23, 2020
1 parent bc21013 commit c94465f
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> validIndications();

/**
* Array that can be made up of multiple signs such as {@code left}, {@code right}, etc.
*
Expand Down Expand Up @@ -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<String> validIndications);

/**
* list that can be made up of multiple signs such as {@code left}, {@code right}, etc.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;

public class IntersectionLanesTest extends TestUtils {

Expand All @@ -21,25 +22,53 @@ public void sanity() throws Exception {
}

@Test
public void testSerializable() throws Exception {
public void testSerializableRoundTripping() throws Exception {
IntersectionLanes intersectionLanes = IntersectionLanes.builder()
.indications(new ArrayList<String>())
.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();
IntersectionLanes intersectionLanesFromJson = IntersectionLanes.fromJson(jsonString);

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

0 comments on commit c94465f

Please sign in to comment.