Skip to content

Commit ad9202b

Browse files
committed
add ic and jct information to step intersection
1 parent 6b94f10 commit ad9202b

7 files changed

Lines changed: 417 additions & 1 deletion

File tree

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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.mapbox.api.directions.v5.DirectionsAdapterFactory;
10+
11+
/*
12+
* An object containing information about routing and passing interchange(s) along the route.
13+
*/
14+
@AutoValue
15+
@SuppressWarnings({"checkstyle:javadoctype", "checkstyle:javadocmethod"})
16+
public abstract class Interchange extends DirectionsJsonObject {
17+
18+
/*
19+
* The name of the interchange. Optionally included if data is available.
20+
*/
21+
@Nullable
22+
public abstract String name();
23+
24+
/*
25+
* Create a new instance of this class by using the {@link Builder} class.
26+
*
27+
* @return this classes {@link Builder} for creating a new instance
28+
*/
29+
public static Builder builder() {
30+
return new AutoValue_Interchange.Builder();
31+
}
32+
33+
/*
34+
* Convert the current {@link Interchange} to its builder holding the currently assigned
35+
* values. This allows you to modify a single property and then rebuild the object resulting in
36+
* an updated and modified {@link Interchange}.
37+
*
38+
* @return a {@link Builder} with the same values set to match the ones defined in this {@link
39+
* Interchange}
40+
*/
41+
public abstract Builder toBuilder();
42+
43+
/*
44+
* Gson type adapter for parsing Gson to this class.
45+
*
46+
* @param gson the built {@link Gson} object
47+
* @return the type adapter for this class
48+
*/
49+
public static TypeAdapter<Interchange> typeAdapter(Gson gson) {
50+
return new AutoValue_Interchange.GsonTypeAdapter(gson);
51+
}
52+
53+
/*
54+
* Create a new instance of this class by passing in a formatted valid JSON String.
55+
*
56+
* @param json a formatted valid JSON string defining an {@link Interchange}
57+
* @return a new instance of this class defined by the values passed in the method
58+
*/
59+
public static Interchange fromJson(String json) {
60+
GsonBuilder gson = new GsonBuilder();
61+
gson.registerTypeAdapterFactory(DirectionsAdapterFactory.create());
62+
return gson.create().fromJson(json, Interchange.class);
63+
}
64+
65+
/*
66+
* This builder can be used to set the values describing the {@link Interchange}.
67+
*/
68+
@AutoValue.Builder
69+
public abstract static class Builder extends DirectionsJsonObject.Builder<Builder> {
70+
71+
/*
72+
* The name of the interchange. Optionally included if data is available.
73+
*
74+
* @param name interchange name
75+
*/
76+
@NonNull
77+
public abstract Builder name(@Nullable String name);
78+
79+
/*
80+
* Build a new {@link Interchange} object.
81+
*
82+
* @return a new {@link Interchange} using the provided values in this builder
83+
*/
84+
@NonNull
85+
public abstract Interchange build();
86+
}
87+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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.mapbox.api.directions.v5.DirectionsAdapterFactory;
10+
11+
/*
12+
* An object containing information about routing and passing junction(s) along the route.
13+
*/
14+
@AutoValue
15+
@SuppressWarnings({"checkstyle:javadoctype", "checkstyle:javadocmethod"})
16+
public abstract class Junction extends DirectionsJsonObject {
17+
18+
/*
19+
* The name of the junction. Optionally included if data is available.
20+
*/
21+
@Nullable
22+
public abstract String name();
23+
24+
/*
25+
* Create a new instance of this class by using the {@link Builder} class.
26+
*
27+
* @return this classes {@link Builder} for creating a new instance
28+
*/
29+
public static Builder builder() {
30+
return new AutoValue_Junction.Builder();
31+
}
32+
33+
/*
34+
* Convert the current {@link Junction} to its builder holding the currently assigned
35+
* values. This allows you to modify a single property and then rebuild the object resulting in
36+
* an updated and modified {@link Junction}.
37+
*
38+
* @return a {@link Builder} with the same values set to match the ones defined
39+
* in this {@link Junction}
40+
*/
41+
public abstract Builder toBuilder();
42+
43+
/*
44+
* Gson type adapter for parsing Gson to this class.
45+
*
46+
* @param gson the built {@link Gson} object
47+
* @return the type adapter for this class
48+
*/
49+
public static TypeAdapter<Junction> typeAdapter(Gson gson) {
50+
return new AutoValue_Junction.GsonTypeAdapter(gson);
51+
}
52+
53+
/*
54+
* Create a new instance of this class by passing in a formatted valid JSON String.
55+
*
56+
* @param json a formatted valid JSON string defining a Junction
57+
* @return a new instance of this class defined by the values passed in the method
58+
*/
59+
public static Junction fromJson(String json) {
60+
GsonBuilder gson = new GsonBuilder();
61+
gson.registerTypeAdapterFactory(DirectionsAdapterFactory.create());
62+
return gson.create().fromJson(json, Junction.class);
63+
}
64+
65+
/*
66+
* This builder can be used to set the values describing the {@link Junction}.
67+
*/
68+
@AutoValue.Builder
69+
public abstract static class Builder extends DirectionsJsonObject.Builder<Builder> {
70+
71+
/*
72+
* The name of the junction. Optionally included if data is available.
73+
*
74+
* @param name junction name
75+
*/
76+
@NonNull
77+
public abstract Builder name(@Nullable String name);
78+
79+
/*
80+
* Build a new {@link Junction} object.
81+
*
82+
* @return a new {@link Junction} using the provided values in this builder
83+
*/
84+
@NonNull
85+
public abstract Junction build();
86+
}
87+
}

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

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,30 @@ public Point location() {
241241
@SerializedName("yield_sign")
242242
public abstract Boolean yieldSign();
243243

244+
/*
245+
* An object containing information about routing and passing interchange(s) along the route.
246+
* The object is optionally included if the data is available.
247+
*
248+
* @return an object containing information about routing and passing interchange(s) along the
249+
* route if data is available, otherwise null.
250+
*/
251+
@Nullable
252+
@SerializedName("ic")
253+
@SuppressWarnings("checkstyle:javadocmethod")
254+
public abstract Interchange interchange();
255+
256+
/*
257+
* An object containing information about routing and passing junction(s) along the route.
258+
* The object is optionally included if the data is available.
259+
*
260+
* @return an object containing information about routing and passing junction(s) along the
261+
* route if data is available, otherwise null.
262+
*/
263+
@Nullable
264+
@SerializedName("jct")
265+
@SuppressWarnings("checkstyle:javadocmethod")
266+
public abstract Junction junction();
267+
244268
/**
245269
* Convert the current {@link StepIntersection} to its builder holding the currently assigned
246270
* values. This allows you to modify a single property and then rebuild the object resulting in
@@ -480,6 +504,30 @@ public abstract static class Builder extends DirectionsJsonObject.Builder<Builde
480504
@NonNull
481505
public abstract Builder yieldSign(@Nullable Boolean yieldSign);
482506

507+
/*
508+
* An object containing information about routing and passing interchange(s) along the route.
509+
*
510+
* @param interchange object containing information about routing and passing interchange(s)
511+
* along the route.
512+
* @return Builder containing information about routing and passing interchange(s) along the
513+
* route if data is available, otherwise null.
514+
*/
515+
@NonNull
516+
@SuppressWarnings("checkstyle:javadocmethod")
517+
public abstract Builder interchange(@Nullable Interchange interchange);
518+
519+
/*
520+
* An object containing information about routing and passing junction(s) along the route.
521+
*
522+
* @param junction object containing information about routing and passing junction(s)
523+
* along the route.
524+
* @return Builder containing information about routing and passing junction(s) along the
525+
* route if data is available, otherwise null.
526+
*/
527+
@NonNull
528+
@SuppressWarnings("checkstyle:javadocmethod")
529+
public abstract Builder junction(@Nullable Junction junction);
530+
483531
/**
484532
* The rawLocation as a double array. Once the {@link StepIntersection} object's created,
485533
* this raw location gets converted into a {@link Point} object and is public exposed as such.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package com.mapbox.api.directions.v5.models;
2+
3+
import com.mapbox.core.TestUtils;
4+
import org.junit.Test;
5+
6+
import static org.junit.Assert.*;
7+
8+
public class InterchangeTest extends TestUtils {
9+
10+
private static final String DIRECTIONS_V5_AMENITIES_FIXTURE = "directions_v5_amenities.json";
11+
12+
@Test
13+
public void sanity() throws Exception {
14+
Interchange interchange = Interchange.builder()
15+
.name("IC TEST NAME")
16+
.build();
17+
assertNotNull(interchange);
18+
}
19+
20+
@Test
21+
public void whenInterchangeNameNull() {
22+
Interchange interchange = Interchange.builder()
23+
.name(null)
24+
.build();
25+
assertNotNull(interchange);
26+
}
27+
28+
@Test
29+
public void interchangeNameNull() {
30+
Interchange interchange = Interchange.builder().build();
31+
assertNull(interchange.name());
32+
}
33+
34+
@Test
35+
public void serializableObject() throws Exception {
36+
Interchange expected = Interchange.builder()
37+
.name("IC TEST NAME")
38+
.build();
39+
40+
Interchange actual = deserialize(
41+
TestUtils.serialize(expected),
42+
Interchange.class
43+
);
44+
45+
assertEquals(expected, actual);
46+
}
47+
48+
@Test
49+
public void toFromJson() {
50+
Interchange expected = Interchange.builder()
51+
.name("IC TEST NAME")
52+
.build();
53+
54+
Interchange actual = Interchange.fromJson(expected.toJson());
55+
56+
assertEquals(expected, actual);
57+
}
58+
59+
@Test
60+
public void fromJson_correctlyBuildsFromJson() throws Exception {
61+
String json = loadJsonFixture(DIRECTIONS_V5_AMENITIES_FIXTURE);
62+
DirectionsResponse response = DirectionsResponse.fromJson(json);
63+
64+
Interchange interchange = response.routes().get(0).legs().get(0).steps().get(1).intersections().get(0).interchange();
65+
66+
assertNotNull(interchange);
67+
assertEquals("IC NAME", interchange.name());
68+
}
69+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package com.mapbox.api.directions.v5.models;
2+
3+
import com.mapbox.core.TestUtils;
4+
import org.junit.Test;
5+
6+
import static org.junit.Assert.*;
7+
8+
public class JunctionTest extends TestUtils {
9+
10+
private static final String DIRECTIONS_V5_AMENITIES_FIXTURE = "directions_v5_amenities.json";
11+
12+
@Test
13+
public void sanity() throws Exception {
14+
Junction junction = Junction.builder()
15+
.name("JCT TEST NAME")
16+
.build();
17+
assertNotNull(junction);
18+
}
19+
20+
@Test
21+
public void whenJunctionNameNull() {
22+
Junction junction = Junction.builder()
23+
.name(null)
24+
.build();
25+
assertNotNull(junction);
26+
}
27+
28+
@Test
29+
public void junctionNameNull() {
30+
Junction junction = Junction.builder().build();
31+
assertNull(junction.name());
32+
}
33+
34+
@Test
35+
public void serializableObject() throws Exception {
36+
Junction expected = Junction.builder()
37+
.name("JCT TEST NAME")
38+
.build();
39+
40+
Junction actual = deserialize(
41+
TestUtils.serialize(expected),
42+
Junction.class
43+
);
44+
45+
assertEquals(expected, actual);
46+
}
47+
48+
@Test
49+
public void toFromJson() {
50+
Junction expected = Junction.builder()
51+
.name("JCT TEST NAME")
52+
.build();
53+
54+
Junction actual = Junction.fromJson(expected.toJson());
55+
56+
assertEquals(expected, actual);
57+
}
58+
59+
@Test
60+
public void fromJson_correctlyBuildsFromJson() throws Exception {
61+
String json = loadJsonFixture(DIRECTIONS_V5_AMENITIES_FIXTURE);
62+
DirectionsResponse response = DirectionsResponse.fromJson(json);
63+
64+
Junction junction = response.routes().get(0).legs().get(0).steps().get(1).intersections().get(0).junction();
65+
66+
assertNotNull(junction);
67+
assertEquals("JCT NAME", junction.name());
68+
}
69+
}

0 commit comments

Comments
 (0)