Skip to content

Commit bc21013

Browse files
committed
add speedlimitunit and speedlimitsign to legstep
1 parent defecb9 commit bc21013

6 files changed

Lines changed: 124 additions & 2 deletions

File tree

services-directions-models/src/main/java/com/mapbox/api/directions/v5/models/LegStep.java

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33
import androidx.annotation.NonNull;
44
import androidx.annotation.Nullable;
55

6+
import androidx.annotation.StringDef;
67
import com.google.auto.value.AutoValue;
78
import com.google.gson.Gson;
89
import com.google.gson.GsonBuilder;
910
import com.google.gson.TypeAdapter;
1011
import com.google.gson.annotations.SerializedName;
1112
import com.mapbox.api.directions.v5.DirectionsAdapterFactory;
1213

14+
import java.lang.annotation.Retention;
15+
import java.lang.annotation.RetentionPolicy;
1316
import java.util.List;
1417

1518
/**
@@ -20,6 +23,27 @@
2023
@AutoValue
2124
public abstract class LegStep extends DirectionsJsonObject {
2225

26+
/**
27+
* {@link LegStep.SpeedLimitSign} accident.
28+
*/
29+
public static final String MUTCD = "mutcd";
30+
31+
/**
32+
* {@link LegStep.SpeedLimitSign} congestion.
33+
*/
34+
public static final String VIENNA = "vienna";
35+
36+
/**
37+
* Speed limit sign.
38+
*/
39+
@Retention(RetentionPolicy.SOURCE)
40+
@StringDef({
41+
MUTCD,
42+
VIENNA
43+
})
44+
public @interface SpeedLimitSign {
45+
}
46+
2347
/**
2448
* Create a new instance of this class by using the {@link Builder} class.
2549
*
@@ -59,6 +83,24 @@ public static Builder builder() {
5983
@SerializedName("duration_typical")
6084
public abstract Double durationTypical();
6185

86+
/**
87+
* Speed limit unit as per the locale.
88+
*
89+
* @return unit of the speed limit
90+
*/
91+
@Nullable
92+
@SpeedLimit.Unit
93+
public abstract String speedLimitUnit();
94+
95+
/**
96+
* Speed limit sign type.
97+
*
98+
* @see LegStep.SpeedLimitSign
99+
*/
100+
@Nullable
101+
@LegStep.SpeedLimitSign
102+
public abstract String speedLimitSign();
103+
62104
/**
63105
* Gives the geometry of the leg step.
64106
*
@@ -288,6 +330,24 @@ public abstract static class Builder {
288330
*/
289331
public abstract Builder durationTypical(@Nullable Double durationTypical);
290332

333+
/**
334+
* Speed limit unit as per the locale.
335+
*
336+
* @param speedLimitUnit speed limit unit
337+
* @return this builder for chaining options together
338+
* @see SpeedLimit.Unit
339+
*/
340+
public abstract Builder speedLimitUnit(@Nullable @SpeedLimit.Unit String speedLimitUnit);
341+
342+
/**
343+
* Speed limit sign type.
344+
*
345+
* @param speedLimitSign speed limit sign
346+
* @return this builder for chaining options together
347+
* @see SpeedLimitSign
348+
*/
349+
public abstract Builder speedLimitSign(@Nullable @SpeedLimitSign String speedLimitSign);
350+
291351
/**
292352
* Gives the geometry of the leg step.
293353
*

services-directions-models/src/main/java/com/mapbox/api/directions/v5/models/MaxSpeed.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import com.google.gson.TypeAdapter;
99
import com.mapbox.api.directions.v5.DirectionsAdapterFactory;
1010

11-
1211
/**
1312
* Object representing max speeds along a route.
1413
*
@@ -43,6 +42,7 @@ public static Builder builder() {
4342
* @since 3.0.0
4443
*/
4544
@Nullable
45+
@SpeedLimit.Unit
4646
public abstract String unit();
4747

4848
/**
@@ -124,7 +124,7 @@ public abstract static class Builder {
124124
* @return a {@link Builder} object
125125
* @since 3.0.0
126126
*/
127-
public abstract Builder unit(@Nullable String unit);
127+
public abstract Builder unit(@Nullable @SpeedLimit.Unit String unit);
128128

