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

expose active and validIndications lane information #1217

Merged
merged 1 commit into from
Nov 23, 2020
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,10 +1,12 @@
package com.mapbox.api.directions.v5.models;

import androidx.annotation.Nullable;

import com.google.auto.value.AutoValue;
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 +41,35 @@ 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 +137,25 @@ 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 {
Copy link
Contributor

Choose a reason for hiding this comment

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

❤️

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() {
Copy link
Contributor

Choose a reason for hiding this comment

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

❤️

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