Skip to content

Commit 54cc7f3

Browse files
authored
affected route names (#1457)
1 parent ca34f46 commit 54cc7f3

3 files changed

Lines changed: 76 additions & 24 deletions

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 `Incident.affectedRoadNames`. [#1457](https://github.com/mapbox/mapbox-java/pull/1457)
67

78
### v6.6.0 - Jun 30, 2022
89
- 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)

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,13 @@ public abstract class Incident extends DirectionsJsonObject {
279279
@SerializedName("num_lanes_blocked")
280280
public abstract Integer numLanesBlocked();
281281

282+
/**
283+
* List of roads names affected by the incident.
284+
*/
285+
@Nullable
286+
@SerializedName("affected_road_names")
287+
public abstract List<String> affectedRoadNames();
288+
282289
/**
283290
* Create a new instance of this class by using the {@link Incident.Builder} class.
284291
*
@@ -332,6 +339,7 @@ public abstract static class Builder extends DirectionsJsonObject.Builder<Builde
332339
*
333340
* @param id String
334341
*/
342+
@NonNull
335343
public abstract Builder id(@NonNull String id);
336344

337345
/**
@@ -340,6 +348,7 @@ public abstract static class Builder extends DirectionsJsonObject.Builder<Builde
340348
* @param type incident type
341349
* @see IncidentType
342350
*/
351+
@NonNull
343352
public abstract Builder type(@Nullable @IncidentType String type);
344353

345354
/**
@@ -348,27 +357,31 @@ public abstract static class Builder extends DirectionsJsonObject.Builder<Builde
348357
*
349358
* @param closed is way closed
350359
*/
360+
@NonNull
351361
public abstract Builder closed(@Nullable Boolean closed);
352362

353363
/**
354364
* Quantitative descriptor of congestion.
355365
*
356366
* @param congestion congestion
357367
*/
368+
@NonNull
358369
public abstract Builder congestion(@Nullable Congestion congestion);
359370

360371
/**
361372
* Human-readable description of the incident suitable for displaying to the users.
362373
*
363374
* @param description incident description
364375
*/
376+
@NonNull
365377
public abstract Builder description(@Nullable String description);
366378

367379
/**
368380
* Human-readable long description of the incident suitable for displaying to the users.
369381
*
370382
* @param longDescription incident long description
371383
*/
384+
@NonNull
372385
public abstract Builder longDescription(@Nullable String longDescription);
373386

374387
/**
@@ -377,20 +390,23 @@ public abstract static class Builder extends DirectionsJsonObject.Builder<Builde
377390
* @param impact impact type
378391
* @see ImpactType
379392
*/
393+
@NonNull
380394
public abstract Builder impact(@Nullable @ImpactType String impact);
381395

382396
/**
383397
* Sub-type of the incident.
384398
*
385399
* @param subType syp-type
386400
*/
401+
@NonNull
387402
public abstract Builder subType(@Nullable String subType);
388403

389404
/**
390405
* Sub-type-specific description.
391406
*
392407
* @param subTypeDescription sub-type description
393408
*/
409+
@NonNull
394410
public abstract Builder subTypeDescription(@Nullable String subTypeDescription);
395411

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

404421
/**
405422
* Incident's geometry index start point.
406423
*
407424
* @param geometryIndexStart start index
408425
*/
426+
@NonNull
409427
public abstract Builder geometryIndexStart(@Nullable Integer geometryIndexStart);
410428

411429
/**
412430
* Incident's geometry index end point.
413431
*
414432
* @param geometryIndexEnd end index
415433
*/
434+
@NonNull
416435
public abstract Builder geometryIndexEnd(@Nullable Integer geometryIndexEnd);
417436

418437
/**
419438
* Time the incident was created/updated in ISO8601 format.
420439
*
421440
* @param creationTime ISO8601 format
422441
*/
442+
@NonNull
423443
public abstract Builder creationTime(@Nullable String creationTime);
424444

425445
/**
426446
* Start time in ISO8601 format.
427447
*
428448
* @param startTime ISO8601 format
429449
*/
450+
@NonNull
430451
public abstract Builder startTime(@Nullable String startTime);
431452

432453
/**
433454
* End time in ISO8601 format.
434455
*
435456
* @param endTime ISO8601 format
436457
*/
458+
@NonNull
437459
public abstract Builder endTime(@Nullable String endTime);
438460

439461
/**
@@ -442,6 +464,7 @@ public abstract static class Builder extends DirectionsJsonObject.Builder<Builde
442464
*
443465
* @param countryCodeAlpha2 2 letter country code
444466
*/
467+
@NonNull
445468
public abstract Builder countryCodeAlpha2(@Nullable String countryCodeAlpha2);
446469

447470
/**
@@ -450,27 +473,38 @@ public abstract static class Builder extends DirectionsJsonObject.Builder<Builde
450473
*
451474
* @param countryCodeAlpha3 3 letter country code
452475
*/
476+
@NonNull
453477
public abstract Builder countryCodeAlpha3(@Nullable String countryCodeAlpha3);
454478

455479
/**
456480
* A list of lanes that are blocked by the incident.
457481
*
458482
* @param lanesBlocked lanes blocked
459483
*/
484+
@NonNull
460485
public abstract Builder lanesBlocked(@Nullable List<String> lanesBlocked);
461486

462487
/**
463488
* The number of items in the {@link Incident#lanesBlocked()} list.
464489
*
465490
* @param numLanesBlocked number lanes blocked
466491
*/
492+
@NonNull
467493
public abstract Builder numLanesBlocked(@Nullable Integer numLanesBlocked);
468494

495+
/**
496+
* Sets list of roads names affected by the incident.
497+
* @param affectedRoadNames list of roads names affected by the incident.
498+
*/
499+
@NonNull
500+
public abstract Builder affectedRoadNames(@Nullable List<String> affectedRoadNames);
501+
469502
/**
470503
* Build a new instance of {@link Incident}.
471504
*
472505
* @return a new instance of {@link Incident}.
473506
*/
507+
@NonNull
474508
public abstract Incident build();
475509
}
476510
}

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

