From 3bed27a64a0b934f5bf8a9b2ce2b18725b6d9a56 Mon Sep 17 00:00:00 2001 From: Yury Kanetski Date: Mon, 5 Sep 2022 14:49:46 +0200 Subject: [PATCH] RouteLegRefresh: added `List` (#1489) * RouteLegRefresh: added `List` --- CHANGELOG.md | 3 ++- .../v1/models/RouteLegRefresh.java | 19 ++++++++++++++++ .../DirectionsRefreshResponseTest.java | 3 ++- .../RouteLegRefreshTest.java | 22 +++++++++++++++++++ .../test/resources/directions_refresh_v1.json | 6 +++++ 5 files changed, 51 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f33f403d7..d5cd8b198 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,8 @@ Mapbox welcomes participation and contributions from everyone. ### main -- Added `TurfSimplify#simplify` method to simplify `LineString` using Ramer-Douglas-Peucker algorithm. [1486](https://github.com/mapbox/mapbox-java/pull/1486) +- Added `TurfSimplify#simplify` method to simplify `LineString` using Ramer-Douglas-Peucker algorithm. [#1486](https://github.com/mapbox/mapbox-java/pull/1486) +- Added `List` to `RouteLegRefresh` to make `DirectionsRoute#RouteLeg` refreshed with closures. [#1489](https://github.com/mapbox/mapbox-java/pull/1489) ### v6.8.0-beta.3 - September 1, 2022 - Added `subTypes` to `BannerComponents`. [#1485](https://github.com/mapbox/mapbox-java/pull/1485) diff --git a/services-directions-refresh-models/src/main/java/com/mapbox/api/directionsrefresh/v1/models/RouteLegRefresh.java b/services-directions-refresh-models/src/main/java/com/mapbox/api/directionsrefresh/v1/models/RouteLegRefresh.java index df8be0c7f..6e2b78932 100644 --- a/services-directions-refresh-models/src/main/java/com/mapbox/api/directionsrefresh/v1/models/RouteLegRefresh.java +++ b/services-directions-refresh-models/src/main/java/com/mapbox/api/directionsrefresh/v1/models/RouteLegRefresh.java @@ -7,6 +7,7 @@ import com.google.gson.GsonBuilder; import com.google.gson.TypeAdapter; import com.mapbox.api.directions.v5.DirectionsAdapterFactory; +import com.mapbox.api.directions.v5.models.Closure; import com.mapbox.api.directions.v5.models.DirectionsWaypoint; import com.mapbox.api.directions.v5.models.Incident; import com.mapbox.api.directions.v5.models.LegAnnotation; @@ -47,6 +48,15 @@ public static Builder builder() { @Nullable public abstract LegAnnotation annotation(); + + /** + * A list of closures that occur on this leg. + * + * @return a list of {@link Closure} + */ + @Nullable + public abstract List closures(); + /** * Convert the current {@link RouteLegRefresh} to its builder holding the currently assigned * values. This allows you to modify a single property and then rebuild the object resulting in @@ -108,6 +118,15 @@ public abstract static class Builder { @NonNull public abstract Builder annotation(@Nullable LegAnnotation annotation); + /** + * A list of closures that occur on this leg. + * + * @param closures a list of {@link Closure} + * @return this builder for chaining options together + */ + @NonNull + public abstract Builder closures(@Nullable List closures); + /** * Build a new {@link RouteLegRefresh} object. * diff --git a/services-directions-refresh-models/src/test/java/com.mapbox.api.directionsrefresh.v1.models/DirectionsRefreshResponseTest.java b/services-directions-refresh-models/src/test/java/com.mapbox.api.directionsrefresh.v1.models/DirectionsRefreshResponseTest.java index e01eb97b3..979db942d 100644 --- a/services-directions-refresh-models/src/test/java/com.mapbox.api.directionsrefresh.v1.models/DirectionsRefreshResponseTest.java +++ b/services-directions-refresh-models/src/test/java/com.mapbox.api.directionsrefresh.v1.models/DirectionsRefreshResponseTest.java @@ -37,8 +37,9 @@ public void testSerialization() throws IOException { assertNotNull(directionsRefreshResponse.route().legs().get(0)); assertNotNull(directionsRefreshResponse.route().legs().get(0).annotation()); assertTrue(directionsRefreshResponse.route().legs().get(0).annotation().congestion().size() > 0); - assertTrue(directionsRefreshResponse.route().legs().get(0).incidents().size() > 0); assertTrue(directionsRefreshResponse.route().legs().get(0).annotation().trafficTendency().size() > 0); + assertTrue(directionsRefreshResponse.route().legs().get(0).incidents().size() > 0); + assertTrue(directionsRefreshResponse.route().legs().get(0).closures().size() > 0); } @Test diff --git a/services-directions-refresh-models/src/test/java/com.mapbox.api.directionsrefresh.v1.models/RouteLegRefreshTest.java b/services-directions-refresh-models/src/test/java/com.mapbox.api.directionsrefresh.v1.models/RouteLegRefreshTest.java index 9bfe5c50c..a7a630f09 100644 --- a/services-directions-refresh-models/src/test/java/com.mapbox.api.directionsrefresh.v1.models/RouteLegRefreshTest.java +++ b/services-directions-refresh-models/src/test/java/com.mapbox.api.directionsrefresh.v1.models/RouteLegRefreshTest.java @@ -4,6 +4,7 @@ import static org.junit.Assert.assertNotNull; import com.mapbox.api.directions.v5.DirectionsCriteria; +import com.mapbox.api.directions.v5.models.Closure; import com.mapbox.api.directions.v5.models.Congestion; import com.mapbox.api.directions.v5.models.Incident; import com.mapbox.api.directions.v5.models.LegAnnotation; @@ -38,6 +39,14 @@ public void sanity() { .build() ) ) + .closures( + Arrays.asList( + Closure.builder() + .geometryIndexStart(1) + .geometryIndexEnd(2) + .build() + ) + ) .build(); } @@ -111,6 +120,17 @@ public void fromJson() { .build() ); + List closures = Arrays.asList( + Closure.builder() + .geometryIndexStart(2) + .geometryIndexEnd(4) + .build(), + Closure.builder() + .geometryIndexStart(10) + .geometryIndexEnd(20) + .build() + ); + RouteLegRefresh routeLegRefresh = RouteLegRefresh.builder() .annotation( LegAnnotation.builder() @@ -123,6 +143,7 @@ public void fromJson() { .build() ) .incidents(incidents) + .closures(closures) .build(); String json = routeLegRefresh.toJson(); @@ -130,6 +151,7 @@ public void fromJson() { assertNotNull(routeLegRefresh.annotation()); assertNotNull(routeLegRefresh.incidents()); + assertNotNull(routeLegRefresh.closures()); assertEquals(routeLegRefresh, fromJson); } diff --git a/services-directions-refresh-models/src/test/resources/directions_refresh_v1.json b/services-directions-refresh-models/src/test/resources/directions_refresh_v1.json index f917d2364..88bc4acd6 100644 --- a/services-directions-refresh-models/src/test/resources/directions_refresh_v1.json +++ b/services-directions-refresh-models/src/test/resources/directions_refresh_v1.json @@ -3,6 +3,12 @@ "route": { "legs": [ { + "closures": [ + { + "geometry_index_end": 21, + "geometry_index_start": 13 + } + ], "incidents": [ { "length": 288,