Ticket #20832: 20832.2.patch
| File 20832.2.patch, 4.0 KB (added by , 2 years ago) |
|---|
-
src/org/openstreetmap/josm/data/validation/tests/TurnrestrictionTest.java
51 51 "no_entry", "no_exit" 52 52 ); 53 53 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 54 66 /** 55 67 * Constructs a new {@code TurnrestrictionTest}. 56 68 */ … … 58 70 super(tr("Turn restrictions"), tr("This test checks if turn restrictions are valid.")); 59 71 } 60 72 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" or "restriction: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:")) 81 return false; 82 String[] parts = key.split(":"); 83 if (parts.length > 3) 84 return false; 85 if (parts.length == 3 && !SUPPORTED_VEHICLE_TYPES.contains(parts[1])) 86 return false; 87 if (key.endsWith(CONDITIONAL_STRING)) { 88 // restriction:conditional=* or restriction:mode:condition=* 66 89 try { 67 List<ConditionalValue> values = ConditionalValue.parse(conditionalValue); 68 return !values.isEmpty() && SUPPORTED_RESTRICTIONS.contains(values.get(0).restrictionValue); 90 final List<ConditionalValue> conditionalValues = ConditionalValue.parse(value); 91 return !conditionalValues.isEmpty() && conditionalValues.stream() 92 .anyMatch(conditional -> SUPPORTED_RESTRICTIONS.contains(conditional.restrictionValue)); 69 93 } catch (ConditionalParsingException e) { 70 94 Logging.trace(e); 71 95 } 96 } else if (SUPPORTED_VEHICLE_TYPES.contains(parts[1])) { 97 // restriction:mode=* 98 return SUPPORTED_RESTRICTIONS.contains(value); 72 99 } 73 100 return false; 74 101 } 75 102 103 private static boolean hasSupportedRestrictionTag(Relation r) { 104 if (r.hasTag(RESTRICTION_STRING, SUPPORTED_RESTRICTIONS)) 105 return true; 106 if (r.hasTag("restriction:bicycle", "give_way", "stop")) 107 return true; 108 return r.getKeys().entrySet().stream() 109 .anyMatch(entry -> restrictionTagIsSupported(entry.getKey(), entry.getValue())); 110 } 111 76 112 @Override 77 113 public void visit(Relation r) { 78 if (!r.hasTag("type", "restriction"))114 if (!r.hasTag("type", RESTRICTION_STRING)) 79 115 return; 80 116 81 117 if (!hasSupportedRestrictionTag(r)) { … … 224 260 return; 225 261 } 226 262 if (fromWay.equals(toWay)) { 227 Severity severity = r.hasTag( "restriction", "no_u_turn") ? Severity.OTHER : Severity.WARNING;263 Severity severity = r.hasTag(RESTRICTION_STRING, "no_u_turn") ? Severity.OTHER : Severity.WARNING; 228 264 errors.add(TestError.builder(this, severity, FROM_EQUALS_TO) 229 265 .message(tr("\"from\" way equals \"to\" way")) 230 266 .primitives(r)
