Skip to content

Commit

Permalink
add speedlimitunit and speedlimitsign to legstep
Browse files Browse the repository at this point in the history
  • Loading branch information
abhishek1508 committed Oct 23, 2020
1 parent defecb9 commit bc21013
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import androidx.annotation.StringDef;
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.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.List;

/**
Expand All @@ -20,6 +23,27 @@
@AutoValue
public abstract class LegStep extends DirectionsJsonObject {

/**
* {@link LegStep.SpeedLimitSign} accident.
*/
public static final String MUTCD = "mutcd";

/**
* {@link LegStep.SpeedLimitSign} congestion.
*/
public static final String VIENNA = "vienna";

/**
* Speed limit sign.
*/
@Retention(RetentionPolicy.SOURCE)
@StringDef({
MUTCD,
VIENNA
})
public @interface SpeedLimitSign {
}

/**
* Create a new instance of this class by using the {@link Builder} class.
*
Expand Down Expand Up @@ -59,6 +83,24 @@ public static Builder builder() {
@SerializedName("duration_typical")
public abstract Double durationTypical();

/**
* Speed limit unit as per the locale.
*
* @return unit of the speed limit
*/
@Nullable
@SpeedLimit.Unit
public abstract String speedLimitUnit();

/**
* Speed limit sign type.
*
* @see LegStep.SpeedLimitSign
*/
@Nullable
@LegStep.SpeedLimitSign
public abstract String speedLimitSign();

/**
* Gives the geometry of the leg step.
*
Expand Down Expand Up @@ -288,6 +330,24 @@ public abstract static class Builder {
*/
public abstract Builder durationTypical(@Nullable Double durationTypical);

/**
* Speed limit unit as per the locale.
*
* @param speedLimitUnit speed limit unit
* @return this builder for chaining options together
* @see SpeedLimit.Unit
*/
public abstract Builder speedLimitUnit(@Nullable @SpeedLimit.Unit String speedLimitUnit);

/**
* Speed limit sign type.
*
* @param speedLimitSign speed limit sign
* @return this builder for chaining options together
* @see SpeedLimitSign
*/
public abstract Builder speedLimitSign(@Nullable @SpeedLimitSign String speedLimitSign);

/**
* Gives the geometry of the leg step.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.google.gson.TypeAdapter;
import com.mapbox.api.directions.v5.DirectionsAdapterFactory;


/**
* Object representing max speeds along a route.
*
Expand Down Expand Up @@ -43,6 +42,7 @@ public static Builder builder() {
* @since 3.0.0
*/
@Nullable
@SpeedLimit.Unit
public abstract String unit();

/**
Expand Down Expand Up @@ -124,7 +124,7 @@ public abstract static class Builder {
* @return a {@link Builder} object
* @since 3.0.0
*/
public abstract Builder unit(@Nullable String unit);
public abstract Builder unit(@Nullable @SpeedLimit.Unit String unit);

/**
* Boolean is true if the speed limit is not known, otherwise null.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.mapbox.api.directions.v5.models;

import androidx.annotation.StringDef;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
* The file exposes speed limit annotations.
*/
public class SpeedLimit {
/**
* Speed limit unit in km/h.
*/
public static final String KMPH = "km/h";

/**
* Speed limit unit in mph.
*/
public static final String MPH = "mph";

/**
* Speed limit unit.
*/
@Retention(RetentionPolicy.SOURCE)
@StringDef({
MPH,
KMPH
})
public @interface Unit {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public void testToFromJson3() {
.modifier("left")
.instruction("Turn left onto Adalbertstraße")
.build())
.speedLimitUnit("mph")
.speedLimitSign(LegStep.MUTCD)
.intersections(intersections)
.voiceInstructions(voiceInstructions)
.bannerInstructions(bannerInstructions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public class MapboxDirectionsTest extends TestUtils {
private static final String DIRECTIONS_ROTARY_FIXTURE = "directions_v5_fixtures_rotary.json";
private static final String DIRECTIONS_V5_ANNOTATIONS_FIXTURE = "directions_annotations_v5.json";
private static final String DIRECTIONS_V5_NO_ROUTE = "directions_v5_no_route.json";
private static final String DIRECTIONS_V5_SPEED_LIMIT = "directions_v5_speedlimit.json";
private static final String DIRECTIONS_V5_MAX_SPEED_ANNOTATION = "directions_v5_max_speed_annotation.json";
private static final String DIRECTIONS_V5_BANNER_INSTRUCTIONS = "directions_v5_banner_instructions.json";
private static final String DIRECTIONS_V5_APPROACHES_REQUEST = "directions_v5_approaches.json";
Expand Down Expand Up @@ -789,6 +790,32 @@ public void maxSpeedAnnotation_doesGetCreatedInResponse() throws IOException {
assertNotNull(maxSpeedAnnotation.maxspeed());
}

@Test
public void speedLimit_doesUnitGetCreatedInResponse() throws IOException {
Gson gson = new GsonBuilder()
.registerTypeAdapterFactory(DirectionsAdapterFactory.create()).create();
String body = loadJsonFixture(DIRECTIONS_V5_SPEED_LIMIT);
DirectionsResponse response = gson.fromJson(body, DirectionsResponse.class);
DirectionsRoute speedLimitRoute = response.routes().get(0);
String speedLimitSign = speedLimitRoute.legs().get(0).steps().get(0).speedLimitSign();
String speedLimitUnit = speedLimitRoute.legs().get(0).steps().get(0).speedLimitUnit();

assertEquals("mph", speedLimitUnit);
}

@Test
public void speedLimit_doesSignGetCreatedInResponse() throws IOException {
Gson gson = new GsonBuilder()
.registerTypeAdapterFactory(DirectionsAdapterFactory.create()).create();
String body = loadJsonFixture(DIRECTIONS_V5_SPEED_LIMIT);
DirectionsResponse response = gson.fromJson(body, DirectionsResponse.class);
DirectionsRoute speedLimitRoute = response.routes().get(0);
String speedLimitSign = speedLimitRoute.legs().get(0).steps().get(0).speedLimitSign();
String speedLimitUnit = speedLimitRoute.legs().get(0).steps().get(0).speedLimitUnit();

assertEquals("mutcd", speedLimitSign);
}

@Test
public void subBannerInstructions() throws Exception {
Gson gson = new GsonBuilder()
Expand Down

Large diffs are not rendered by default.

0 comments on commit bc21013

Please sign in to comment.