Skip to content

Commit d35cdde

Browse files
authored
Directions models: Incident and Congestion (#1201)
1 parent d45921d commit d35cdde

5 files changed

Lines changed: 648 additions & 0 deletions

File tree

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package com.mapbox.api.directions.v5.models;
2+
3+
import com.google.auto.value.AutoValue;
4+
import com.google.gson.Gson;
5+
import com.google.gson.GsonBuilder;
6+
import com.google.gson.TypeAdapter;
7+
import com.mapbox.api.directions.v5.DirectionsAdapterFactory;
8+
9+
/**
10+
* Quantitative descriptor of congestion.
11+
*/
12+
@AutoValue
13+
public abstract class Congestion extends DirectionsJsonObject {
14+
15+
/**
16+
* Quantitative descriptor of congestion. 0 to 100.
17+
*/
18+
public abstract int value();
19+
20+
/**
21+
* Create a new instance of this class by using the {@link Builder} class.
22+
*
23+
* @return this classes {@link Builder} for creating a new instance
24+
*/
25+
public static Builder builder() {
26+
return new AutoValue_Congestion.Builder();
27+
}
28+
29+
/**
30+
* Convert the current {@link Congestion} to its builder holding the currently assigned
31+
* values. This allows you to modify a single property and then rebuild the object resulting in
32+
* an updated and modified {@link Congestion}.
33+
*
34+
* @return a {@link Builder} with the same values set to match the ones defined in this
35+
* {@link Congestion}
36+
*/
37+
public abstract Builder toBuilder();
38+
39+
/**
40+
* Gson type adapter for parsing Gson to this class.
41+
*
42+
* @param gson the built {@link Gson} object
43+
* @return the type adapter for this class
44+
*/
45+
public static TypeAdapter<Congestion> typeAdapter(Gson gson) {
46+
return new AutoValue_Congestion.GsonTypeAdapter(gson);
47+
}
48+
49+
/**
50+
* Create a new instance of this class by passing in a formatted valid JSON String.
51+
*
52+
* @param json a formatted valid JSON string defining an Congestion
53+
* @return a new instance of this class defined by the values passed in the method
54+
*/
55+
public static Congestion fromJson(String json) {
56+
GsonBuilder gson = new GsonBuilder();
57+
gson.registerTypeAdapterFactory(DirectionsAdapterFactory.create());
58+
return gson.create().fromJson(json, Congestion.class);
59+
}
60+
61+
/**
62+
* This builder can be used to set the values describing the {@link Congestion}.
63+
*/
64+
@AutoValue.Builder
65+
public abstract static class Builder {
66+
67+
/**
68+
* Quantitative descriptor of congestion. 0 to 100.
69+
* @param value 0 to 100
70+
*/
71+
public abstract Builder value(int value);
72+
73+
/**
74+
* Build a new instance of {@link Congestion}.
75+
* @return a new instance of {@link Congestion}.
76+
*/
77+
public abstract Congestion build();
78+
}
79+
}

0 commit comments

Comments
 (0)