Skip to content

Commit 5988a03

Browse files
authored
MapboxStreetsV8 and isUrban fields (#1182)
1 parent 21a4873 commit 5988a03

4 files changed

Lines changed: 202 additions & 2 deletions

File tree

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package com.mapbox.api.directions.v5.models;
2+
3+
import androidx.annotation.Nullable;
4+
import com.google.auto.value.AutoValue;
5+
import com.google.gson.Gson;
6+
import com.google.gson.GsonBuilder;
7+
import com.google.gson.TypeAdapter;
8+
import com.google.gson.annotations.SerializedName;
9+
import com.mapbox.api.directions.v5.DirectionsAdapterFactory;
10+
import com.mapbox.api.directions.v5.DirectionsCriteria;
11+
12+
/**
13+
* An object containing detailed information about the road exiting the intersection along the
14+
* route.
15+
* Only available on the {@link DirectionsCriteria#PROFILE_DRIVING} profile.
16+
*/
17+
@AutoValue
18+
public abstract class MapboxStreetsV8 extends DirectionsJsonObject {
19+
20+
/**
21+
* Class of the road exiting the intersection.
22+
*
23+
* @return class of the road.
24+
*/
25+
@Nullable
26+
@SerializedName("class")
27+
public abstract String roadClass();
28+
29+
/**
30+
* Create a new instance of this class by using the {@link Builder} class.
31+
*
32+
* @return this classes {@link Builder} for creating a new instance
33+
*/
34+
public static Builder builder() {
35+
return new AutoValue_MapboxStreetsV8.Builder();
36+
}
37+
38+
/**
39+
* Convert the current {@link MapboxStreetsV8} to its builder holding the currently assigned
40+
* values. This allows you to modify a single property and then rebuild the object resulting in
41+
* an updated and modified {@link MapboxStreetsV8}.
42+
*
43+
* @return a {@link Builder} with the same values set to match the ones defined in this {@link
44+
* MapboxStreetsV8}
45+
*/
46+
public abstract Builder toBuilder();
47+
48+
/**
49+
* Gson type adapter for parsing Gson to this class.
50+
*
51+
* @param gson the built {@link Gson} object
52+
* @return the type adapter for this class
53+
*/
54+
public static TypeAdapter<MapboxStreetsV8> typeAdapter(Gson gson) {
55+
return new AutoValue_MapboxStreetsV8.GsonTypeAdapter(gson);
56+
}
57+
58+
/**
59+
* Create a new instance of this class by passing in a formatted valid JSON String.
60+
*
61+
* @param json a formatted valid JSON string defining an Incident
62+
* @return a new instance of this class defined by the values passed in the method
63+
*/
64+
public static MapboxStreetsV8 fromJson(String json) {
65+
GsonBuilder gson = new GsonBuilder();
66+
gson.registerTypeAdapterFactory(DirectionsAdapterFactory.create());
67+
return gson.create().fromJson(json, MapboxStreetsV8.class);
68+
}
69+
70+
/**
71+
* This builder can be used to set the values describing the {@link MapboxStreetsV8}.
72+
*/
73+
@AutoValue.Builder
74+
public abstract static class Builder {
75+
76+
/**
77+
* Class of the road exiting the intersection.
78+
*
79+
* @param roadClass class of the road exiting the intersection.
80+
* @return this builder for chaining options together
81+
*/
82+
public abstract Builder roadClass(@Nullable String roadClass);
83+
84+
/**
85+
* Build a new {@link MapboxStreetsV8} object.
86+
*
87+
* @return a new {@link MapboxStreetsV8} using the provided values in this builder
88+
*/
89+
public abstract MapboxStreetsV8 build();
90+
}
91+
}

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

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.google.gson.TypeAdapter;
99
import com.google.gson.annotations.SerializedName;
1010
import com.mapbox.api.directions.v5.DirectionsAdapterFactory;
11+
import com.mapbox.api.directions.v5.DirectionsCriteria;
1112
import com.mapbox.geojson.Point;
1213

1314
import java.util.List;
@@ -146,6 +147,28 @@ public Point location() {
146147
@SerializedName("geometry_index")
147148
public abstract Integer geometryIndex();
148149

150+
/**
151+
* A boolean indicating whether the road exiting the intersection is considered to be in an urban
152+
* area. This value is determined by the density of the surrounding road network.
153+
* Only available on the {@link DirectionsCriteria#PROFILE_DRIVING} profile.
154+
*
155+
* @return a value indicating whether the road exiting the intersection is in an urban area
156+
*/
157+
@Nullable
158+
@SerializedName("is_urban")
159+
public abstract Boolean isUrban();
160+
161+
/**
162+
* An object containing detailed information about the road exiting the intersection along the
163+
* route. Properties in this object correspond to properties in the {@link #classes()}
164+
* specification. Only available on the {@link DirectionsCriteria#PROFILE_DRIVING} profile.
165+
*
166+
* @return an object containing detailed road information.
167+
*/
168+
@Nullable
169+
@SerializedName("mapbox_streets_v8")
170+
public abstract MapboxStreetsV8 mapboxStreetsV8();
171+
149172
/**
150173
* Convert the current {@link StepIntersection} to its builder holding the currently assigned
151174
* values. This allows you to modify a single property and then rebuild the object resulting in
@@ -284,6 +307,28 @@ public abstract static class Builder {
284307
*/
285308
public abstract Builder geometryIndex(@Nullable Integer geometryIndex);
286309

310+
/**
311+
* A boolean indicating whether the road exiting the intersection is considered to be in an
312+
* urban area. This value is determined by the density of the surrounding road network.
313+
* Only available on the {@link DirectionsCriteria#PROFILE_DRIVING} profile.
314+
*
315+
* @param isUrban indicating whether the road exiting the intersection is in an urban area
316+
* @return this builder for chaining options together
317+
*/
318+
@Nullable
319+
public abstract Builder isUrban(@Nullable Boolean isUrban);
320+
321+
/**
322+
* An object containing detailed information about the road exiting the intersection along the
323+
* route. Properties in this object correspond to properties in the {@link #classes()}
324+
* specification. Only available on the {@link DirectionsCriteria#PROFILE_DRIVING} profile.
325+
*
326+
* @param street an object containing detailed road information.
327+
* @return this builder for chaining options together
328+
*/
329+
@Nullable
330+
public abstract Builder mapboxStreetsV8(@Nullable MapboxStreetsV8 street);
331+
287332
/**
288333
* The rawLocation as a double array. Once the {@link StepIntersection} object's created,
289334
* this raw location gets converted into a {@link Point} object and is public exposed as such.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.mapbox.api.directions.v5.models;
2+
3+
import com.mapbox.core.TestUtils;
4+
import org.junit.Assert;
5+
import org.junit.Test;
6+
7+
import static junit.framework.TestCase.assertEquals;
8+
import static org.junit.Assert.assertNotNull;
9+
10+
11+
public class MapboxStreetsV8Test extends TestUtils {
12+
@Test
13+
public void sanity() {
14+
assertNotNull(buildDefaultStreet());
15+
}
16+
17+
@Test
18+
public void testSerializable() throws Exception {
19+
MapboxStreetsV8 street = buildDefaultStreet();
20+
byte[] serialized = TestUtils.serialize(street);
21+
assertEquals(street, deserialize(serialized, MapboxStreetsV8.class));
22+
}
23+
24+
@Test
25+
public void testFromJson() {
26+
String streetJsonString = "{"
27+
+ "\"class\": \"street\""
28+
+ "}";
29+
30+
MapboxStreetsV8 street = MapboxStreetsV8.fromJson(streetJsonString);
31+
Assert.assertEquals("street", street.roadClass());
32+
33+
String jsonStr = street.toJson();
34+
compareJson(streetJsonString, jsonStr);
35+
}
36+
37+
@Test
38+
public void testToFromJson() {
39+
MapboxStreetsV8 street = buildDefaultStreet();
40+
41+
String jsonString = street.toJson();
42+
MapboxStreetsV8 streetFromJson = MapboxStreetsV8.fromJson(jsonString);
43+
44+
Assert.assertEquals(street, streetFromJson);
45+
}
46+
47+
private MapboxStreetsV8 buildDefaultStreet() {
48+
return MapboxStreetsV8.builder()
49+
.roadClass("street")
50+
.build();
51+
}
52+
}

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import static junit.framework.TestCase.assertEquals;
44
import static org.junit.Assert.assertNotNull;
5+
import static org.junit.Assert.assertTrue;
56

67
import com.mapbox.core.TestUtils;
78
import com.mapbox.geojson.Point;
@@ -45,6 +46,8 @@ public void testToFromJson1() {
4546
.rawLocation(new double[]{13.426579, 52.508068})
4647
.tunnelName("test tunnel")
4748
.geometryIndex(123)
49+
.isUrban(true)
50+
.mapboxStreetsV8(MapboxStreetsV8.builder().roadClass("street").build())
4851
.build();
4952

5053
String jsonString = intersection.toJson();
@@ -62,6 +65,7 @@ public void testToFromJson2() {
6265
.bearings(Arrays.asList(120, 210, 300))
6366
.rawLocation(new double[]{13.424671, 52.508812})
6467
.tunnelName("test tunnel")
68+
.mapboxStreetsV8(MapboxStreetsV8.builder().roadClass("street").build())
6569
.build();
6670

6771
String jsonString = intersection.toJson();
@@ -73,14 +77,22 @@ public void testToFromJson2() {
7377

7478
@Test
7579
public void testFromJson() {
76-
String stepIntersectionJsonString = "{\"out\": 0, \"entry\": [true], \"bearings\": [ 125 ], "
80+
String stepIntersectionJsonString = "{"
81+
+ "\"location\": [ 13.426579, 52.508068 ],"
82+
+ "\"bearings\": [ 125 ], "
83+
+ "\"entry\": [true], "
84+
+ "\"out\": 0, "
7785
+ "\"tunnel_name\": \"test tunnel name\","
7886
+ "\"geometry_index\": 123,"
79-
+ "\"location\": [ 13.426579, 52.508068 ] }";
87+
+ "\"is_urban\": true,"
88+
+ "\"mapbox_streets_v8\": {\"class\": \"street\"}"
89+
+ "}";
8090

8191
StepIntersection stepIntersection = StepIntersection.fromJson(stepIntersectionJsonString);
8292
Assert.assertEquals("test tunnel name", stepIntersection.tunnelName());
8393
Assert.assertEquals(123, stepIntersection.geometryIndex().intValue());
94+
assertTrue(stepIntersection.isUrban());
95+
assertEquals("street", stepIntersection.mapboxStreetsV8().roadClass());
8496

8597
Point location = stepIntersection.location();
8698
Assert.assertEquals(13.426579, location.longitude(), 0.0001);

0 commit comments

Comments
 (0)