|
| 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()} |
| 67 | + * and {@link Notification#subtype()}. |
| 68 | + * |
| 69 | + * @return notification details |
| 70 | + */ |
| 71 | + @Nullable |
| 72 | + public abstract NotificationDetails details(); |
| 73 | + |
| 74 | + /** |
| 75 | + * Convert the current {@link Notification} to its builder holding the currently assigned |
| 76 | + * values. This allows you to modify a single property and then rebuild the object resulting in |
| 77 | + * an updated and modified {@link Notification}. |
| 78 | + * |
| 79 | + * @return a {@link Builder} with the same values set to match the ones defined |
| 80 | + * in this {@link Notification} |
| 81 | + */ |
| 82 | + public abstract Builder toBuilder(); |
| 83 | + |
| 84 | + /** |
| 85 | + * Gson type adapter for parsing Gson to this class. |
| 86 | + * |
| 87 | + * @param gson the built {@link Gson} object |
| 88 | + * @return the type adapter for this class |
| 89 | + */ |
| 90 | + public static TypeAdapter<Notification> typeAdapter(Gson gson) { |
| 91 | + return new AutoValue_Notification.GsonTypeAdapter(gson); |
| 92 | + } |
| 93 | + |
| 94 | + /** |
| 95 | + * Create a new instance of this class by passing in a formatted valid JSON String. |
| 96 | + * |
| 97 | + * @param json a formatted valid JSON string defining a Notification |
| 98 | + * @return a new instance of this class defined by the values passed inside this static factory |
| 99 | + * method |
| 100 | + */ |
| 101 | + public static Notification fromJson(String json) { |
| 102 | + GsonBuilder gson = new GsonBuilder(); |
| 103 | + gson.registerTypeAdapterFactory(DirectionsAdapterFactory.create()); |
| 104 | + return gson.create().fromJson(json, Notification.class); |
| 105 | + } |
| 106 | + |
| 107 | + /** |
| 108 | + * This builder can be used to set the values describing the {@link Notification}. |
| 109 | + */ |
| 110 | + @AutoValue.Builder |
| 111 | + public abstract static class Builder extends DirectionsJsonObject.Builder<Builder> { |
| 112 | + |
| 113 | + /** |
| 114 | + * Notification type. Can be one of {@link DirectionsCriteria.NotificationsTypeCriteria}. |
| 115 | + * |
| 116 | + * @param type notification type |
| 117 | + * @return this builder for chaining options together |
| 118 | + */ |
| 119 | + @NonNull |
| 120 | + public abstract Builder type( |
| 121 | + @NonNull @DirectionsCriteria.NotificationsTypeCriteria String type |
| 122 | + ); |
| 123 | + |
| 124 | + /** |
| 125 | + * Notification subtype. Can be one of {@link DirectionsCriteria.NotificationsSubtypeCriteria}, |
| 126 | + * depending on {@link Notification.Builder#type()}. |
| 127 | + * |
| 128 | + * @param subtype notification subtype |
| 129 | + * @return this builder for chaining options together |
| 130 | + */ |
| 131 | + @NonNull |
| 132 | + public abstract Builder subtype( |
| 133 | + @Nullable @DirectionsCriteria.NotificationsSubtypeCriteria String subtype |
| 134 | + ); |
| 135 | + |
| 136 | + /** |
| 137 | + * Leg-wise start index of the area that violates the request parameter. |
| 138 | + * |
| 139 | + * @param geometryIndexStart start index |
| 140 | + * @return this builder for chaining options together |
| 141 | + */ |
| 142 | + @SerializedName("geometry_index_start") |
| 143 | + @NonNull |
| 144 | + public abstract Builder geometryIndexStart(@Nullable Integer geometryIndexStart); |
| 145 | + |
| 146 | + /** |
| 147 | + * Leg-wise end index of the area that violates the request parameter. |
| 148 | + * |
| 149 | + * @param geometryIndexEnd end index |
| 150 | + * @return this builder for chaining options together |
| 151 | + */ |
| 152 | + @SerializedName("geometry_index_end") |
| 153 | + @NonNull |
| 154 | + public abstract Builder geometryIndexEnd(@Nullable Integer geometryIndexEnd); |
| 155 | + |
| 156 | + /** |
| 157 | + * Notification details. |
| 158 | + * |
| 159 | + * @param details notification details |
| 160 | + * @return this builder for chaining options together |
| 161 | + */ |
| 162 | + @NonNull |
| 163 | + public abstract Builder details(@Nullable NotificationDetails details); |
| 164 | + |
| 165 | + /** |
| 166 | + * Build a new {@link Notification} object. |
| 167 | + * |
| 168 | + * @return a new {@link Notification} using the provided values in this builder |
| 169 | + */ |
| 170 | + @NonNull |
| 171 | + public abstract Notification build(); |
| 172 | + } |
| 173 | +} |
0 commit comments