Changeset 9023 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2015-11-19T00:33:55+01:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/validation/tests/TagChecker.java
r8969 r9023 80 80 private static final List<String> ignoreDataEquals = new ArrayList<>(); 81 81 private static final List<String> ignoreDataEndsWith = new ArrayList<>(); 82 private static final List< IgnoreKeyPair> ignoreDataKeyPair= new ArrayList<>();82 private static final List<Tag> ignoreDataTag = new ArrayList<>(); 83 83 84 84 /** The preferences prefix */ … … 159 159 ignoreDataEquals.clear(); 160 160 ignoreDataEndsWith.clear(); 161 ignoreData KeyPair.clear();161 ignoreDataTag.clear(); 162 162 harmonizedKeys.clear(); 163 163 … … 207 207 break; 208 208 case "K:": 209 IgnoreKeyPair tmp = new IgnoreKeyPair(); 210 int mid = line.indexOf('='); 211 tmp.key = line.substring(0, mid); 212 tmp.value = line.substring(mid+1); 213 ignoreDataKeyPair.add(tmp); 209 ignoreDataTag.add(Tag.ofString(line)); 214 210 } 215 211 } else if (tagcheckerfile) { … … 309 305 310 306 /** 307 * Determines if the given key is in internal presets. 308 * @param key key 309 * @return {@code true} if the given key is in internal presets 310 * @since 9023 311 */ 312 public static boolean isKeyInPresets(String key) { 313 return presetsValueData.get(key) != null; 314 } 315 316 /** 317 * Determines if the given tag is in internal presets. 318 * @param key key 319 * @param value value 320 * @return {@code true} if the given tag is in internal presets 321 * @since 9023 322 */ 323 public static boolean isTagInPresets(String key, String value) { 324 final Set<String> values = presetsValueData.get(key); 325 return values != null && (values.isEmpty() || values.contains(value)); 326 } 327 328 /** 329 * Returns the list of ignored tags. 330 * @return the list of ignored tags 331 * @since 9023 332 */ 333 public static List<Tag> getIgnoredTags() { 334 return new ArrayList<>(ignoreDataTag); 335 } 336 337 /** 338 * Determines if the given tag is ignored for checks "key/tag not in presets". 339 * @param key key 340 * @param value value 341 * @return {@code true} if the given tag is ignored 342 * @since 9023 343 */ 344 public static boolean isTagIgnored(String key, String value) { 345 boolean tagInPresets = isTagInPresets(key, value); 346 boolean ignore = false; 347 348 for (String a : ignoreDataStartsWith) { 349 if (key.startsWith(a)) { 350 ignore = true; 351 } 352 } 353 for (String a : ignoreDataEquals) { 354 if (key.equals(a)) { 355 ignore = true; 356 } 357 } 358 for (String a : ignoreDataEndsWith) { 359 if (key.endsWith(a)) { 360 ignore = true; 361 } 362 } 363 364 if (!tagInPresets) { 365 for (Tag a : ignoreDataTag) { 366 if (key.equals(a.getKey()) && value.equals(a.getValue())) { 367 ignore = true; 368 } 369 } 370 } 371 return ignore; 372 } 373 374 /** 311 375 * Checks the primitive tags 312 376 * @param p The primitive to check … … 373 437 } 374 438 if (checkValues && key != null && value != null && !value.isEmpty() && presetsValueData != null) { 375 final Set<String> values = presetsValueData.get(key); 376 final boolean keyInPresets = values != null; 377 final boolean tagInPresets = values != null && (values.isEmpty() || values.contains(prop.getValue())); 378 379 boolean ignore = false; 380 for (String a : ignoreDataStartsWith) { 381 if (key.startsWith(a)) { 382 ignore = true; 383 } 384 } 385 for (String a : ignoreDataEquals) { 386 if (key.equals(a)) { 387 ignore = true; 388 } 389 } 390 for (String a : ignoreDataEndsWith) { 391 if (key.endsWith(a)) { 392 ignore = true; 393 } 394 } 395 396 if (!tagInPresets) { 397 for (IgnoreKeyPair a : ignoreDataKeyPair) { 398 if (key.equals(a.key) && value.equals(a.value)) { 399 ignore = true; 400 } 401 } 402 } 403 404 if (!ignore) { 405 if (!keyInPresets) { 439 if (!isTagIgnored(key, value)) { 440 if (!isKeyInPresets(key)) { 406 441 String prettifiedKey = harmonizeKey(key); 407 442 String fixedKey = harmonizedKeys.get(prettifiedKey); … … 420 455 withErrors.put(p, "UPK"); 421 456 } 422 } else if (! tagInPresets) {457 } else if (!isTagInPresets(key, value)) { 423 458 // try to fix common typos and check again if value is still unknown 424 459 String fixedValue = harmonizeValue(prop.getValue()); 425 Map<String, String> possibleValues = getPossibleValues( values);460 Map<String, String> possibleValues = getPossibleValues(presetsValueData.get(key)); 426 461 if (possibleValues.containsKey(fixedValue)) { 427 462 fixedValue = possibleValues.get(fixedValue); … … 642 677 643 678 return false; 644 }645 646 protected static class IgnoreKeyPair {647 public String key;648 public String value;649 679 } 650 680
Note:
See TracChangeset
for help on using the changeset viewer.