Skip to content

Commit d7b224d

Browse files
authored
[NAVAND-6128] Expose step intersection duration as Double (#1622)
1 parent 63fe29d commit d7b224d

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
Mapbox welcomes participation and contributions from everyone.
44

55
### main
6+
- Add `StepIntersection#duration` (previously available through `StepIntersection#getUnrecognizedProperty("duration")`)
67

78
### v7.7.0 - August 13, 2025
89
- Add `RouteLeg#notifications`

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,18 @@ public Point location() {
350350
@SerializedName("merging_area")
351351
public abstract MergingArea mergingArea();
352352

353+
354+
/**
355+
* The time required, in seconds, to traverse the intersection.
356+
* Only available on the driving profile.
357+
*
358+
* @return The time required, in seconds, to traverse the intersection.
359+
* Only available on the driving profile.
360+
*/
361+
@Nullable
362+
@SerializedName("duration")
363+
public abstract Double duration();
364+
353365
/**
354366
* Convert the current {@link StepIntersection} to its builder holding the currently assigned
355367
* values. This allows you to modify a single property and then rebuild the object resulting in
@@ -713,6 +725,16 @@ public abstract static class Builder extends DirectionsJsonObject.Builder<Builde
713725
@NonNull
714726
public abstract Builder mergingArea(@Nullable MergingArea mergingArea);
715727

728+
/**
729+
* The time required, in seconds, to traverse the intersection.
730+
* Only available on the driving profile.
731+
*
732+
* @param duration The time required, in seconds, to traverse the intersection
733+
* @return this builder for chaining options together
734+
*/
735+
@NonNull
736+
public abstract Builder duration(@Nullable Double duration);
737+
716738
/**
717739
* Build a new {@link StepIntersection} object.
718740
*

services-directions-models/src/test/java/com/mapbox/api/directions/v5/models/StepIntersectionTest.java

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public void testToFromJson1() {
5959
.junction(Junction.builder().name("jct_name").build())
6060
.interchange(Interchange.builder().name("ic_name").build())
6161
.mergingArea(MergingArea.builder().type(MergingArea.TYPE_FROM_LEFT).build())
62+
.duration(12.34)
6263
.build();
6364

6465
String jsonString = intersection.toJson();
@@ -101,7 +102,8 @@ public void testFromJson() {
101102
+ "\"traffic_signal\": true,"
102103
+ "\"stop_sign\": true,"
103104
+ "\"merging_area\": {\"type\": \"from_right\"},"
104-
+ "\"yield_sign\": true"
105+
+ "\"yield_sign\": true,"
106+
+ "\"duration\": 12.34"
105107
+ "}";
106108

107109
StepIntersection stepIntersection = StepIntersection.fromJson(stepIntersectionJsonString);
@@ -114,6 +116,7 @@ public void testFromJson() {
114116
assertTrue(stepIntersection.stopSign());
115117
assertTrue(stepIntersection.yieldSign());
116118
assertEquals(MergingArea.builder().type(MergingArea.TYPE_FROM_RIGHT).build(), stepIntersection.mergingArea());
119+
assertEquals(12.34, stepIntersection.duration(), 0.0001);
117120

118121
Point location = stepIntersection.location();
119122
assertEquals(13.426579, location.longitude(), 0.0001);
@@ -222,6 +225,33 @@ public void testNullInterchange() {
222225
compareJson(stepIntersectionJsonString, jsonStr);
223226
}
224227

228+
@Test
229+
public void testDuration() {
230+
String stepIntersectionJsonString = "{"
231+
+ "\"location\": [ 13.426579, 52.508068 ],"
232+
+ "\"duration\": 12.34"
233+
+ "}";
234+
235+
StepIntersection stepIntersection = StepIntersection.fromJson(stepIntersectionJsonString);
236+
237+
Assert.assertEquals(12.34, stepIntersection.duration(), 0.0001);
238+
String jsonStr = stepIntersection.toJson();
239+
compareJson(stepIntersectionJsonString, jsonStr);
240+
}
241+
242+
@Test
243+
public void testNullDuration() {
244+
String stepIntersectionJsonString = "{"
245+
+ "\"location\": [ 13.426579, 52.508068 ]"
246+
+ "}";
247+
248+
StepIntersection stepIntersection = StepIntersection.fromJson(stepIntersectionJsonString);
249+
250+
Assert.assertNull(stepIntersection.duration());
251+
String jsonStr = stepIntersection.toJson();
252+
compareJson(stepIntersectionJsonString, jsonStr);
253+
}
254+
225255
@Test
226256
public void testMergingArea() {
227257
String stepIntersectionJsonString = "{"

0 commit comments

Comments
 (0)