Skip to content

Commit 11b5d4c

Browse files
authored
addSnappingClosure fun (#1253)
1 parent 222899e commit 11b5d4c

2 files changed

Lines changed: 65 additions & 8 deletions

File tree

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

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,6 +1046,22 @@ public Builder waypointTargets(@NonNull List<Point> waypointTargets) {
10461046

10471047
abstract Builder waypointTargets(@Nullable String waypointTargets);
10481048

1049+
/**
1050+
* A point to specify drop-off locations that are distinct from the locations specified in
1051+
* coordinates.
1052+
* The number of waypoint targets must be the same as the number of coordinates,
1053+
* but you can skip a coordinate with a null value.
1054+
* Must be used with steps=true.
1055+
*
1056+
* @param waypointTarget a point for drop-off locations
1057+
* @return this builder for chaining options together
1058+
* @since 4.3.0
1059+
*/
1060+
public Builder addWaypointTarget(@Nullable Point waypointTarget) {
1061+
this.waypointTargets.add(waypointTarget);
1062+
return this;
1063+
}
1064+
10491065
/**
10501066
* A list of booleans affecting snapping of waypoint locations to road segments.
10511067
* If true, road segments closed due to live-traffic closures will be considered for snapping.
@@ -1066,18 +1082,20 @@ public Builder snappingClosures(@NonNull List<Boolean> snappingClosures) {
10661082
abstract Builder snappingClosures(@Nullable String snappingClosures);
10671083

10681084
/**
1069-
* A point to specify drop-off locations that are distinct from the locations specified in
1085+
* A boolean affecting snapping of waypoint location to the road segment.
1086+
* If true, road segment closed due to live-traffic closure will be considered for snapping.
1087+
* If false, it will not be considered for snapping.
1088+
* If provided, the number of snappingClosures must be the same as the number of
10701089
* coordinates.
1071-
* The number of waypoint targets must be the same as the number of coordinates,
1072-
* but you can skip a coordinate with a null value.
1073-
* Must be used with steps=true.
1090+
* You can skip a coordinate with null value.
1091+
* Must be used with {@link DirectionsCriteria#PROFILE_DRIVING_TRAFFIC}
10741092
*
1075-
* @param waypointTarget a point for drop-off locations
1093+
* @param snappingClosure a boolean affecting snapping of waypoint location to the road segment.
10761094
* @return this builder for chaining options together
1077-
* @since 4.3.0
1095+
* @since 5.9.0
10781096
*/
1079-
public Builder addWaypointTarget(@Nullable Point waypointTarget) {
1080-
this.waypointTargets.add(waypointTarget);
1097+
public Builder addSnappingClosure(@Nullable Boolean snappingClosure) {
1098+
this.snappingClosures.add(snappingClosure);
10811099
return this;
10821100
}
10831101

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1436,6 +1436,45 @@ public void snappingClosuresList() throws Exception {
14361436
mapboxDirections.cloneCall().request().url().queryParameter("snapping_include_closures"));
14371437
}
14381438

1439+
@Test
1440+
public void addSnappingClosure() throws Exception {
1441+
MapboxDirections mapboxDirections = MapboxDirections.builder()
1442+
.origin(Point.fromLngLat(1.0, 1.0))
1443+
.destination(Point.fromLngLat(4.0, 4.0))
1444+
.baseUrl("https://foobar.com")
1445+
.accessToken(ACCESS_TOKEN)
1446+
.addSnappingClosure(null)
1447+
.addSnappingClosure(true)
1448+
.build();
1449+
1450+
assertNotNull(mapboxDirections);
1451+
assertEquals(";true",
1452+
mapboxDirections.cloneCall().request().url().queryParameter("snapping_include_closures"));
1453+
}
1454+
1455+
@Test
1456+
public void addSnappingClosures() throws Exception {
1457+
List<Boolean> snappingClosures = new ArrayList<>();
1458+
snappingClosures.add(false);
1459+
snappingClosures.add(false);
1460+
1461+
MapboxDirections mapboxDirections = MapboxDirections.builder()
1462+
.origin(Point.fromLngLat(1.0, 1.0))
1463+
.addWaypoint(Point.fromLngLat(2.0, 2.0))
1464+
.addWaypoint(Point.fromLngLat(2.0, 3.0))
1465+
.destination(Point.fromLngLat(4.0, 4.0))
1466+
.baseUrl("https://foobar.com")
1467+
.accessToken(ACCESS_TOKEN)
1468+
.snappingClosures(snappingClosures)
1469+
.addSnappingClosure(null)
1470+
.addSnappingClosure(true)
1471+
.build();
1472+
1473+
assertNotNull(mapboxDirections);
1474+
assertEquals("false;false;;true",
1475+
mapboxDirections.cloneCall().request().url().queryParameter("snapping_include_closures"));
1476+
}
1477+
14391478
@Test
14401479
public void snappingClosuresListNotMatchingCoordinates() throws Exception {
14411480
thrown.expect(ServicesException.class);

0 commit comments

Comments
 (0)