Skip to content

Commit a6fb521

Browse files
NAVAND-1547: new annotations (#1567)
1 parent 5ab857c commit a6fb521

File tree

4 files changed

+6878
-1
lines changed

4 files changed

+6878
-1
lines changed

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,17 @@ public final class DirectionsCriteria {
152152
@SuppressWarnings("checkstyle:javadocvariable")
153153
public static final String ANNOTATION_TRAFFIC_TENDENCY = "traffic_tendency";
154154

155+
/**
156+
* The freeflow value conveys the typical speed at low traffic times of day
157+
* such as nights or early mornings.
158+
*/
159+
public static final String ANNOTATION_FREEFLOW_SPEED = "freeflow_speed";
160+
161+
/**
162+
* The current speed value conveys the instantaneous (at the time of the request) speed.
163+
*/
164+
public static final String ANNOTATION_CURRENT_SPEED = "current_speed";
165+
155166
/**
156167
* Exclude all tolls along the returned directions route.
157168
*
@@ -528,7 +539,9 @@ private DirectionsCriteria() {
528539
ANNOTATION_CONGESTION_NUMERIC,
529540
ANNOTATION_MAXSPEED,
530541
ANNOTATION_CLOSURE,
531-
ANNOTATION_TRAFFIC_TENDENCY
542+
ANNOTATION_TRAFFIC_TENDENCY,
543+
ANNOTATION_CURRENT_SPEED,
544+
ANNOTATION_FREEFLOW_SPEED
532545
})
533546
public @interface AnnotationCriteria {
534547
}

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,30 @@ public static Builder builder() {
105105
@SerializedName("traffic_tendency")
106106
public abstract List<Integer> trafficTendency();
107107

108+
/**
109+
* The speed may be either a positive integer in kilometers per hour
110+
* or `null` where attribution is missing.
111+
* The freeflow value conveys the typical speed at low traffic times of day
112+
* such as nights or early mornings.
113+
* Available only for `mapbox/driving` and `mapbox/driving-traffic` profiles.
114+
* @return The freeflow speed for each line segment along the route geometry.
115+
*/
116+
@Nullable
117+
@SerializedName("freeflow_speed")
118+
public abstract List<Integer> freeflowSpeed();
119+
120+
/**
121+
* The speed may be either a positive integer in kilometers per hour
122+
* or `null` where attribution is missing.
123+
* The current speed value conveys the instantaneous
124+
* (at the time of the request) speed.
125+
* Available only for `mapbox/driving` and `mapbox/driving-traffic` profiles.
126+
* @return The current speed for each line segment along the route geometry.
127+
*/
128+
@Nullable
129+
@SerializedName("current_speed")
130+
public abstract List<Integer> currentSpeed();
131+
108132
/**
109133
* Convert the current {@link LegAnnotation} to its builder holding the currently assigned
110134
* values. This allows you to modify a single property and then rebuild the object resulting in
@@ -219,6 +243,24 @@ public abstract static class Builder extends DirectionsJsonObject.Builder<Builde
219243
@NonNull
220244
public abstract Builder trafficTendency(@Nullable List<Integer> trafficTendency);
221245

246+
/**
247+
* @param freeflowSpeed speed for each line segment along the route geometry.
248+
* The speed may be either a positive integer in kilometers per hour or
249+
* `null` where attribution is missing.
250+
* @return this builder for chaining options together
251+
*/
252+
@NonNull
253+
public abstract Builder freeflowSpeed(@Nullable List<Integer> freeflowSpeed);
254+
255+
/**
256+
* @param currentSpeed The current speed for each line segment along the route geometry.
257+
* The speed may be either a positive integer in kilometers per hour
258+
* or `null` where attribution is missing.
259+
* @return this builder for chaining options together
260+
*/
261+
@NonNull
262+
public abstract Builder currentSpeed(@Nullable List<Integer> currentSpeed);
263+
222264
/**
223265
* Build a new {@link LegAnnotation} object.
224266
*

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

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.mapbox.api.directions.v5.models;
22

3+
import static java.nio.charset.StandardCharsets.UTF_8;
34
import static org.junit.Assert.assertEquals;
45
import static org.junit.Assert.assertNotNull;
56

@@ -8,11 +9,14 @@
89
import com.mapbox.core.TestUtils;
910
import org.junit.Test;
1011

12+
import java.io.IOException;
13+
import java.io.InputStream;
1114
import java.util.ArrayList;
1215
import java.util.Arrays;
1316
import java.util.HashMap;
1417
import java.util.List;
1518
import java.util.Map;
19+
import java.util.Scanner;
1620

1721
public class LegAnnotationTest extends TestUtils {
1822

@@ -105,12 +109,36 @@ public void testToFromJson1() {
105109
0,
106110
0);
107111

112+
List<Integer> freeflowSpeed = Arrays.asList(
113+
0,
114+
1,
115+
2,
116+
3,
117+
4,
118+
null,
119+
0,
120+
9
121+
);
122+
123+
List<Integer> currentSpeed = Arrays.asList(
124+
0,
125+
4,
126+
2,
127+
7,
128+
4,
129+
null,
130+
0,
131+
2
132+
);
133+
108134
LegAnnotation annotation = LegAnnotation.builder()
109135
.congestionNumeric(congestionNumericList)
110136
.distance(distanceList)
111137
.duration(durationList)
112138
.speed(speedList)
113139
.congestion(congestionList)
140+
.freeflowSpeed(freeflowSpeed)
141+
.currentSpeed(currentSpeed)
114142
.unrecognizedJsonProperties(unrecognizedProperties)
115143
.build();
116144

@@ -120,4 +148,35 @@ public void testToFromJson1() {
120148

121149
assertEquals(annotation, annotationFromJson);
122150
}
151+
152+
@Test
153+
public void testExampleResponse() throws IOException {
154+
String responseString = loadJsonFixture("directions_freeflow_speed_and_current_speed_annotations.json");
155+
DirectionsResponse response = DirectionsResponse.fromJson(responseString);
156+
157+
List<Integer> freeflowSpeed = response.routes().get(0).legs().get(0).annotation().freeflowSpeed();
158+
assertEquals(341, freeflowSpeed.size());
159+
assertEquals((Integer) 11, freeflowSpeed.get(0));
160+
assertEquals(null, freeflowSpeed.get(24));
161+
assertEquals((Integer) 27, freeflowSpeed.get(113));
162+
assertEquals((Integer) 8, freeflowSpeed.get(340));
163+
164+
List<Integer> currentSpeed = response.routes().get(0).legs().get(0).annotation().currentSpeed();
165+
assertEquals(341, currentSpeed.size());
166+
assertEquals(null, currentSpeed.get(0));
167+
assertEquals((Integer) 5, currentSpeed.get(33));
168+
assertEquals((Integer) 9, currentSpeed.get(317));
169+
assertEquals(null, currentSpeed.get(340));
170+
}
171+
172+
protected String loadJsonFixture(String filename) throws IOException {
173+
InputStream inputStream = getResourceInputSteam(filename);
174+
Scanner scanner = new Scanner(inputStream, UTF_8.name()).useDelimiter("\\A");
175+
return scanner.hasNext() ? scanner.next() : "";
176+
}
177+
178+
private InputStream getResourceInputSteam(String filename) {
179+
ClassLoader classLoader = getClass().getClassLoader();
180+
return classLoader.getResourceAsStream(filename);
181+
}
123182
}

0 commit comments

Comments
 (0)