Skip to content

Commit 9d971f7

Browse files
fix waypoints apis naming for map matching and directions services - from waypoints to waypoint indices (#962)
1 parent 6e6110a commit 9d971f7

7 files changed

Lines changed: 107 additions & 134 deletions

File tree

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,24 @@ public interface DirectionsService {
3131
* @param steps define if you'd like the route steps
3232
* @param bearings used to filter the road segment the waypoint will be placed on by
3333
* direction and dictates the angle of approach
34-
* @param continueStraight define whether the route should continue straight even if the route
35-
* will be slower
34+
* @param continueStraight define whether the route should continue straight even if the
35+
* route will be slower
3636
* @param annotations an annotations object that contains additional details about each
37-
* line segment along the route geometry. Each entry in an annotations
38-
* field corresponds to a coordinate along the route geometry
37+
* line segment along the route geometry. Each entry in an
38+
* annotations field corresponds to a coordinate along the route
39+
* geometry
3940
* @param language language of returned turn-by-turn text instructions
40-
* @param roundaboutExits Add extra step when roundabouts occur with additional information for
41-
* the user
41+
* @param roundaboutExits Add extra step when roundabouts occur with additional information
42+
* for the user
4243
* @param voiceInstructions request that the response contain voice instruction information,
4344
* useful for navigation
4445
* @param bannerInstructions request that the response contain banner instruction information,
4546
* useful for navigation
4647
* @param voiceUnits voice units
4748
* @param exclude exclude tolls, motorways or more along your route
4849
* @param approaches which side of the road to approach a waypoint
49-
* @param viaWayPoints which input coordinates should be treated as via waypoints
50+
* @param waypointIndices which input coordinates should be treated as waypoints/separate legs.
51+
* Note: coordinate indices not added here act as silent waypoints
5052
* @param waypointNames custom names for waypoints used for the arrival instruction
5153
* @param waypointTargets list of coordinate pairs for drop-off locations
5254
* @return the {@link DirectionsResponse} in a Call wrapper
@@ -74,7 +76,7 @@ Call<DirectionsResponse> getCall(
7476
@Query("voice_units") String voiceUnits,
7577
@Query("exclude") String exclude,
7678
@Query("approaches") String approaches,
77-
@Query("waypoints") String viaWayPoints,
79+
@Query("waypoints") String waypointIndices,
7880
@Query("waypoint_names") String waypointNames,
7981
@Query("waypoint_targets") String waypointTargets
8082
);

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

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ protected Call<DirectionsResponse> initializeCall() {
9292
voiceUnits(),
9393
exclude(),
9494
approaches(),
95-
viaWayPoints(),
95+
waypointIndices(),
9696
waypointNames(),
9797
waypointTargets());
9898
}
@@ -235,6 +235,7 @@ private List<DirectionsRoute> generateRouteOptions(Response<DirectionsResponse>
235235
RouteOptions.builder()
236236
.profile(profile())
237237
.coordinates(coordinates())
238+
.waypointIndices(waypointIndices())
238239
.waypointNames(waypointNames())
239240
.waypointTargets(waypointTargets())
240241
.continueStraight(continueStraight())
@@ -362,7 +363,7 @@ private static String formatWaypointTargets(Point[] waypointTargets) {
362363
abstract String approaches();
363364

364365
@Nullable
365-
abstract String viaWayPoints();
366+
abstract String waypointIndices();
366367

367368
@Nullable
368369
abstract String waypointNames();
@@ -424,7 +425,7 @@ public abstract static class Builder {
424425
private Point destination;
425426
private Point origin;
426427
private String[] approaches;
427-
private Integer[] viaWayPoints;
428+
private Integer[] waypointIndices;
428429
private String[] waypointNames;
429430
private Point[] waypointTargets;
430431

@@ -794,24 +795,25 @@ public Builder addApproaches(String... approaches) {
794795
abstract Builder approaches(@Nullable String approaches);
795796

796797
/**
797-
* Optionally, set which input coordinates should be treated as via way points.
798+
* Optionally, set which input coordinates should be treated as waypoints / separate legs.
799+
* Note: coordinate indices not added here act as silent waypoints
798800
* <p>
799801
* Most useful in combination with steps=true and requests based on traces
800802
* with high sample rates. Can be an index corresponding to any of the input coordinates,
801803
* but must contain the first ( 0 ) and last coordinates' index separated by ; .
802804
* {@link #steps()}
803805
* </p>
804806
*
805-
* @param viaWayPoints integer array of coordinate indices to be used as via way points
807+
* @param waypointIndices integer array of coordinate indices to be used as waypoints
806808
* @return this builder for chaining options together
807809
* @since 4.4.0
808810
*/
809-
public Builder addViaWayPoints(@Nullable @IntRange(from = 0) Integer... viaWayPoints) {
810-
this.viaWayPoints = viaWayPoints;
811+
public Builder addWaypointIndices(@Nullable @IntRange(from = 0) Integer... waypointIndices) {
812+
this.waypointIndices = waypointIndices;
811813
return this;
812814
}
813815

814-
abstract Builder viaWayPoints(@Nullable String viaWayPoints);
816+
abstract Builder waypointIndices(@Nullable String waypointIndices);
815817

816818
/**
817819
* Custom names for waypoints used for the arrival instruction,
@@ -871,30 +873,26 @@ public MapboxDirections build() {
871873
+ " directions API request.");
872874
}
873875

874-
if (viaWayPoints != null) {
875-
if (viaWayPoints.length < 2) {
876+
if (waypointIndices != null) {
877+
if (waypointIndices.length < 2) {
876878
throw new ServicesException(
877-
"Via way points must be a list of at least two indexes separated by ';'");
879+
"Waypoints must be a list of at least two indexes separated by ';'");
878880
}
879-
if (viaWayPoints[0] != 0
880-
|| viaWayPoints[viaWayPoints.length - 1] != coordinates.size() - 1) {
881+
if (waypointIndices[0] != 0 || waypointIndices[waypointIndices.length - 1]
882+
!= coordinates.size() - 1) {
881883
throw new ServicesException(
882-
"Via way points must contain indices of the first and last coordinates"
884+
"Waypoints must contain indices of the first and last coordinates"
883885
);
884886
}
885-
for (int i = 1; i < viaWayPoints.length - 1; i++) {
886-
if (viaWayPoints[i] < 0 || viaWayPoints[i] >= coordinates.size()) {
887+
for (int i = 1; i < waypointIndices.length - 1; i++) {
888+
if (waypointIndices[i] < 0 || waypointIndices[i] >= coordinates.size()) {
887889
throw new ServicesException(
888-
"Via way points index too large (no corresponding coordinate)");
890+
"Waypoints index too large (no corresponding coordinate)");
889891
}
890892
}
891893
}
892894

893895
if (waypointNames != null) {
894-
if (waypointNames.length != coordinates.size()) {
895-
throw new ServicesException("Number of waypoint names must match "
896-
+ " the number of waypoints provided.");
897-
}
898896
final String waypointNamesStr = TextUtils.formatWaypointNames(waypointNames);
899897
waypointNames(waypointNamesStr);
900898
}
@@ -924,7 +922,7 @@ public MapboxDirections build() {
924922
bearing(TextUtils.formatBearing(bearings));
925923
annotation(TextUtils.join(",", annotations));
926924
radius(TextUtils.formatRadiuses(radiuses));
927-
viaWayPoints(TextUtils.join(";", viaWayPoints));
925+
waypointIndices(TextUtils.join(";", waypointIndices));
928926

929927
MapboxDirections directions = autoBuild();
930928

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -268,20 +268,20 @@ public static Builder builder() {
268268
public abstract String approaches();
269269

270270
/**
271-
* Indicates which input coordinates should be treated as via way points.
271+
* Indicates which input coordinates should be treated as waypoints.
272272
* <p>
273273
* Most useful in combination with steps=true and requests based on traces
274274
* with high sample rates. Can be an index corresponding to any of the input coordinates,
275275
* but must contain the first ( 0 ) and last coordinates' index separated by ; .
276276
* {@link #steps()}
277277
* </p>
278278
*
279-
* @return a string representing indices to be used as via way points
279+
* @return a string representing indices to be used as waypoints
280280
* @since 4.4.0
281281
*/
282282
@SerializedName("waypoints")
283283
@Nullable
284-
public abstract String viaWayPoints();
284+
public abstract String waypointIndices();
285285

286286
/**
287287
* Custom names for waypoints used for the arrival instruction in banners and voice instructions,
@@ -558,15 +558,15 @@ public abstract Builder overview(
558558
public abstract Builder approaches(String approaches);
559559

560560
/**
561-
* The same via way points the user originally made when the request was made.
561+
* The same waypoint indices the user originally made when the request was made.
562562
*
563-
* @param indices to be used as via way points
563+
* @param indices to be used as waypoints
564564
* @return this builder for chaining options together
565565
* @since 4.4.0
566566
*/
567567

568568
@Nullable
569-
public abstract Builder viaWayPoints(@Nullable String indices);
569+
public abstract Builder waypointIndices(@Nullable String indices);
570570

571571
/**
572572
* The same waypoint names the user originally made when the request was made.

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

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -231,12 +231,12 @@ public void addWaypoint_doesGetFormattedInUrlCorrectly() throws Exception {
231231
}
232232

233233
@Test
234-
public void waypoints_doesGetFormattedInUrlCorrectly() throws Exception {
234+
public void waypoints_doesGetFormattedInUrlCorrectly() {
235235
MapboxDirections directions = MapboxDirections.builder()
236236
.destination(Point.fromLngLat(13.4930, 9.958))
237237
.addWaypoint(Point.fromLngLat(4.56, 7.89))
238238
.origin(Point.fromLngLat(1.234, 2.345))
239-
.addViaWayPoints(0, 2)
239+
.addWaypointIndices(0, 2)
240240
.accessToken(ACCESS_TOKEN)
241241
.build();
242242
String semicolon = "%3B";
@@ -673,7 +673,7 @@ public void build_exceptionThrownWhenLessThanTwoWaypointsProvided() {
673673
MapboxDirections.builder()
674674
.origin(Point.fromLngLat(2.0, 2.0))
675675
.destination(Point.fromLngLat(4.0, 4.0))
676-
.addViaWayPoints(0)
676+
.addWaypointIndices(0)
677677
.baseUrl("https://foobar.com")
678678
.accessToken(ACCESS_TOKEN)
679679
.build();
@@ -685,7 +685,7 @@ public void build_exceptionThrownWhenWaypointsDoNotStartWith0() {
685685
.origin(Point.fromLngLat(2.0, 2.0))
686686
.addWaypoint(Point.fromLngLat(3.0, 3.0))
687687
.destination(Point.fromLngLat(4.0, 4.0))
688-
.addViaWayPoints(1, 2)
688+
.addWaypointIndices(1, 2)
689689
.baseUrl("https://foobar.com")
690690
.accessToken(ACCESS_TOKEN)
691691
.build();
@@ -697,7 +697,7 @@ public void build_exceptionThrownWhenWaypointDoNotEndWithLast() {
697697
.origin(Point.fromLngLat(2.0, 2.0))
698698
.addWaypoint(Point.fromLngLat(3.0, 3.0))
699699
.destination(Point.fromLngLat(4.0, 4.0))
700-
.addViaWayPoints(0, 1)
700+
.addWaypointIndices(0, 1)
701701
.baseUrl("https://foobar.com")
702702
.accessToken(ACCESS_TOKEN)
703703
.build();
@@ -709,7 +709,7 @@ public void build_exceptionThrownWhenMiddleWaypointsAreWrong() {
709709
.origin(Point.fromLngLat(2.0, 2.0))
710710
.addWaypoint(Point.fromLngLat(3.0, 3.0))
711711
.destination(Point.fromLngLat(4.0, 4.0))
712-
.addViaWayPoints(0, 3, 2)
712+
.addWaypointIndices(0, 3, 2)
713713
.baseUrl("https://foobar.com")
714714
.accessToken(ACCESS_TOKEN)
715715
.build();
@@ -730,22 +730,6 @@ public void sanityWaypointNamesInstructions() throws Exception {
730730
mapboxDirections.cloneCall().request().url().queryParameter("waypoint_names"));
731731
}
732732

733-
@Test
734-
public void build_exceptionThrownWhenWaypointNamesDoNotMatchCoordinates() throws Exception {
735-
thrown.expect(ServicesException.class);
736-
thrown.expectMessage(
737-
startsWith("Number of waypoint names must match"));
738-
MapboxDirections mapboxDirections = MapboxDirections.builder()
739-
.origin(Point.fromLngLat(2.0, 2.0))
740-
.addWaypoint(Point.fromLngLat(2.0, 2.0))
741-
.addWaypoint(Point.fromLngLat(3.0, 3.0))
742-
.destination(Point.fromLngLat(4.0, 4.0))
743-
.addWaypointNames("Home", "Work")
744-
.baseUrl("https://foobar.com")
745-
.accessToken(ACCESS_TOKEN)
746-
.build();
747-
}
748-
749733
@Test
750734
public void testWithWaypointNames() throws Exception {
751735

services-matching/src/main/java/com/mapbox/api/matching/v5/MapMatchingService.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ public interface MapMatchingService {
5959
* @param voiceInstructions whether or not to return
6060
* marked-up text for voice guidance along the route.
6161
* @param voiceUnits voice units
62-
* @param waypoints Which input coordinates should be treated as waypoints.
63-
* @param waypointNames wustom names for waypoints used for the arrival instruction.
62+
* @param waypointIndices which input coordinates should be treated as waypoints/separate legs.
63+
* Note: coordinate indices not added here act as silent waypoints
64+
* @param waypointNames custom names for waypoints used for the arrival instruction.
6465
* @param approaches which side of the road to approach a waypoint.
6566
* @return the MapMatchingResponse in a Call wrapper
6667
* @since 2.0.0
@@ -84,7 +85,7 @@ Call<MapMatchingResponse> getCall(
8485
@Query("banner_instructions") Boolean bannerInstructions,
8586
@Query("voice_instructions") Boolean voiceInstructions,
8687
@Query("voice_units") String voiceUnits,
87-
@Query("waypoints") String waypoints,
88+
@Query("waypoints") String waypointIndices,
8889
@Query("waypoint_names") String waypointNames,
8990
@Query("approaches") String approaches);
9091

@@ -130,8 +131,9 @@ Call<MapMatchingResponse> getCall(
130131
* @param voiceInstructions whether or not to return
131132
* marked-up text for voice guidance along the route.
132133
* @param voiceUnits voice units
133-
* @param waypoints Which input coordinates should be treated as waypoints.
134-
* @param waypointNames wustom names for waypoints used for the arrival instruction.
134+
* @param waypointIndices which input coordinates should be treated as waypoints/separate legs.
135+
* Note: coordinate indices not added here act as silent waypoints
136+
* @param waypointNames custom names for waypoints used for the arrival instruction.
135137
* @param approaches which side of the road to approach a waypoint.
136138
* @return the MapMatchingResponse in a Call wrapper
137139
* @since 4.4.0
@@ -156,7 +158,7 @@ Call<MapMatchingResponse> postCall(
156158
@Field("banner_instructions") Boolean bannerInstructions,
157159
@Field("voice_instructions") Boolean voiceInstructions,
158160
@Field("voice_units") String voiceUnits,
159-
@Field("waypoints") String waypoints,
161+
@Field("waypoints") String waypointIndices,
160162
@Field("waypoint_names") String waypointNames,
161163
@Field("approaches") String approaches);
162164
}

0 commit comments

Comments
 (0)