Ticket #20832: 20832.patch

File 20832.patch, 3.2 KB (added by taylor.smock, 5 years ago)

Modify TurnrestrictionTest to account for restriction:mode:conditional and restriction:mode. Note: supported modes are currently hardcoded (see #18383, needs update) to a limited set and no tests are written yet.

  • src/org/openstreetmap/josm/data/validation/tests/TurnrestrictionTest.java

    diff --git a/src/org/openstreetmap/josm/data/validation/tests/TurnrestrictionTest.java b/src/org/openstreetmap/josm/data/validation/tests/TurnrestrictionTest.java
    index aed103c9ce..93735aab42 100644
    a b public class TurnrestrictionTest extends Test {  
    5151            "no_entry", "no_exit"
    5252        );
    5353
     54    // This should really be replaced with a transport mode hierarchy, i.e. #18383
     55    private static final List<String> SUPPORTED_VEHICLE_TYPES = Arrays.asList(
     56            "agricultural", "bicycle", "bus", "caravan", "foot", "hazmat",
     57            "hgv", "horse", "motor_vehicle", "motorcar", "motorcycle",
     58            "psv", "vehicle"
     59    );
     60
     61    /** A string for "restriction" */
     62    private static final String RESTRICTION_STRING = "restriction";
     63    /** A string for "conditional" */
     64    private static final String CONDITIONAL_STRING = "conditional";
     65
    5466    /**
    5567     * Constructs a new {@code TurnrestrictionTest}.
    5668     */
    public class TurnrestrictionTest extends Test {  
    5870        super(tr("Turn restrictions"), tr("This test checks if turn restrictions are valid."));
    5971    }
    6072
    61     private static boolean hasSupportedRestrictionTag(Relation r) {
    62         if (r.hasTag("restriction", SUPPORTED_RESTRICTIONS))
    63             return true;
    64         String conditionalValue = r.get("restriction:conditional");
    65         if (conditionalValue != null) {
     73    /**
     74     * Check for any restriction tag (e.g., "restriction:mode:conditional")
     75     * @param key The key to check
     76     * @param value The value to check
     77     * @return {@code true} if the tag is supported
     78     */
     79    private static boolean restrictionTagIsSupported(final String key, final String value) {
     80        if (key.startsWith(RESTRICTION_STRING) && key.endsWith(CONDITIONAL_STRING)
     81            && SUPPORTED_VEHICLE_TYPES.contains(key.substring(RESTRICTION_STRING.length() + 1, key.length() - CONDITIONAL_STRING.length() - 1))) {
    6682            try {
    67                 List<ConditionalValue> values = ConditionalValue.parse(conditionalValue);
    68                 return !values.isEmpty() && SUPPORTED_RESTRICTIONS.contains(values.get(0).restrictionValue);
     83                final List<ConditionalValue> conditionalValues = ConditionalValue.parse(value);
     84                return !conditionalValues.isEmpty() && conditionalValues.stream()
     85                        .anyMatch(conditional -> SUPPORTED_RESTRICTIONS.contains(conditional.restrictionValue));
    6986            } catch (ConditionalParsingException e) {
    7087                Logging.trace(e);
    7188            }
     89        } else if (key.startsWith(RESTRICTION_STRING)) {
     90            return SUPPORTED_RESTRICTIONS.contains(value);
    7291        }
    7392        return false;
    7493    }
    7594
     95    private static boolean hasSupportedRestrictionTag(Relation r) {
     96        if (r.hasTag(RESTRICTION_STRING, SUPPORTED_RESTRICTIONS))
     97            return true;
     98        return r.getKeys().entrySet().stream()
     99                .anyMatch(entry -> restrictionTagIsSupported(entry.getKey(), entry.getValue()));
     100    }
     101
    76102    @Override
    77103    public void visit(Relation r) {
    78104        if (!r.hasTag("type", "restriction"))