Skip to content

Commit

Permalink
RouteLegRefresh: added List<Closure> (#1489)
Browse files Browse the repository at this point in the history
* RouteLegRefresh: added `List<Closure>`
  • Loading branch information
RingerJK authored Sep 5, 2022
1 parent 30d7171 commit 3bed27a
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<Closure>` 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Closure> 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
Expand Down Expand Up @@ -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<Closure> closures);

/**
* Build a new {@link RouteLegRefresh} object.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -38,6 +39,14 @@ public void sanity() {
.build()
)
)
.closures(
Arrays.asList(
Closure.builder()
.geometryIndexStart(1)
.geometryIndexEnd(2)
.build()
)
)
.build();
}

Expand Down Expand Up @@ -111,6 +120,17 @@ public void fromJson() {
.build()
);

List<Closure> closures = Arrays.asList(
Closure.builder()
.geometryIndexStart(2)
.geometryIndexEnd(4)
.build(),
Closure.builder()
.geometryIndexStart(10)
.geometryIndexEnd(20)
.build()
);

RouteLegRefresh routeLegRefresh = RouteLegRefresh.builder()
.annotation(
LegAnnotation.builder()
Expand All @@ -123,13 +143,15 @@ public void fromJson() {
.build()
)
.incidents(incidents)
.closures(closures)
.build();

String json = routeLegRefresh.toJson();
RouteLegRefresh fromJson = RouteLegRefresh.fromJson(json);

assertNotNull(routeLegRefresh.annotation());
assertNotNull(routeLegRefresh.incidents());
assertNotNull(routeLegRefresh.closures());
assertEquals(routeLegRefresh, fromJson);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
"route": {
"legs": [
{
"closures": [
{
"geometry_index_end": 21,
"geometry_index_start": 13
}
],
"incidents": [
{
"length": 288,
Expand Down

0 comments on commit 3bed27a

Please sign in to comment.