1+ package com .mapbox .api .directions .v5 .models ;
2+
3+ import androidx .annotation .NonNull ;
4+ import androidx .annotation .Nullable ;
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 .google .gson .annotations .SerializedName ;
10+ import com .mapbox .api .directions .v5 .DirectionsAdapterFactory ;
11+ import com .mapbox .api .directions .v5 .DirectionsCriteria ;
12+
13+ /**
14+ * Class containing information about route notification. See {@link RouteLeg#notifications()}.
15+ */
16+ @ AutoValue
17+ public abstract class Notification extends DirectionsJsonObject {
18+
19+ /**
20+ * Create a new instance of this class by using the {@link Builder} class.
21+ *
22+ * @return this classes {@link Builder} for creating a new instance
23+ */
24+ public static Builder builder () {
25+ return new AutoValue_Notification .Builder ();
26+ }
27+
28+ /**
29+ * Notification type. Can be one of {@link DirectionsCriteria.NotificationsTypeCriteria}.
30+ *
31+ * @return notification type
32+ */
33+ @ NonNull
34+ @ DirectionsCriteria .NotificationsTypeCriteria
35+ public abstract String type ();
36+
37+ /**
38+ * Notification subtype. Can be one of {@link DirectionsCriteria.NotificationsSubtypeCriteria},
39+ * depending on {@link Notification#type()}.
40+ *
41+ * @return notification subtype
42+ */
43+ @ Nullable
44+ @ DirectionsCriteria .NotificationsSubtypeCriteria
45+ public abstract String subtype ();
46+
47+ /**
48+ * Leg-wise start index of the area that violates the request parameter.
49+ *
50+ * @return start index
51+ */
52+ @ SerializedName ("geometry_index_start" )
53+ @ Nullable
54+ public abstract Integer geometryIndexStart ();
55+
56+ /**
57+ * Leg-wise end index of the area that violates the request parameter.
58+ *
59+ * @return end index
60+ */
61+ @ SerializedName ("geometry_index_end" )
62+ @ Nullable
63+ public abstract Integer geometryIndexEnd ();
64+
65+ /**
66+ * Notification details specific to {@link Notification#type()} and {@link Notification#subtype()}.
67+ *
68+ * @return notification details
69+ */
70+ @ Nullable
71+ public abstract NotificationDetails details ();
72+
73+ /**
74+ * Convert the current {@link Notification} to its builder holding the currently assigned
75+ * values. This allows you to modify a single property and then rebuild the object resulting in
76+ * an updated and modified {@link Notification}.
77+ *
78+ * @return a {@link Builder} with the same values set to match the ones defined
79+ * in this {@link Notification}
80+ */
81+ public abstract Builder toBuilder ();
82+
83+ /**
84+ * Gson type adapter for parsing Gson to this class.
85+ *
86+ * @param gson the built {@link Gson} object
87+ * @return the type adapter for this class
88+ */
89+ public static TypeAdapter <Notification > typeAdapter (Gson gson ) {
90+ return new AutoValue_Notification .GsonTypeAdapter (gson );
91+ }
92+
93+ /**
94+ * Create a new instance of this class by passing in a formatted valid JSON String.
95+ *
96+ * @param json a formatted valid JSON string defining a Notification
97+ * @return a new instance of this class defined by the values passed inside this static factory
98+ * method
99+ */
100+ public static Notification fromJson (String json ) {
101+ GsonBuilder gson = new GsonBuilder ();
102+ gson .registerTypeAdapterFactory (DirectionsAdapterFactory .create ());
103+ return gson .create ().fromJson (json , Notification .class );
104+ }
105+
106+ /**
107+ * This builder can be used to set the values describing the {@link Notification}.
108+ */
109+ @ AutoValue .Builder
110+ public abstract static class Builder extends DirectionsJsonObject .Builder <Builder > {
111+
112+ /**
113+ * Notification type. Can be one of {@link DirectionsCriteria.NotificationsTypeCriteria}.
114+ *
115+ * @param type notification type
116+ * @return this builder for chaining options together
117+ */
118+ @ NonNull
119+ public abstract Builder type (@ NonNull @ DirectionsCriteria .NotificationsTypeCriteria String type );
120+
121+ /**
122+ * Notification subtype. Can be one of {@link DirectionsCriteria.NotificationsSubtypeCriteria},
123+ * depending on {@link Notification.Builder#type()}.
124+ *
125+ * @param subtype notification subtype
126+ * @return this builder for chaining options together
127+ */
128+ @ NonNull
129+ public abstract Builder subtype (@ Nullable @ DirectionsCriteria .NotificationsSubtypeCriteria String subtype );
130+
131+ /**
132+ * Leg-wise start index of the area that violates the request parameter.
133+ *
134+ * @param geometryIndexStart start index
135+ * @return this builder for chaining options together
136+ */
137+ @ SerializedName ("geometry_index_start" )
138+ @ NonNull
139+ public abstract Builder geometryIndexStart (@ Nullable Integer geometryIndexStart );
140+
141+ /**
142+ * Leg-wise end index of the area that violates the request parameter.
143+ *
144+ * @param geometryIndexEnd end index
145+ * @return this builder for chaining options together
146+ */
147+ @ SerializedName ("geometry_index_end" )
148+ @ NonNull
149+ public abstract Builder geometryIndexEnd (@ Nullable Integer geometryIndexEnd );
150+
151+ /**
152+ * Notification details.
153+ *
154+ * @param details notification details
155+ * @return this builder for chaining options together
156+ */
157+ @ NonNull
158+ public abstract Builder details (@ Nullable NotificationDetails details );
159+
160+ /**
161+ * Build a new {@link Notification} object.
162+ *
163+ * @return a new {@link Notification} using the provided values in this builder
164+ */
165+ @ NonNull
166+ public abstract Notification build ();
167+ }
168+ }
0 commit comments