Skip to content

Commit 5cb6535

Browse files
author
Łukasz Paczos
committed
expose toll collection
1 parent ffa1dd4 commit 5cb6535

3 files changed

Lines changed: 135 additions & 0 deletions

File tree

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,20 @@ public Point location() {
171171
@SerializedName("rest_stop")
172172
public abstract RestStop restStop();
173173

174+
/**
175+
* An object containing information about a toll collection point along the route.
176+
* This is a payment booth or overhead electronic gantry
177+
* <a href="https://wiki.openstreetmap.org/wiki/Tag:barrier%3Dtoll_booth">
178+
* payment booth or overhead electronic gantry</a>
179+
* where toll charge is collected.
180+
* Only available on the {@link DirectionsCriteria#PROFILE_DRIVING} profile.
181+
*
182+
* @return an object containing information about a toll collection point along the route.
183+
*/
184+
@Nullable
185+
@SerializedName("toll_collection")
186+
public abstract TollCollection tollCollection();
187+
174188
/**
175189
* An object containing detailed information about the road exiting the intersection along the
176190
* route. Properties in this object correspond to properties in the {@link #classes()}
@@ -344,6 +358,20 @@ public abstract static class Builder {
344358
@Nullable
345359
public abstract Builder restStop(@Nullable RestStop restStop);
346360

361+
/**
362+
* An object containing information about a toll collection point along the route.
363+
* This is a payment booth or overhead electronic gantry
364+
* <a href="https://wiki.openstreetmap.org/wiki/Tag:barrier%3Dtoll_booth">
365+
* payment booth or overhead electronic gantry</a>
366+
* where toll charge is collected.
367+
*
368+
* @param tollCollection object containing information about
369+
* a toll collection point along the route.
370+
* @return this builder for chaining options together
371+
*/
372+
@Nullable
373+
public abstract Builder tollCollection(@Nullable TollCollection tollCollection);
374+
347375
/**
348376
* An object containing detailed information about the road exiting the intersection along the
349377
* route. Properties in this object correspond to properties in the {@link #classes()}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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 a toll collection point along the route.
14+
* This is a payment booth or overhead electronic gantry
15+
* <a href="https://wiki.openstreetmap.org/wiki/Tag:barrier%3Dtoll_booth">
16+
* payment booth or overhead electronic gantry</a>
17+
* where toll charge is collected.
18+
* Only available on the {@link DirectionsCriteria#PROFILE_DRIVING} profile.
19+
*/
20+
@AutoValue
21+
public abstract class TollCollection extends DirectionsJsonObject {
22+
23+
/**
24+
* The type of toll collection point, either `toll_booth` or `toll_gantry`.
25+
* Note that adding new possible types is not considered a breaking change.
26+
*/
27+
@Nullable
28+
public abstract String type();
29+
30+
/**
31+
* Create a new instance of this class by using the {@link Builder} class.
32+
*
33+
* @return this classes {@link Builder} for creating a new instance
34+
*/
35+
public static Builder builder() {
36+
return new AutoValue_TollCollection.Builder();
37+
}
38+
39+
/**
40+
* Convert the current {@link TollCollection} to its builder holding the currently assigned
41+
* values. This allows you to modify a single property and then rebuild the object resulting in
42+
* an updated and modified {@link TollCollection}.
43+
*
44+
* @return a {@link Builder} with the same values set to match the ones defined in this {@link
45+
* TollCollection}
46+
*/
47+
public abstract Builder toBuilder();
48+
49+
/**
50+
* Gson type adapter for parsing Gson to this class.
51+
*
52+
* @param gson the built {@link Gson} object
53+
* @return the type adapter for this class
54+
*/
55+
public static TypeAdapter<TollCollection> typeAdapter(Gson gson) {
56+
return new AutoValue_TollCollection.GsonTypeAdapter(gson);
57+
}
58+
59+
/**
60+
* Create a new instance of this class by passing in a formatted valid JSON String.
61+
*
62+
* @param json a formatted valid JSON string defining an Incident
63+
* @return a new instance of this class defined by the values passed in the method
64+
*/
65+
public static TollCollection fromJson(String json) {
66+
GsonBuilder gson = new GsonBuilder();
67+
gson.registerTypeAdapterFactory(DirectionsAdapterFactory.create());
68+
return gson.create().fromJson(json, TollCollection.class);
69+
}
70+
71+
/**
72+
* This builder can be used to set the values describing the {@link TollCollection}.
73+
*/
74+
@AutoValue.Builder
75+
public abstract static class Builder {
76+
77+
/**
78+
* The type of toll collection point, either `toll_booth` or `toll_gantry`.
79+
* Note that adding new possible types is not considered a breaking change.
80+
*
81+
* @param type toll collection type
82+
*/
83+
public abstract Builder type(@Nullable String type);
84+
85+
/**
86+
* Build a new {@link TollCollection} object.
87+
*
88+
* @return a new {@link TollCollection} using the provided values in this builder
89+
*/
90+
public abstract TollCollection build();
91+
}
92+
}

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
@@ -47,6 +47,7 @@ public void testToFromJson1() {
4747
.geometryIndex(123)
4848
.isUrban(true)
4949
.restStop(RestStop.builder().type("rest_area").build())
50+
.tollCollection(TollCollection.builder().type("toll_gantry").build())
5051
.adminIndex(2)
5152
.mapboxStreetsV8(MapboxStreetsV8.builder().roadClass("street").build())
5253
.build();
@@ -128,4 +129,18 @@ public void testRestStop() {
128129
String jsonStr = stepIntersection.toJson();
129130
compareJson(stepIntersectionJsonString, jsonStr);
130131
}
132+
133+
@Test
134+
public void testTollCollection() {
135+
String stepIntersectionJsonString = "{"
136+
+ "\"location\": [ 13.426579, 52.508068 ],"
137+
+ "\"toll_collection\": { \"type\": \"toll_gantry\" }"
138+
+ "}";
139+
140+
StepIntersection stepIntersection = StepIntersection.fromJson(stepIntersectionJsonString);
141+
142+
Assert.assertEquals("toll_gantry", stepIntersection.tollCollection().type());
143+
String jsonStr = stepIntersection.toJson();
144+
compareJson(stepIntersectionJsonString, jsonStr);
145+
}
131146
}

0 commit comments

Comments
 (0)