Changeset 3674 in josm for trunk/src/org/openstreetmap/josm/data/validation/tests/TagChecker.java
- Timestamp:
- 2010-11-25T18:06:50+01:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/validation/tests/TagChecker.java
r3673 r3674 24 24 import java.util.Map; 25 25 import java.util.Map.Entry; 26 import java.util.Set; 26 27 import java.util.regex.Matcher; 27 28 import java.util.regex.Pattern; … … 50 51 import org.openstreetmap.josm.data.validation.Test; 51 52 import org.openstreetmap.josm.data.validation.TestError; 52 import org.openstreetmap.josm.data.validation.util.Bag;53 53 import org.openstreetmap.josm.data.validation.util.Entities; 54 54 import org.openstreetmap.josm.data.validation.util.ValUtil; … … 59 59 import org.openstreetmap.josm.io.MirroredInputStream; 60 60 import org.openstreetmap.josm.tools.GBC; 61 import org.openstreetmap.josm.tools.MultiMap; 61 62 62 63 /** … … 75 76 protected static Map<String, String> spellCheckKeyData; 76 77 /** The spell check preset values */ 77 protected static Bag<String, String> presetsValueData;78 protected static MultiMap<String, String> presetsValueData; 78 79 /** The TagChecker data */ 79 80 protected static List<CheckerData> checkerData = new ArrayList<CheckerData>(); … … 294 295 Collection<TaggingPreset> presets = TaggingPresetPreference.taggingPresets; 295 296 if (presets != null) { 296 presetsValueData = new Bag<String, String>();297 presetsValueData = new MultiMap<String, String>(); 297 298 for (String a : OsmPrimitive.getUninterestingKeys()) { 298 presetsValueData. add(a);299 presetsValueData.putVoid(a); 299 300 } 300 301 // TODO directionKeys are no longer in OsmPrimitive (search pattern is used instead) … … 304 305 for (String a : Main.pref.getCollection(ValidatorPreference.PREFIX + ".knownkeys", 305 306 Arrays.asList(new String[]{"is_in", "int_ref", "fixme", "population"}))) { 306 presetsValueData. add(a);307 presetsValueData.putVoid(a); 307 308 } 308 309 for (TaggingPreset p : presets) { … … 312 313 if (combo.values != null) { 313 314 for(String value : combo.values.split(",")) { 314 presetsValueData. add(combo.key, value);315 presetsValueData.put(combo.key, value); 315 316 } 316 317 } 317 318 } else if (i instanceof TaggingPreset.Key) { 318 319 TaggingPreset.Key k = (TaggingPreset.Key) i; 319 presetsValueData. add(k.key, k.value);320 presetsValueData.put(k.key, k.value); 320 321 } else if (i instanceof TaggingPreset.Text) { 321 322 TaggingPreset.Text k = (TaggingPreset.Text) i; 322 presetsValueData. add(k.key);323 presetsValueData.putVoid(k.key); 323 324 } else if (i instanceof TaggingPreset.Check) { 324 325 TaggingPreset.Check k = (TaggingPreset.Check) i; 325 presetsValueData. add(k.key, "yes");326 presetsValueData. add(k.key, "no");326 presetsValueData.put(k.key, "yes"); 327 presetsValueData.put(k.key, "no"); 327 328 } 328 329 } … … 366 367 private void checkPrimitive(OsmPrimitive p) { 367 368 // Just a collection to know if a primitive has been already marked with error 368 Bag<OsmPrimitive, String> withErrors = new Bag<OsmPrimitive, String>();369 MultiMap<OsmPrimitive, String> withErrors = new MultiMap<OsmPrimitive, String>(); 369 370 370 371 if (checkComplex) { … … 400 401 errors.add( new TestError(this, Severity.ERROR, tr("Illegal tag/value combinations"), 401 402 tr("Illegal tag/value combinations"), tr("Illegal tag/value combinations"), 1272, p) ); 402 withErrors. add(p, "TC");403 withErrors.put(p, "TC"); 403 404 } 404 405 } … … 409 410 errors.add( new TestError(this, d.getSeverity(), tr("Illegal tag/value combinations"), 410 411 d.getDescription(), d.getDescriptionOrig(), d.getCode(), p) ); 411 withErrors. add(p, "TC");412 withErrors.put(p, "TC"); 412 413 } 413 414 } … … 422 423 errors.add( new TestError(this, Severity.WARNING, tr("Tag value contains character with code less than 0x20"), 423 424 tr(s, key), MessageFormat.format(s, key), LOW_CHAR_VALUE, p) ); 424 withErrors. add(p, "ICV");425 withErrors.put(p, "ICV"); 425 426 } 426 427 if (checkKeys && (containsLow(key)) && !withErrors.contains(p, "ICK")) { 427 428 errors.add( new TestError(this, Severity.WARNING, tr("Tag key contains character with code less than 0x20"), 428 429 tr(s, key), MessageFormat.format(s, key), LOW_CHAR_KEY, p) ); 429 withErrors. add(p, "ICK");430 withErrors.put(p, "ICK"); 430 431 } 431 432 if (checkValues && (value!=null && value.length() > 255) && !withErrors.contains(p, "LV")) { 432 433 errors.add( new TestError(this, Severity.ERROR, tr("Tag value longer than allowed"), 433 434 tr(s, key), MessageFormat.format(s, key), LONG_VALUE, p) ); 434 withErrors. add(p, "LV");435 withErrors.put(p, "LV"); 435 436 } 436 437 if (checkKeys && (key!=null && key.length() > 255) && !withErrors.contains(p, "LK")) { 437 438 errors.add( new TestError(this, Severity.ERROR, tr("Tag key longer than allowed"), 438 439 tr(s, key), MessageFormat.format(s, key), LONG_KEY, p) ); 439 withErrors. add(p, "LK");440 withErrors.put(p, "LK"); 440 441 } 441 442 if (checkValues && (value==null || value.trim().length() == 0) && !withErrors.contains(p, "EV")) { 442 443 errors.add( new TestError(this, Severity.WARNING, tr("Tags with empty values"), 443 444 tr(s, key), MessageFormat.format(s, key), EMPTY_VALUES, p) ); 444 withErrors. add(p, "EV");445 withErrors.put(p, "EV"); 445 446 } 446 447 if (checkKeys && spellCheckKeyData.containsKey(key) && !withErrors.contains(p, "IPK")) { 447 448 errors.add( new TestError(this, Severity.WARNING, tr("Invalid property key"), 448 449 tr(s, key), MessageFormat.format(s, key), INVALID_KEY, p) ); 449 withErrors. add(p, "IPK");450 withErrors.put(p, "IPK"); 450 451 } 451 452 if (checkKeys && key.indexOf(" ") >= 0 && !withErrors.contains(p, "IPK")) { 452 453 errors.add( new TestError(this, Severity.WARNING, tr("Invalid white space in property key"), 453 454 tr(s, key), MessageFormat.format(s, key), INVALID_KEY_SPACE, p) ); 454 withErrors. add(p, "IPK");455 withErrors.put(p, "IPK"); 455 456 } 456 457 if (checkValues && value != null && (value.startsWith(" ") || value.endsWith(" ")) && !withErrors.contains(p, "SPACE")) { 457 458 errors.add( new TestError(this, Severity.OTHER, tr("Property values start or end with white space"), 458 459 tr(s, key), MessageFormat.format(s, key), INVALID_SPACE, p) ); 459 withErrors. add(p, "SPACE");460 withErrors.put(p, "SPACE"); 460 461 } 461 462 if (checkValues && value != null && !value.equals(entities.unescape(value)) && !withErrors.contains(p, "HTML")) { 462 463 errors.add( new TestError(this, Severity.OTHER, tr("Property values contain HTML entity"), 463 464 tr(s, key), MessageFormat.format(s, key), INVALID_HTML, p) ); 464 withErrors. add(p, "HTML");465 withErrors.put(p, "HTML"); 465 466 } 466 467 if (checkValues && value != null && value.length() > 0 && presetsValueData != null) { 467 List<String> values = presetsValueData.get(key);468 Set<String> values = presetsValueData.get(key); 468 469 if (values == null) { 469 470 boolean ignore = false; … … 487 488 errors.add( new TestError(this, Severity.OTHER, tr("Presets do not contain property key"), 488 489 tr(i, key), MessageFormat.format(i, key), INVALID_VALUE, p) ); 489 withErrors. add(p, "UPK");490 withErrors.put(p, "UPK"); 490 491 } 491 492 } else if (values.size() > 0 && !values.contains(prop.getValue())) { … … 507 508 errors.add( new TestError(this, Severity.OTHER, tr("Presets do not contain property value"), 508 509 tr(i, prop.getValue(), key), MessageFormat.format(i, prop.getValue(), key), INVALID_VALUE, p) ); 509 withErrors. add(p, "UPV");510 withErrors.put(p, "UPV"); 510 511 } 511 512 } … … 518 519 errors.add(new TestError(this, Severity.OTHER, 519 520 tr("FIXMES"), FIXME, p)); 520 withErrors. add(p, "FIXME");521 withErrors.put(p, "FIXME"); 521 522 } 522 523 } … … 755 756 List<Command> commands = new ArrayList<Command>(50); 756 757 757 int i = -1; 758 List<? extends OsmPrimitive> primitives = testError.getPrimitives(); 758 Collection<? extends OsmPrimitive> primitives = testError.getPrimitives(); 759 759 for (OsmPrimitive p : primitives) { 760 i++;761 760 Map<String, String> tags = p.getKeys(); 762 761 if (tags == null || tags.isEmpty()) { … … 768 767 String value = prop.getValue(); 769 768 if (value == null || value.trim().length() == 0) { 770 commands.add(new ChangePropertyCommand(Collections.singleton(p rimitives.get(i)), key, null));769 commands.add(new ChangePropertyCommand(Collections.singleton(p), key, null)); 771 770 } else if (value.startsWith(" ") || value.endsWith(" ")) { 772 commands.add(new ChangePropertyCommand(Collections.singleton(p rimitives.get(i)), key, value.trim()));771 commands.add(new ChangePropertyCommand(Collections.singleton(p), key, value.trim())); 773 772 } else if (key.startsWith(" ") || key.endsWith(" ")) { 774 commands.add(new ChangePropertyKeyCommand(Collections.singleton(p rimitives.get(i)), key, key.trim()));773 commands.add(new ChangePropertyKeyCommand(Collections.singleton(p), key, key.trim())); 775 774 } else { 776 775 String evalue = entities.unescape(value); 777 776 if (!evalue.equals(value)) { 778 commands.add(new ChangePropertyCommand(Collections.singleton(p rimitives.get(i)), key, evalue));777 commands.add(new ChangePropertyCommand(Collections.singleton(p), key, evalue)); 779 778 } else { 780 779 String replacementKey = spellCheckKeyData.get(key); 781 780 if (replacementKey != null) { 782 commands.add(new ChangePropertyKeyCommand(Collections.singleton(p rimitives.get(i)),781 commands.add(new ChangePropertyKeyCommand(Collections.singleton(p), 783 782 key, replacementKey)); 784 783 }
Note:
See TracChangeset
for help on using the changeset viewer.