Lines changed: 41 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,24 @@ public void sanity(){
1616
}
1717

1818
@Test
19-
public void testSerializableObject() throws Exception {
20-
Incident incident = Incident.builder()
21-
.id("some_id")
22-
.alertcCodes(Lists.newArrayList(431, 2123, 934))
23-
.closed(true)
24-
.congestion(Congestion.builder().value(10).build())
25-
.creationTime("2020-11-18T11:34:14Z")
26-
.startTime("2021-11-18T11:32:14Z")
27-
.endTime("2021-11-18T12:12:08Z")
28-
.description("description")
29-
.longDescription("long description")
30-
.geometryIndexStart(1)
31-
.geometryIndexEnd(943)
32-
.impact(Incident.IMPACT_MAJOR)
33-
.subType("sub type")
34-
.subTypeDescription("sub type desc")
35-
.type(Incident.INCIDENT_DISABLED_VEHICLE)
36-
.lanesBlocked(Lists.<String>newArrayList())
37-
.numLanesBlocked(null)
38-
.countryCodeAlpha2("US")
39-
.countryCodeAlpha3("USA")
40-
.build();
19+
public void serialize() throws Exception {
20+
Incident incident = getFilledIncident();
4121
byte[] serialized = TestUtils.serialize(incident);
4222
assertEquals(incident, deserialize(serialized, Incident.class));
4323
}
4424

4525
@Test
46-
public void testSerializableFromJson(){
26+
public void toAndFromJson() {
27+
Incident source = getFilledIncident();
28+
29+
String json = source.toJson();
30+
Incident serialized = Incident.fromJson(json);
31+
32+
assertEquals(source, serialized);
33+
}
34+
35+
@Test
36+
public void deserializeFromJson(){
4737
String json = "{" +
4838
"\"id\": \"15985415522454461962\"," +
4939
"\"type\": \"construction\"," +
@@ -66,7 +56,8 @@ public void testSerializableFromJson(){
6656
"\"iso_3166_1_alpha2\": US," +
6757
"\"iso_3166_1_alpha3\": USA," +
6858
"\"geometry_index_start\": 805," +
69-
"\"geometry_index_end\": 896" +
59+
"\"geometry_index_end\": 896," +
60+
"\"affected_road_names\": [\"S6/E 28/Obwodnica Trójmiasta\"]" +
7061
"}";
7162

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

@@ -97,4 +89,29 @@ private Incident getDefault() {
9789
.id("id")
9890
.build();
9991
}
92+
93+
private Incident getFilledIncident() {
94+
return Incident.builder()
95+
.id("some_id")
96+
.alertcCodes(Lists.newArrayList(431, 2123, 934))
97+
.closed(true)
98+
.congestion(Congestion.builder().value(10).build())
99+
.creationTime("2020-11-18T11:34:14Z")
100+
.startTime("2021-11-18T11:32:14Z")
101+
.endTime("2021-11-18T12:12:08Z")
102+
.description("description")
103+
.longDescription("long description")
104+
.geometryIndexStart(1)
105+
.geometryIndexEnd(943)
106+
.impact(Incident.IMPACT_MAJOR)
107+
.subType("sub type")
108+
.subTypeDescription("sub type desc")
109+
.type(Incident.INCIDENT_DISABLED_VEHICLE)
110+
.lanesBlocked(Lists.<String>newArrayList())
111+
.numLanesBlocked(null)
112+
.countryCodeAlpha2("US")
113+
.countryCodeAlpha3("USA")
114+
.affectedRoadNames(Lists.newArrayList("test1", "test2"))
115+
.build();
116+
}
100117
}

0 commit comments

Comments
 (0)