|
| 1 | +package com.mapbox.api.directions.v5.models; |
| 2 | + |
| 3 | +import androidx.annotation.NonNull; |
| 4 | +import androidx.annotation.Nullable; |
| 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.mapbox.api.directions.v5.DirectionsAdapterFactory; |
| 11 | + |
| 12 | +import java.io.Serializable; |
| 13 | +import java.util.List; |
| 14 | + |
| 15 | +/** |
| 16 | + * ShieldSpriteAttribute. |
| 17 | + */ |
| 18 | +@AutoValue |
| 19 | +public abstract class ShieldSpriteAttribute implements Serializable { |
| 20 | + |
| 21 | + /** |
| 22 | + * Create a new instance of this class by using the {@link ShieldSpriteAttribute.Builder} class. |
| 23 | + * |
| 24 | + * @return {@link ShieldSpriteAttribute.Builder} for creating a new instance |
| 25 | + */ |
| 26 | + public static Builder builder() { |
| 27 | + return new AutoValue_ShieldSpriteAttribute.Builder(); |
| 28 | + } |
| 29 | + |
| 30 | + /** |
| 31 | + * Create a new instance of this class by passing in a formatted valid JSON String. |
| 32 | + * |
| 33 | + * @param json a formatted valid JSON string defining a shield sprite |
| 34 | + * @return a new instance of this class defined by the values passed inside this static factory |
| 35 | + * method |
| 36 | + */ |
| 37 | + @NonNull |
| 38 | + public static ShieldSpriteAttribute fromJson(@NonNull String json) { |
| 39 | + GsonBuilder gson = new GsonBuilder(); |
| 40 | + gson.registerTypeAdapterFactory(DirectionsAdapterFactory.create()); |
| 41 | + return gson.create().fromJson(json, ShieldSpriteAttribute.class); |
| 42 | + } |
| 43 | + |
| 44 | + /** |
| 45 | + * Shield sprite's width. |
| 46 | + */ |
| 47 | + @NonNull |
| 48 | + public abstract Integer width(); |
| 49 | + |
| 50 | + /** |
| 51 | + * Shield sprite's height. |
| 52 | + */ |
| 53 | + @NonNull |
| 54 | + public abstract Integer height(); |
| 55 | + |
| 56 | + /** |
| 57 | + * Shield sprite's x position. |
| 58 | + */ |
| 59 | + @NonNull |
| 60 | + public abstract Integer x(); |
| 61 | + |
| 62 | + /** |
| 63 | + * Shield sprite's y position. |
| 64 | + */ |
| 65 | + @NonNull |
| 66 | + public abstract Integer y(); |
| 67 | + |
| 68 | + /** |
| 69 | + * Shield sprite's pixel ratio. |
| 70 | + */ |
| 71 | + @NonNull |
| 72 | + public abstract Integer pixelRatio(); |
| 73 | + |
| 74 | + /** |
| 75 | + * Shield sprite's placeholder (optional). |
| 76 | + */ |
| 77 | + @Nullable |
| 78 | + public abstract List<Double> placeholder(); |
| 79 | + |
| 80 | + /** |
| 81 | + * Shield sprite's visibility. |
| 82 | + */ |
| 83 | + @NonNull |
| 84 | + public abstract Boolean visible(); |
| 85 | + |
| 86 | + /** |
| 87 | + * Convert the current {@link ShieldSpriteAttribute} to its builder holding the currently assigned |
| 88 | + * values. This allows you to modify a single property and then rebuild the object resulting in |
| 89 | + * an updated and modified {@link ShieldSpriteAttribute}. |
| 90 | + * |
| 91 | + * @return a {@link ShieldSpriteAttribute.Builder} with the same values set to match the ones |
| 92 | + * defined in this {@link ShieldSpriteAttribute} |
| 93 | + */ |
| 94 | + public abstract Builder toBuilder(); |
| 95 | + |
| 96 | + /** |
| 97 | + * This takes the currently defined values found inside the {@link ShieldSpriteAttribute} instance |
| 98 | + * and converts it to a {@link ShieldSpriteAttribute} string. |
| 99 | + * |
| 100 | + * @return a JSON string which represents a {@link ShieldSpriteAttribute} |
| 101 | + */ |
| 102 | + @NonNull |
| 103 | + public String toJson() { |
| 104 | + GsonBuilder gson = new GsonBuilder(); |
| 105 | + gson.registerTypeAdapterFactory(DirectionsAdapterFactory.create()); |
| 106 | + return gson.create().toJson(this); |
| 107 | + } |
| 108 | + |
| 109 | + /** |
| 110 | + * Gson type adapter for parsing Gson to this class. |
| 111 | + * |
| 112 | + * @param gson the built {@link Gson} object |
| 113 | + * @return the type adapter for this class |
| 114 | + */ |
| 115 | + public static TypeAdapter<ShieldSpriteAttribute> typeAdapter(Gson gson) { |
| 116 | + return new AutoValue_ShieldSpriteAttribute.GsonTypeAdapter(gson); |
| 117 | + } |
| 118 | + |
| 119 | + /** |
| 120 | + * This builder can be used to set the values describing the {@link ShieldSpriteAttribute}. |
| 121 | + */ |
| 122 | + @AutoValue.Builder |
| 123 | + public abstract static class Builder { |
| 124 | + |
| 125 | + /** |
| 126 | + * Shield sprite's width. |
| 127 | + * |
| 128 | + * @param width sprite's width |
| 129 | + */ |
| 130 | + @NonNull |
| 131 | + public abstract Builder width(@NonNull Integer width); |
| 132 | + |
| 133 | + /** |
| 134 | + * Shield sprite's height. |
| 135 | + * |
| 136 | + * @param height sprite's height |
| 137 | + */ |
| 138 | + @NonNull |
| 139 | + public abstract Builder height(@NonNull Integer height); |
| 140 | + |
| 141 | + /** |
| 142 | + * Shield sprite's x position. |
| 143 | + * |
| 144 | + * @param x sprite's x position |
| 145 | + */ |
| 146 | + @NonNull |
| 147 | + public abstract Builder x(@NonNull Integer x); |
| 148 | + |
| 149 | + /** |
| 150 | + * Shield sprite's y position. |
| 151 | + * |
| 152 | + * @param y sprite's x position |
| 153 | + */ |
| 154 | + @NonNull |
| 155 | + public abstract Builder y(@NonNull Integer y); |
| 156 | + |
| 157 | + /** |
| 158 | + * Shield sprite's pixel ratio. |
| 159 | + * |
| 160 | + * @param pixelRatio sprite's pixel ratio |
| 161 | + */ |
| 162 | + @NonNull |
| 163 | + public abstract Builder pixelRatio(@NonNull Integer pixelRatio); |
| 164 | + |
| 165 | + /** |
| 166 | + * Shield sprite's placeholder. |
| 167 | + * |
| 168 | + * @param placeholder sprite's placeholder |
| 169 | + */ |
| 170 | + @NonNull |
| 171 | + public abstract Builder placeholder(@Nullable List<Double> placeholder); |
| 172 | + |
| 173 | + /** |
| 174 | + * Shield sprite's visibility. |
| 175 | + * |
| 176 | + * @param visible sprite's visibility |
| 177 | + */ |
| 178 | + @NonNull |
| 179 | + public abstract Builder visible(@NonNull Boolean visible); |
| 180 | + |
| 181 | + /** |
| 182 | + * Build a new {@link ShieldSpriteAttribute} object. |
| 183 | + * |
| 184 | + * @return a new {@link ShieldSpriteAttribute} using the provided values in this builder |
| 185 | + */ |
| 186 | + @NonNull |
| 187 | + public abstract ShieldSpriteAttribute build(); |
| 188 | + } |
| 189 | +} |
0 commit comments