|
| 1 | +package com.mapbox.api.directions.v5.models; |
| 2 | + |
| 3 | +import androidx.annotation.Nullable; |
| 4 | +import androidx.annotation.StringDef; |
| 5 | + |
| 6 | +import com.google.auto.value.AutoValue; |
| 7 | +import com.google.gson.Gson; |
| 8 | +import com.google.gson.GsonBuilder; |
| 9 | +import com.google.gson.TypeAdapter; |
| 10 | +import com.google.gson.annotations.SerializedName; |
| 11 | +import com.mapbox.api.directions.v5.DirectionsAdapterFactory; |
| 12 | + |
| 13 | +import java.lang.annotation.Retention; |
| 14 | +import java.lang.annotation.RetentionPolicy; |
| 15 | +import java.util.List; |
| 16 | + |
| 17 | +/** |
| 18 | + * Object representing lane access attributes. |
| 19 | + */ |
| 20 | +@AutoValue |
| 21 | +public abstract class IntersectionLaneAccess extends DirectionsJsonObject { |
| 22 | + |
| 23 | + /** |
| 24 | + * Indicates lanes that is designated to bicycles. |
| 25 | + */ |
| 26 | + public static final String BICYCLE = "bicycle"; |
| 27 | + |
| 28 | + /** |
| 29 | + * Indicates lanes that is designated to buses. |
| 30 | + */ |
| 31 | + public static final String BUS = "bus"; |
| 32 | + |
| 33 | + /** |
| 34 | + * Indicates High-occupancy vehicle lanes. |
| 35 | + */ |
| 36 | + public static final String HOV = "hov"; |
| 37 | + |
| 38 | + /** |
| 39 | + * Indicates lanes that is designated to mopeds. |
| 40 | + */ |
| 41 | + public static final String MOPED = "moped"; |
| 42 | + |
| 43 | + /** |
| 44 | + * Indicates lanes that is designated to motorcycles. |
| 45 | + */ |
| 46 | + public static final String MOTORCYCLE = "motorcycle"; |
| 47 | + |
| 48 | + /** |
| 49 | + * Indicates lanes that is designated to taxis. |
| 50 | + */ |
| 51 | + public static final String TAXI = "taxi"; |
| 52 | + |
| 53 | + /** |
| 54 | + * Represents the allowed vehicle types for a designated lane. |
| 55 | + */ |
| 56 | + @Retention(RetentionPolicy.CLASS) |
| 57 | + @StringDef({ |
| 58 | + BICYCLE, |
| 59 | + BUS, |
| 60 | + HOV, |
| 61 | + MOPED, |
| 62 | + MOTORCYCLE, |
| 63 | + TAXI |
| 64 | + }) |
| 65 | + public @interface LaneDesignatedVehicleType { |
| 66 | + } |
| 67 | + |
| 68 | + /** |
| 69 | + * Indicates whether a lane is designated to specified vehicle types. |
| 70 | + * A vehicle type can be any of (but not limited to) the predefined constants in |
| 71 | + * {@link LaneDesignatedVehicleType}, such as {@link #BICYCLE}, |
| 72 | + * {@link #BUS}, {@link #HOV}, {@link #MOPED}, {@link #MOTORCYCLE}, or {@link #TAXI}. |
| 73 | + * For example, when a lane is designated to buses and taxis, this list should have |
| 74 | + * {@link #BUS} and {@link #TAXI} as its values. |
| 75 | + * |
| 76 | + * @return a list of vehicle types for which this lane is designated |
| 77 | + * @see LaneDesignatedVehicleType |
| 78 | + */ |
| 79 | + @Nullable |
| 80 | + @SerializedName("designated") |
| 81 | + public abstract List<String> designated(); |
| 82 | + |
| 83 | + /** |
| 84 | + * Convert the current {@link IntersectionLaneAccess} to its builder holding the |
| 85 | + * currently assigned values. This allows you to modify a single property and then rebuild |
| 86 | + * the object resulting in an updated and modified {@link IntersectionLaneAccess}. |
| 87 | + * |
| 88 | + * @return a {@link IntersectionLaneAccess.Builder} with the same values set to match the ones |
| 89 | + * defined in this {@link IntersectionLaneAccess} |
| 90 | + */ |
| 91 | + public abstract IntersectionLaneAccess.Builder toBuilder(); |
| 92 | + |
| 93 | + /** |
| 94 | + * Create a new instance of this class by using the {@link IntersectionLaneAccess.Builder} class. |
| 95 | + * |
| 96 | + * @return this classes {@link IntersectionLaneAccess.Builder} for creating a new instance |
| 97 | + */ |
| 98 | + public static IntersectionLaneAccess.Builder builder() { |
| 99 | + return new AutoValue_IntersectionLaneAccess.Builder(); |
| 100 | + } |
| 101 | + |
| 102 | + /** |
| 103 | + * Gson type adapter for parsing Gson to this class. |
| 104 | + * |
| 105 | + * @param gson the built {@link Gson} object |
| 106 | + * @return the type adapter for this class |
| 107 | + */ |
| 108 | + public static TypeAdapter<IntersectionLaneAccess> typeAdapter(Gson gson) { |
| 109 | + final Gson customGson = gson.newBuilder() |
| 110 | + .registerTypeAdapter(String.class, new InterningStringAdapter()) |
| 111 | + .create(); |
| 112 | + return new AutoValue_IntersectionLaneAccess.GsonTypeAdapter(customGson); |
| 113 | + } |
| 114 | + |
| 115 | + /** |
| 116 | + * Create a new instance of this class by passing in a formatted valid JSON String. |
| 117 | + * |
| 118 | + * @param json a formatted valid JSON string defining an IntersectionLaneAccess |
| 119 | + * @return a new instance of this class defined by the values passed inside this static factory |
| 120 | + * method |
| 121 | + */ |
| 122 | + public static IntersectionLaneAccess fromJson(String json) { |
| 123 | + GsonBuilder gson = new GsonBuilder(); |
| 124 | + gson.registerTypeAdapterFactory(DirectionsAdapterFactory.create()); |
| 125 | + return gson.create().fromJson(json, IntersectionLaneAccess.class); |
| 126 | + } |
| 127 | + |
| 128 | + /** |
| 129 | + * This builder can be used to set the values describing the {@link IntersectionLaneAccess}. |
| 130 | + */ |
| 131 | + @AutoValue.Builder |
| 132 | + public abstract static class Builder extends |
| 133 | + DirectionsJsonObject.Builder<IntersectionLaneAccess.Builder> { |
| 134 | + |
| 135 | + /** |
| 136 | + * Provide a list of vehicle types for which this lane is designated. A vehicle type can be |
| 137 | + * any of (but not limited to) the predefined constants in |
| 138 | + * {@link LaneDesignatedVehicleType}, such as {@link #BICYCLE}, {@link #BUS}, {@link #HOV}, |
| 139 | + * {@link #MOPED}, {@link #MOTORCYCLE}, or {@link #TAXI} |
| 140 | + * |
| 141 | + * @param designated a list of vehicle types for which this lane is designated. |
| 142 | + * @return this builder for chaining options together |
| 143 | + */ |
| 144 | + public abstract IntersectionLaneAccess.Builder designated(@Nullable List<String> designated); |
| 145 | + |
| 146 | + /** |
| 147 | + * Build a new {@link IntersectionLaneAccess} object. |
| 148 | + * |
| 149 | + * @return a new {@link IntersectionLaneAccess} using the provided values in this builder |
| 150 | + */ |
| 151 | + public abstract IntersectionLaneAccess build(); |
| 152 | + } |
| 153 | +} |
0 commit comments