Skip to content

Commit 860eb7e

Browse files
Turn lane attributes for vehicle type accessibility (#1608)
* Support for IntersectionLane attributes * Changelog
1 parent 342f3a8 commit 860eb7e

File tree

10 files changed

+482
-102
lines changed

10 files changed

+482
-102
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Mapbox welcomes participation and contributions from everyone.
44

55
### main
66

7+
- Added `IntersectionLanes#access` property which provides lane access attributes, such as allowed vehicle types for designated lanes. [#1608](https://github.com/mapbox/mapbox-java/pull/1608)
8+
79
### v7.3.2 - March 13, 2025
810

911
- Updated `auto-value-gson` to version [0.0.2](https://github.com/mapbox/auto-value-gson/releases/tag/mapbox-v0.0.2). [#1605](https://github.com/mapbox/mapbox-java/pull/1605)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.mapbox.api.directions.v5.models;
2+
3+
import com.google.gson.TypeAdapter;
4+
import com.google.gson.stream.JsonReader;
5+
import com.google.gson.stream.JsonToken;
6+
import com.google.gson.stream.JsonWriter;
7+
8+
import java.io.IOException;
9+
10+
class InterningStringAdapter extends TypeAdapter<String> {
11+
12+
@Override
13+
public void write(JsonWriter out, String value) throws IOException {
14+
out.value(value);
15+
}
16+
17+
@Override
18+
public String read(JsonReader in) throws IOException {
19+
if (in.peek() == JsonToken.NULL) {
20+
in.nextNull();
21+
return null;
22+
}
23+
return in.nextString().intern();
24+
}
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
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+
}

services-directions-models/src/main/java/com/mapbox/api/directions/v5/models/IntersectionLanes.java

+30-8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.google.gson.TypeAdapter;
88
import com.google.gson.annotations.SerializedName;
99
import com.mapbox.api.directions.v5.DirectionsAdapterFactory;
10+
import com.mapbox.api.directions.v5.DirectionsCriteria.PaymentMethodsCriteria;
1011

1112
import java.util.List;
1213

@@ -72,24 +73,33 @@ public static Builder builder() {
7273
/**
7374
* Array that can be made up of multiple signs such as {@code left}, {@code right}, etc.
7475
*
75-
* @return Array of signs for each turn lane. There can be multiple signs. For example, a turning
76+
* @return List of signs for each turn lane. There can be multiple signs. For example, a turning
7677
* lane can have a sign with an arrow pointing left and another sign with an arrow pointing
7778
* straight.
7879
* @since 2.0.0
7980
*/
8081
@Nullable
8182
public abstract List<String> indications();
8283

83-
/*
84+
/**
8485
* Available payment methods for the lane.
8586
* @return A list of strings where each value
86-
* matches {@link DirectionsCriteria.PaymentMethodsCriteria}
87+
* matches {@link PaymentMethodsCriteria}
8788
*/
88-
@SuppressWarnings("checkstyle:javadocmethod")
8989
@Nullable
9090
@SerializedName("payment_methods")
9191
public abstract List<String> paymentMethods();
9292

93+
/**
94+
* A {@link IntersectionLaneAccess} object representing the access attributes of the lane.
95+
* This can include information such as the vehicle types for which the lane is designated.
96+
*
97+
* @return an object representing the access attributes of the lane.
98+
*/
99+
@Nullable
100+
@SerializedName("access")
101+
public abstract IntersectionLaneAccess access();
102+
93103
/**
94104
* Convert the current {@link IntersectionLanes} to its builder holding the currently assigned
95105
* values. This allows you to modify a single property and then rebuild the object resulting in
@@ -109,7 +119,11 @@ public static Builder builder() {
109119
* @since 3.0.0
110120
*/
111121
public static TypeAdapter<IntersectionLanes> typeAdapter(Gson gson) {
112-
return new IntersectionLanesTypeAdapter(new AutoValue_IntersectionLanes.GsonTypeAdapter(gson));
122+
final Gson customGson = gson.newBuilder()
123+
.registerTypeAdapter(String.class, new InterningStringAdapter())
124+
.create();
125+
126+
return new AutoValue_IntersectionLanes.GsonTypeAdapter(customGson);
113127
}
114128

115129
/**
@@ -176,14 +190,22 @@ public abstract static class Builder extends DirectionsJsonObject.Builder<Builde
176190
*/
177191
public abstract Builder indications(@Nullable List<String> indications);
178192

179-
/*
193+
/**
180194
* Set available payment methods for the lane.
181195
* @param paymentMethods is a list of strings where each value
182-
* matches {@link DirectionsCriteria.PaymentMethodsCriteria}
196+
* matches {@link PaymentMethodsCriteria}
183197
*/
184-
@SuppressWarnings("checkstyle:javadocmethod")
185198
public abstract Builder paymentMethods(@Nullable List<String> paymentMethods);
186199

200+
/**
201+
* A {@link IntersectionLaneAccess} object representing the access attributes of the lane.
202+
* This can include information such as the vehicle types for which the lane is designated.
203+
*
204+
* @param access an object representing the access attributes of the lane.
205+
* @return this builder for chaining options together
206+
*/
207+
public abstract Builder access(@Nullable IntersectionLaneAccess access);
208+
187209
/**
188210
* Build a new {@link IntersectionLanes} object.
189211
*

services-directions-models/src/main/java/com/mapbox/api/directions/v5/models/IntersectionLanesTypeAdapter.java

-91
This file was deleted.

0 commit comments

Comments
 (0)