129129
/**
130130
* Boolean is true if the speed limit is not known, otherwise null.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.mapbox.api.directions.v5.models;
2+
3+
import androidx.annotation.StringDef;
4+
5+
import java.lang.annotation.Retention;
6+
import java.lang.annotation.RetentionPolicy;
7+
8+
/**
9+
* The file exposes speed limit annotations.
10+
*/
11+
public class SpeedLimit {
12+
/**
13+
* Speed limit unit in km/h.
14+
*/
15+
public static final String KMPH = "km/h";
16+
17+
/**
18+
* Speed limit unit in mph.
19+
*/
20+
public static final String MPH = "mph";
21+
22+
/**
23+
* Speed limit unit.
24+
*/
25+
@Retention(RetentionPolicy.SOURCE)
26+
@StringDef({
27+
MPH,
28+
KMPH
29+
})
30+
public @interface Unit {
31+
}
32+
}

services-directions-models/src/test/java/com/mapbox/api/directions/v5/models/LegStepTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ public void testToFromJson3() {
7575
.modifier("left")
7676
.instruction("Turn left onto Adalbertstraße")
7777
.build())
78+
.speedLimitUnit("mph")
79+
.speedLimitSign(LegStep.MUTCD)
7880
.intersections(intersections)
7981
.voiceInstructions(voiceInstructions)
8082
.bannerInstructions(bannerInstructions)

services-directions/src/test/java/com/mapbox/api/directions/v5/MapboxDirectionsTest.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public class MapboxDirectionsTest extends TestUtils {
5656
private static final String DIRECTIONS_ROTARY_FIXTURE = "directions_v5_fixtures_rotary.json";
5757
private static final String DIRECTIONS_V5_ANNOTATIONS_FIXTURE = "directions_annotations_v5.json";
5858
private static final String DIRECTIONS_V5_NO_ROUTE = "directions_v5_no_route.json";
59+
private static final String DIRECTIONS_V5_SPEED_LIMIT = "directions_v5_speedlimit.json";
5960
private static final String DIRECTIONS_V5_MAX_SPEED_ANNOTATION = "directions_v5_max_speed_annotation.json";
6061
private static final String DIRECTIONS_V5_BANNER_INSTRUCTIONS = "directions_v5_banner_instructions.json";
6162
private static final String DIRECTIONS_V5_APPROACHES_REQUEST = "directions_v5_approaches.json";
@@ -789,6 +790,32 @@ public void maxSpeedAnnotation_doesGetCreatedInResponse() throws IOException {
789790
assertNotNull(maxSpeedAnnotation.maxspeed());
790791
}
791792

793+
@Test
794+
public void speedLimit_doesUnitGetCreatedInResponse() throws IOException {
795+
Gson gson = new GsonBuilder()
796+
.registerTypeAdapterFactory(DirectionsAdapterFactory.create()).create();
797+
String body = loadJsonFixture(DIRECTIONS_V5_SPEED_LIMIT);
798+
DirectionsResponse response = gson.fromJson(body, DirectionsResponse.class);
799+
DirectionsRoute speedLimitRoute = response.routes().get(0);
800+
String speedLimitSign = speedLimitRoute.legs().get(0).steps().get(0).speedLimitSign();
801+
String speedLimitUnit = speedLimitRoute.legs().get(0).steps().get(0).speedLimitUnit();
802+
803+
assertEquals("mph", speedLimitUnit);
804+
}
805+
806+
@Test
807+
public void speedLimit_doesSignGetCreatedInResponse() throws IOException {
808+
Gson gson = new GsonBuilder()
809+
.registerTypeAdapterFactory(DirectionsAdapterFactory.create()).create();
810+
String body = loadJsonFixture(DIRECTIONS_V5_SPEED_LIMIT);
811+
DirectionsResponse response = gson.fromJson(body, DirectionsResponse.class);
812+
DirectionsRoute speedLimitRoute = response.routes().get(0);
813+
String speedLimitSign = speedLimitRoute.legs().get(0).steps().get(0).speedLimitSign();
814+
String speedLimitUnit = speedLimitRoute.legs().get(0).steps().get(0).speedLimitUnit();
815+
816+
assertEquals("mutcd", speedLimitSign);
817+
}
818+
792819
@Test
793820
public void subBannerInstructions() throws Exception {
794821
Gson gson = new GsonBuilder()

services-directions/src/test/resources/directions_v5_speedlimit.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)