Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Mapbox welcomes participation and contributions from everyone.

### main
- Added `Incident.affectedRoadNames`. [#1457](https://github.com/mapbox/mapbox-java/pull/1457)

### v6.6.0 - Jun 30, 2022
- Fixed `RouteOptions#toUrl` for a case when `RouteOptions` was deserialized from a json generated by an old version of mapbox-java. [#1447](https://github.com/mapbox/mapbox-java/pull/1447)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,13 @@ public abstract class Incident extends DirectionsJsonObject {
@SerializedName("num_lanes_blocked")
public abstract Integer numLanesBlocked();

/**
* List of roads names affected by the incident.
*/
@Nullable
@SerializedName("affected_road_names")
public abstract List<String> affectedRoadNames();

/**
* Create a new instance of this class by using the {@link Incident.Builder} class.
*
Expand Down Expand Up @@ -332,6 +339,7 @@ public abstract static class Builder extends DirectionsJsonObject.Builder<Builde
*
* @param id String
*/
@NonNull
public abstract Builder id(@NonNull String id);

/**
Expand All @@ -340,6 +348,7 @@ public abstract static class Builder extends DirectionsJsonObject.Builder<Builde
* @param type incident type
* @see IncidentType
*/
@NonNull
public abstract Builder type(@Nullable @IncidentType String type);

/**
Expand All @@ -348,27 +357,31 @@ public abstract static class Builder extends DirectionsJsonObject.Builder<Builde
*
* @param closed is way closed
*/
@NonNull
public abstract Builder closed(@Nullable Boolean closed);

/**
* Quantitative descriptor of congestion.
*
* @param congestion congestion
*/
@NonNull
public abstract Builder congestion(@Nullable Congestion congestion);

/**
* Human-readable description of the incident suitable for displaying to the users.
*
* @param description incident description
*/
@NonNull
public abstract Builder description(@Nullable String description);

/**
* Human-readable long description of the incident suitable for displaying to the users.
*
* @param longDescription incident long description
*/
@NonNull
public abstract Builder longDescription(@Nullable String longDescription);

/**
Expand All @@ -377,20 +390,23 @@ public abstract static class Builder extends DirectionsJsonObject.Builder<Builde
* @param impact impact type
* @see ImpactType
*/
@NonNull
public abstract Builder impact(@Nullable @ImpactType String impact);

/**
* Sub-type of the incident.
*
* @param subType syp-type
*/
@NonNull
public abstract Builder subType(@Nullable String subType);

/**
* Sub-type-specific description.
*
* @param subTypeDescription sub-type description
*/
@NonNull
public abstract Builder subTypeDescription(@Nullable String subTypeDescription);

/**
Expand All @@ -399,41 +415,47 @@ public abstract static class Builder extends DirectionsJsonObject.Builder<Builde
* @param alertcCodes list of alert codes
* @see <a href="https://www.iso.org/standard/59231.html">AlertC</a>
*/
@NonNull
public abstract Builder alertcCodes(@Nullable List<Integer> alertcCodes);

/**
* Incident's geometry index start point.
*
* @param geometryIndexStart start index
*/
@NonNull
public abstract Builder geometryIndexStart(@Nullable Integer geometryIndexStart);

/**
* Incident's geometry index end point.
*
* @param geometryIndexEnd end index
*/
@NonNull
public abstract Builder geometryIndexEnd(@Nullable Integer geometryIndexEnd);

/**
* Time the incident was created/updated in ISO8601 format.
*
* @param creationTime ISO8601 format
*/
@NonNull
public abstract Builder creationTime(@Nullable String creationTime);

/**
* Start time in ISO8601 format.
*
* @param startTime ISO8601 format
*/
@NonNull
public abstract Builder startTime(@Nullable String startTime);

/**
* End time in ISO8601 format.
*
* @param endTime ISO8601 format
*/
@NonNull
public abstract Builder endTime(@Nullable String endTime);

/**
Expand All @@ -442,6 +464,7 @@ public abstract static class Builder extends DirectionsJsonObject.Builder<Builde
*
* @param countryCodeAlpha2 2 letter country code
*/
@NonNull
public abstract Builder countryCodeAlpha2(@Nullable String countryCodeAlpha2);

/**
Expand All @@ -450,27 +473,38 @@ public abstract static class Builder extends DirectionsJsonObject.Builder<Builde
*
* @param countryCodeAlpha3 3 letter country code
*/
@NonNull
public abstract Builder countryCodeAlpha3(@Nullable String countryCodeAlpha3);

/**
* A list of lanes that are blocked by the incident.
*
* @param lanesBlocked lanes blocked
*/
@NonNull
public abstract Builder lanesBlocked(@Nullable List<String> lanesBlocked);

/**
* The number of items in the {@link Incident#lanesBlocked()} list.
*
* @param numLanesBlocked number lanes blocked
*/
@NonNull
public abstract Builder numLanesBlocked(@Nullable Integer numLanesBlocked);

/**
* Sets list of roads names affected by the incident.
* @param affectedRoadNames list of roads names affected by the incident.
*/
@NonNull
public abstract Builder affectedRoadNames(@Nullable List<String> affectedRoadNames);

/**
* Build a new instance of {@link Incident}.
*
* @return a new instance of {@link Incident}.
*/
@NonNull
public abstract Incident build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,24 @@ public void sanity(){
}

@Test
public void testSerializableObject() throws Exception {
Incident incident = Incident.builder()
.id("some_id")
.alertcCodes(Lists.newArrayList(431, 2123, 934))
.closed(true)
.congestion(Congestion.builder().value(10).build())
.creationTime("2020-11-18T11:34:14Z")
.startTime("2021-11-18T11:32:14Z")
.endTime("2021-11-18T12:12:08Z")
.description("description")
.longDescription("long description")
.geometryIndexStart(1)
.geometryIndexEnd(943)
.impact(Incident.IMPACT_MAJOR)
.subType("sub type")
.subTypeDescription("sub type desc")
.type(Incident.INCIDENT_DISABLED_VEHICLE)
.lanesBlocked(Lists.<String>newArrayList())
.numLanesBlocked(null)
.countryCodeAlpha2("US")
.countryCodeAlpha3("USA")
.build();
public void serialize() throws Exception {
Incident incident = getFilledIncident();
byte[] serialized = TestUtils.serialize(incident);
assertEquals(incident, deserialize(serialized, Incident.class));
}

@Test
public void testSerializableFromJson(){
public void toAndFromJson() {
Incident source = getFilledIncident();

String json = source.toJson();
Incident serialized = Incident.fromJson(json);

assertEquals(source, serialized);
}

@Test
public void deserializeFromJson(){
String json = "{" +
"\"id\": \"15985415522454461962\"," +
"\"type\": \"construction\"," +
Expand All @@ -66,7 +56,8 @@ public void testSerializableFromJson(){
"\"iso_3166_1_alpha2\": US," +
"\"iso_3166_1_alpha3\": USA," +
"\"geometry_index_start\": 805," +
"\"geometry_index_end\": 896" +
"\"geometry_index_end\": 896," +
"\"affected_road_names\": [\"S6/E 28/Obwodnica Trójmiasta\"]" +
"}";

Incident fromJson = Incident.fromJson(json);
Expand All @@ -89,6 +80,7 @@ public void testSerializableFromJson(){
assertEquals(fromJson.countryCodeAlpha2(), "US");
assertEquals(fromJson.countryCodeAlpha3(), "USA");
assertEquals(fromJson.lanesBlocked().size(), 0);
assertEquals(Lists.newArrayList("S6/E 28/Obwodnica Trójmiasta"), fromJson.affectedRoadNames());
assertNull(fromJson.numLanesBlocked());
}

Expand All @@ -97,4 +89,29 @@ private Incident getDefault() {
.id("id")
.build();
}

private Incident getFilledIncident() {
return Incident.builder()
.id("some_id")
.alertcCodes(Lists.newArrayList(431, 2123, 934))
.closed(true)
.congestion(Congestion.builder().value(10).build())
.creationTime("2020-11-18T11:34:14Z")
.startTime("2021-11-18T11:32:14Z")
.endTime("2021-11-18T12:12:08Z")
.description("description")
.longDescription("long description")
.geometryIndexStart(1)
.geometryIndexEnd(943)
.impact(Incident.IMPACT_MAJOR)
.subType("sub type")
.subTypeDescription("sub type desc")
.type(Incident.INCIDENT_DISABLED_VEHICLE)
.lanesBlocked(Lists.<String>newArrayList())
.numLanesBlocked(null)
.countryCodeAlpha2("US")
.countryCodeAlpha3("USA")
.affectedRoadNames(Lists.newArrayList("test1", "test2"))
.build();
}
}