Skip to content

Commit ffa1dd4

Browse files
author
Łukasz Paczos
committed
expose rest stops
1 parent e58d1d6 commit ffa1dd4

4 files changed

Lines changed: 126 additions & 0 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
@AutoValue
1818
public abstract class MapboxStreetsV8 extends DirectionsJsonObject {
1919

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

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,16 @@ public Point location() {
161161
@SerializedName("admin_index")
162162
public abstract Integer adminIndex();
163163

164+
/**
165+
* An object containing information about passing rest stops along the route.
166+
* Only available on the `driving` profile.
167+
*
168+
* @return an object containing information about passing rest stops along the route.
169+
*/
170+
@Nullable
171+
@SerializedName("rest_stop")
172+
public abstract RestStop restStop();
173+
164174
/**
165175
* An object containing detailed information about the road exiting the intersection along the
166176
* route. Properties in this object correspond to properties in the {@link #classes()}
@@ -324,6 +334,16 @@ public abstract static class Builder {
324334
@Nullable
325335
public abstract Builder adminIndex(@Nullable Integer adminIndex);
326336

337+
/**
338+
* An object containing information about passing rest stops along the route.
339+
* Only available on the `driving` profile.
340+
*
341+
* @param restStop object containing information about passing rest stops along the route.
342+
* @return this builder for chaining options together
343+
*/
344+
@Nullable
345+
public abstract Builder restStop(@Nullable RestStop restStop);
346+
327347
/**
328348
* An object containing detailed information about the road exiting the intersection along the
329349
* route. Properties in this object correspond to properties in the {@link #classes()}

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public void testToFromJson1() {
4646
.rawLocation(new double[]{13.426579, 52.508068})
4747
.geometryIndex(123)
4848
.isUrban(true)
49+
.restStop(RestStop.builder().type("rest_area").build())
4950
.adminIndex(2)
5051
.mapboxStreetsV8(MapboxStreetsV8.builder().roadClass("street").build())
5152
.build();
@@ -113,4 +114,18 @@ public void testAdminIndex() {
113114
String jsonStr = stepIntersection.toJson();
114115
compareJson(stepIntersectionJsonString, jsonStr);
115116
}
117+
118+
@Test
119+
public void testRestStop() {
120+
String stepIntersectionJsonString = "{"
121+
+ "\"location\": [ 13.426579, 52.508068 ],"
122+
+ "\"rest_stop\": { \"type\": \"rest_area\" }"
123+
+ "}";
124+
125+
StepIntersection stepIntersection = StepIntersection.fromJson(stepIntersectionJsonString);
126+
127+
Assert.assertEquals("rest_area", stepIntersection.restStop().type());
128+
String jsonStr = stepIntersection.toJson();
129+
compareJson(stepIntersectionJsonString, jsonStr);
130+
}
116131
}

0 commit comments

Comments
 (0)