|
| 1 | +package com.mapbox.api.directionsrefresh.v1.models; |
| 2 | + |
| 3 | +import androidx.annotation.Nullable; |
| 4 | +import com.google.auto.value.AutoValue; |
| 5 | +import com.google.gson.Gson; |
| 6 | +import com.google.gson.GsonBuilder; |
| 7 | +import com.google.gson.TypeAdapter; |
| 8 | +import com.mapbox.api.directions.v5.DirectionsAdapterFactory; |
| 9 | +import com.mapbox.api.directions.v5.models.DirectionsWaypoint; |
| 10 | +import com.mapbox.api.directions.v5.models.LegAnnotation; |
| 11 | +import com.mapbox.api.directionsrefresh.v1.DirectionsRefreshAdapterFactory; |
| 12 | + |
| 13 | +/** |
| 14 | + * A route refresh data between only two {@link DirectionsWaypoint}. |
| 15 | + */ |
| 16 | +@AutoValue |
| 17 | +public abstract class RouteLegRefresh extends DirectionsRefreshJsonObject { |
| 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_RouteLegRefresh.Builder(); |
| 26 | + } |
| 27 | + |
| 28 | + /** |
| 29 | + * A {@link LegAnnotation} that contains additional details about each line segment along the |
| 30 | + * route geometry. If you'd like to receiving this, you must request it inside your Directions |
| 31 | + * request before executing the call. |
| 32 | + * |
| 33 | + * @return a {@link LegAnnotation} object |
| 34 | + */ |
| 35 | + @Nullable |
| 36 | + public abstract LegAnnotation annotation(); |
| 37 | + |
| 38 | + /** |
| 39 | + * Convert the current {@link RouteLegRefresh} to its builder holding the currently assigned |
| 40 | + * values. This allows you to modify a single property and then rebuild the object resulting in |
| 41 | + * an updated and modified {@link RouteLegRefresh}. |
| 42 | + * |
| 43 | + * @return a {@link RouteLegRefresh.Builder} with the same values set to match the ones defined |
| 44 | + * in this {@link RouteLegRefresh} |
| 45 | + */ |
| 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<RouteLegRefresh> typeAdapter(Gson gson) { |
| 56 | + return new AutoValue_RouteLegRefresh.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 a RouteLeg |
| 63 | + * @return a new instance of this class defined by the values passed inside this static factory |
| 64 | + * method |
| 65 | + */ |
| 66 | + public static RouteLegRefresh fromJson(String json) { |
| 67 | + GsonBuilder gson = new GsonBuilder(); |
| 68 | + gson.registerTypeAdapterFactory(DirectionsAdapterFactory.create()); |
| 69 | + gson.registerTypeAdapterFactory(DirectionsRefreshAdapterFactory.create()); |
| 70 | + return gson.create().fromJson(json, RouteLegRefresh.class); |
| 71 | + } |
| 72 | + |
| 73 | + /** |
| 74 | + * This builder can be used to set the values describing the {@link RouteLegRefresh}. |
| 75 | + */ |
| 76 | + @AutoValue.Builder |
| 77 | + public abstract static class Builder { |
| 78 | + |
| 79 | + /** |
| 80 | + * A {@link LegAnnotation} that contains additional details about each line segment along the |
| 81 | + * route geometry. If you'd like to receiving this, you must request it inside your Directions |
| 82 | + * request before executing the call. |
| 83 | + * |
| 84 | + * @param annotation a {@link LegAnnotation} object |
| 85 | + * @return this builder for chaining options together |
| 86 | + */ |
| 87 | + public abstract Builder annotation(@Nullable LegAnnotation annotation); |
| 88 | + |
| 89 | + /** |
| 90 | + * Build a new {@link RouteLegRefresh} object. |
| 91 | + * |
| 92 | + * @return a new {@link RouteLegRefresh} using the provided values in this builder |
| 93 | + */ |
| 94 | + public abstract RouteLegRefresh build(); |
| 95 | + } |
| 96 | +} |
0 commit comments