|
30 | 30 | public abstract class RouteOptions extends DirectionsJsonObject { |
31 | 31 |
|
32 | 32 | /** |
33 | | - * Build a new instance of this RouteOptions. |
34 | | - * |
35 | | - * @return {@link RouteOptions.Builder} |
| 33 | + * Build a new instance of {@link RouteOptions} and sets default values for: |
| 34 | + * <ul> |
| 35 | + * <li>{@link #baseUrl()} equal to {@link DirectionsCriteria#BASE_API_URL}.</li> |
| 36 | + * <li>{@link #user()} equal to {@link DirectionsCriteria#PROFILE_DEFAULT_USER}.</li> |
| 37 | + * <li>{@link #geometries()} equal to {@link DirectionsCriteria#GEOMETRY_POLYLINE6}.</li> |
| 38 | + * </ul> |
36 | 39 | */ |
37 | 40 | public static Builder builder() { |
38 | 41 | return new AutoValue_RouteOptions.Builder() |
@@ -1140,7 +1143,7 @@ public Builder annotationsList(@Nullable List<String> annotations) { |
1140 | 1143 | */ |
1141 | 1144 | @NonNull |
1142 | 1145 | public Builder approachesList(@Nullable List<String> approaches) { |
1143 | | - String result = FormatUtils.formatApproaches(approaches); |
| 1146 | + String result = FormatUtils.join(";", approaches); |
1144 | 1147 | if (result != null) { |
1145 | 1148 | approaches(result); |
1146 | 1149 | } |
@@ -1416,130 +1419,11 @@ public Builder snappingIncludeClosuresList(@Nullable List<Boolean> snappingClosu |
1416 | 1419 | public abstract Builder enableRefresh(@Nullable Boolean enableRefresh); |
1417 | 1420 |
|
1418 | 1421 | /** |
1419 | | - * Package private used to build the object and verify. |
1420 | | - */ |
1421 | | - @NonNull |
1422 | | - abstract RouteOptions autoBuild(); |
1423 | | - |
1424 | | - /** |
1425 | | - * This uses the provided parameters set using the {@link Builder} and first checks that all |
1426 | | - * values are valid, and creates a new {@link RouteOptions} object with the values provided. |
| 1422 | + * Builds the object. |
1427 | 1423 | * |
1428 | 1424 | * @return a new instance of {@link RouteOptions} |
1429 | 1425 | */ |
1430 | 1426 | @NonNull |
1431 | | - public RouteOptions build() { |
1432 | | - RouteOptions routeOptions = autoBuild(); |
1433 | | - |
1434 | | - List<Point> coordinates = routeOptions.coordinatesList(); |
1435 | | - if (coordinates.size() < 2) { |
1436 | | - throw new RuntimeException( |
1437 | | - "An origin and destination are required before making the directions API request." |
1438 | | - ); |
1439 | | - } |
1440 | | - |
1441 | | - List<Integer> waypointIndices = routeOptions.waypointIndicesList(); |
1442 | | - if (waypointIndices != null && !waypointIndices.isEmpty()) { |
1443 | | - if (waypointIndices.size() < 2) { |
1444 | | - throw new RuntimeException( |
1445 | | - "Waypoints indices must be a list of at least two indexes, origin and destination." |
1446 | | - ); |
1447 | | - } |
1448 | | - if (waypointIndices.get(0) != 0 || waypointIndices.get(waypointIndices.size() - 1) |
1449 | | - != coordinates.size() - 1) { |
1450 | | - throw new RuntimeException( |
1451 | | - "First and last waypoints indices must match the origin and final destination." |
1452 | | - ); |
1453 | | - } |
1454 | | - for (int i = 1; i < waypointIndices.size() - 1; i++) { |
1455 | | - if (waypointIndices.get(i) < 0 |
1456 | | - || waypointIndices.get(i) >= coordinates.size()) { |
1457 | | - throw new RuntimeException( |
1458 | | - "Waypoints index out of bounds (no corresponding coordinate)."); |
1459 | | - } |
1460 | | - } |
1461 | | - } |
1462 | | - |
1463 | | - checkSizeMatchingWaypoints( |
1464 | | - "waypointTargets", |
1465 | | - true, |
1466 | | - routeOptions.waypointTargetsList(), |
1467 | | - coordinates, |
1468 | | - routeOptions.waypointIndicesList() |
1469 | | - ); |
1470 | | - |
1471 | | - checkSizeMatchingWaypoints( |
1472 | | - "approaches", |
1473 | | - false, |
1474 | | - routeOptions.approachesList(), |
1475 | | - coordinates, |
1476 | | - routeOptions.waypointIndicesList() |
1477 | | - ); |
1478 | | - |
1479 | | - checkSizeMatchingWaypoints( |
1480 | | - "snappingIncludeClosures", |
1481 | | - false, |
1482 | | - routeOptions.snappingIncludeClosuresList(), |
1483 | | - coordinates, |
1484 | | - routeOptions.waypointIndicesList() |
1485 | | - ); |
1486 | | - |
1487 | | - checkSizeMatchingWaypoints( |
1488 | | - "bearings", |
1489 | | - false, |
1490 | | - routeOptions.bearingsList(), |
1491 | | - coordinates, |
1492 | | - routeOptions.waypointIndicesList() |
1493 | | - ); |
1494 | | - |
1495 | | - checkSizeMatchingWaypoints( |
1496 | | - "radiuses", |
1497 | | - false, |
1498 | | - routeOptions.radiusesList(), |
1499 | | - coordinates, |
1500 | | - routeOptions.waypointIndicesList() |
1501 | | - ); |
1502 | | - |
1503 | | - checkSizeMatchingWaypoints( |
1504 | | - "waypointNames", |
1505 | | - true, |
1506 | | - routeOptions.waypointNamesList(), |
1507 | | - coordinates, |
1508 | | - routeOptions.waypointIndicesList() |
1509 | | - ); |
1510 | | - |
1511 | | - return routeOptions; |
1512 | | - } |
1513 | | - |
1514 | | - private void checkSizeMatchingWaypoints( |
1515 | | - String paramName, |
1516 | | - boolean waypointIndicesDependent, |
1517 | | - List<?> testedParam, |
1518 | | - List<Point> coordinates, |
1519 | | - List<Integer> waypointIndices |
1520 | | - ) { |
1521 | | - if (testedParam != null && !testedParam.isEmpty()) { |
1522 | | - boolean error = false; |
1523 | | - if (waypointIndicesDependent && waypointIndices != null && !waypointIndices.isEmpty()) { |
1524 | | - if (testedParam.size() != waypointIndices.size()) { |
1525 | | - error = true; |
1526 | | - } |
1527 | | - } else if (testedParam.size() != coordinates.size()) { |
1528 | | - error = true; |
1529 | | - } |
1530 | | - if (error) { |
1531 | | - StringBuilder builder = new StringBuilder(); |
1532 | | - builder.append("Number of "); |
1533 | | - builder.append(paramName); |
1534 | | - builder.append(" must match the number of coordinates"); |
1535 | | - if (waypointIndicesDependent) { |
1536 | | - builder.append(" or waypoints indices (if present)"); |
1537 | | - } |
1538 | | - builder.append("."); |
1539 | | - |
1540 | | - throw new RuntimeException(builder.toString()); |
1541 | | - } |
1542 | | - } |
1543 | | - } |
| 1427 | + public abstract RouteOptions build(); |
1544 | 1428 | } |
1545 | 1429 | } |
0 commit comments