Skip to content

Commit 644552f

Browse files
authored
RouteOptions: added max_weight (#1439)
1 parent 3da6e8a commit 644552f

8 files changed

Lines changed: 53 additions & 1 deletion

File tree

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+
- Added `max_weight` field to `RouteOptions` to provide max vehicle weight, metric tons. [#1439](https://github.com/mapbox/mapbox-java/pull/1439)
67

78
### v6.5.0-beta.5 - May 11, 2022
89
- Added `TollCollection#name` field which contains a name of the toll booth/gantry, when available. [#1432](https://github.com/mapbox/mapbox-java/pull/1432)

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,17 @@ public List<Boolean> snappingIncludeClosuresList() {
798798
@Nullable
799799
public abstract Double maxWidth();
800800

801+
/**
802+
* The max vehicle weight, in metric tons (1000 kg). If this parameter is provided,
803+
* the Directions API will compute a route that includes only roads with a weight limit greater
804+
* than or equal to the max vehicle weight. max_weight must be between 0 and 100 metric tons.
805+
* <p>
806+
* The default value is 2.5 metric tons.
807+
*/
808+
@SerializedName("max_weight")
809+
@Nullable
810+
public abstract Double maxWeight();
811+
801812
/**
802813
* Whether the routes should be refreshable via the directions refresh API.
803814
* <p>
@@ -950,6 +961,7 @@ public URL toUrl(@NonNull String accessToken) {
950961
appendQueryParameter(sb, "depart_at", departAt());
951962
appendQueryParameter(sb, "max_height", maxHeight());
952963
appendQueryParameter(sb, "max_width", maxWidth());
964+
appendQueryParameter(sb, "max_weight", maxWeight());
953965
appendQueryParameter(sb, "metadata", metadata());
954966

955967
Map<String, SerializableJsonElement> unrecognized = unrecognized();
@@ -1888,6 +1900,19 @@ public Builder snappingIncludeClosuresList(@Nullable List<Boolean> snappingClosu
18881900
@NonNull
18891901
public abstract Builder maxWidth(@Nullable @FloatRange(from = 0, to = 10) Double maxWidth);
18901902

1903+
/**
1904+
* The max vehicle weight, in metric tons (1000 kg). If this parameter is provided,
1905+
* the Directions API will compute a route that includes only roads with a weight limit greater
1906+
* than or equal to the max vehicle weight. max_weight must be between 0 and 100 metric tons.
1907+
* <p>
1908+
* The default value is 2.5 metric tons.
1909+
*
1910+
* @param maxWeight max vehicle weight, in tons. Must be between 0 and 100.
1911+
* @return this builder
1912+
*/
1913+
@NonNull
1914+
public abstract Builder maxWeight(@Nullable @FloatRange(from = 0, to = 100) Double maxWeight);
1915+
18911916
/**
18921917
* Whether the routes should be refreshable via the directions refresh API.
18931918
* <p>

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class RouteOptionsTest extends TestUtils {
3232
*/
3333
private static final String ROUTE_OPTIONS_JSON = "route_options_v5.json";
3434
private static final String ROUTE_OPTIONS_URL =
35-
"https://api.mapbox.com/directions/v5/mapbox/driving/-122.4003312,37.7736941;-122.4187529,37.7689715;-122.4255172,37.7775835?access_token=pk.token&geometries=polyline6&alternatives=false&overview=full&radiuses=%3Bunlimited%3B5.1&steps=true&avoid_maneuver_radius=200.0&bearings=0%2C90%3B90%2C0%3B&layers=-42%3B%3B0&continue_straight=false&annotations=congestion%2Cdistance%2Cduration&language=ru&roundabout_exits=false&voice_instructions=true&banner_instructions=true&voice_units=metric&exclude=toll%2Cferry%2Cpoint%2811.0+-22.0%29&include=hot%2Chov2&approaches=%3Bcurb%3B&waypoints=0%3B1%3B2&waypoint_names=%3BSerangoon+Garden+Market+%26+Food+Centre%3BFunky+%26nAmE*&waypoint_targets=%3B12.2%2C21.2%3B&enable_refresh=true&walking_speed=5.11&walkway_bias=-0.2&alley_bias=0.75&snapping_include_closures=%3Bfalse%3Btrue&arrive_by=2021-01-01%27T%2701%3A01&depart_at=2021-02-02%27T%2702%3A02&max_height=1.5&max_width=1.4&metadata=true";
35+
"https://api.mapbox.com/directions/v5/mapbox/driving/-122.4003312,37.7736941;-122.4187529,37.7689715;-122.4255172,37.7775835?access_token=pk.token&geometries=polyline6&alternatives=false&overview=full&radiuses=%3Bunlimited%3B5.1&steps=true&avoid_maneuver_radius=200.0&bearings=0%2C90%3B90%2C0%3B&layers=-42%3B%3B0&continue_straight=false&annotations=congestion%2Cdistance%2Cduration&language=ru&roundabout_exits=false&voice_instructions=true&banner_instructions=true&voice_units=metric&exclude=toll%2Cferry%2Cpoint%2811.0+-22.0%29&include=hot%2Chov2&approaches=%3Bcurb%3B&waypoints=0%3B1%3B2&waypoint_names=%3BSerangoon+Garden+Market+%26+Food+Centre%3BFunky+%26nAmE*&waypoint_targets=%3B12.2%2C21.2%3B&enable_refresh=true&walking_speed=5.11&walkway_bias=-0.2&alley_bias=0.75&snapping_include_closures=%3Bfalse%3Btrue&arrive_by=2021-01-01%27T%2701%3A01&depart_at=2021-02-02%27T%2702%3A02&max_height=1.5&max_width=1.4&max_weight=2.9&metadata=true";
3636
private static final String ACCESS_TOKEN = "pk.token";
3737

3838
private final String optionsJson = loadJsonFixture(ROUTE_OPTIONS_JSON);
@@ -309,6 +309,13 @@ public void maxWidthIsValid_fromJson() {
309309
assertEquals(1.4, options.maxWidth(), 0.000001);
310310
}
311311

312+
@Test
313+
public void maxWeightIsValid_fromJson() {
314+
RouteOptions options = RouteOptions.fromJson(optionsJson);
315+
316+
assertEquals(2.9, options.maxWeight(), 0.000001);
317+
}
318+
312319
@Test
313320
public void enableRefreshIsValid_fromJson() {
314321
RouteOptions options = RouteOptions.fromJson(optionsJson);
@@ -759,6 +766,7 @@ private RouteOptions routeOptions() {
759766
.departAt("2021-02-02'T'02:02")
760767
.maxHeight(1.5)
761768
.maxWidth(1.4)
769+
.maxWeight(2.9)
762770
.snappingIncludeClosures(";false;true")
763771
.user(DirectionsCriteria.PROFILE_DEFAULT_USER)
764772
.enableRefresh(true)
@@ -846,6 +854,7 @@ private RouteOptions routeOptionsList() {
846854
.departAt("2021-02-02'T'02:02")
847855
.maxHeight(1.5)
848856
.maxWidth(1.4)
857+
.maxWeight(2.9)
849858
.snappingIncludeClosuresList(new ArrayList<Boolean>() {{
850859
add(null);
851860
add(false);

services-directions-models/src/test/resources/route_options_v5.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"depart_at": "2021-02-02'T'02:02",
3333
"max_height": 1.5,
3434
"max_width": 1.4,
35+
"max_weight": 2.9,
3536
"enable_refresh": true,
3637
"metadata": true
3738
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ Call<DirectionsResponse> getCall(
9595
@Query("depart_at") String departAt,
9696
@Query("max_height") Double maxHeight,
9797
@Query("max_width") Double maxWidth,
98+
@Query("max_weight") Double maxWeight,
9899
@Query("metadata") Boolean metadata
99100
);
100101

@@ -177,6 +178,7 @@ Call<DirectionsResponse> postCall(
177178
@Field("depart_at") String departAt,
178179
@Field("max_height") Double maxHeight,
179180
@Field("max_width") Double maxWidth,
181+
@Field("max_weight") Double maxWeight,
180182
@Field("metadata") Boolean metadata
181183
);
182184
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ private Call<DirectionsResponse> get() {
107107
routeOptions().departAt(),
108108
routeOptions().maxHeight(),
109109
routeOptions().maxWidth(),
110+
routeOptions().maxWeight(),
110111
routeOptions().metadata()
111112
);
112113
}
@@ -148,6 +149,7 @@ private Call<DirectionsResponse> post() {
148149
routeOptions().departAt(),
149150
routeOptions().maxHeight(),
150151
routeOptions().maxWidth(),
152+
routeOptions().maxWeight(),
151153
routeOptions().metadata()
152154
);
153155
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,17 @@ public void max_width() throws Exception {
754754
mapboxDirections.cloneCall().request().url().queryParameter("max_width"));
755755
}
756756

757+
@Test
758+
public void max_weight() throws Exception {
759+
MapboxDirections mapboxDirections = MapboxDirections.builder()
760+
.accessToken("token")
761+
.routeOptions(routeOptions.toBuilder().baseUrl(mockUrl.toString()).build())
762+
.build();
763+
764+
assertEquals("2.9",
765+
mapboxDirections.cloneCall().request().url().queryParameter("max_weight"));
766+
}
767+
757768
@Test
758769
public void enable_refresh() throws Exception {
759770
MapboxDirections mapboxDirections = MapboxDirections.builder()

services-directions/src/test/resources/route_options_v5.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"depart_at": "2021-02-02'T'02:02",
3333
"max_height": 1.5,
3434
"max_width": 1.4,
35+
"max_weight": 2.9,
3536
"enable_refresh": true,
3637
"metadata": true
3738
}

0 commit comments

Comments
 (0)