Changeset 3674 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2010-11-25T18:06:50+01:00 (14 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 1 deleted
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/validation/TestError.java
r3671 r3674 34 34 private String description_en; 35 35 /** The affected primitives */ 36 private List<? extends OsmPrimitive> primitives;36 private Collection<? extends OsmPrimitive> primitives; 37 37 /** The primitives to be highlighted */ 38 private List<?> highlighted;38 private Collection<?> highlighted; 39 39 /** The tester that raised this error */ 40 40 private Test tester; … … 54 54 */ 55 55 public TestError(Test tester, Severity severity, String message, String description, String description_en, 56 int code, List<? extends OsmPrimitive> primitives, List<?> highlighted) {56 int code, Collection<? extends OsmPrimitive> primitives, Collection<?> highlighted) { 57 57 this.tester = tester; 58 58 this.severity = severity; … … 65 65 } 66 66 67 public TestError(Test tester, Severity severity, String message, int code, List<? extends OsmPrimitive> primitives,68 List<?> highlighted) {67 public TestError(Test tester, Severity severity, String message, int code, Collection<? extends OsmPrimitive> primitives, 68 Collection<?> highlighted) { 69 69 this(tester, severity, message, null, null, code, primitives, highlighted); 70 70 } 71 71 72 72 public TestError(Test tester, Severity severity, String message, String description, String description_en, 73 int code, List<? extends OsmPrimitive> primitives) {73 int code, Collection<? extends OsmPrimitive> primitives) { 74 74 this(tester, severity, message, description, description_en, code, primitives, primitives); 75 75 } 76 76 77 public TestError(Test tester, Severity severity, String message, int code, List<? extends OsmPrimitive> primitives) {77 public TestError(Test tester, Severity severity, String message, int code, Collection<? extends OsmPrimitive> primitives) { 78 78 this(tester, severity, message, null, null, code, primitives, primitives); 79 79 } … … 117 117 * @return the list of primitives affected by this error 118 118 */ 119 public List<? extends OsmPrimitive> getPrimitives() {119 public Collection<? extends OsmPrimitive> getPrimitives() { 120 120 return primitives; 121 121 } -
trunk/src/org/openstreetmap/josm/data/validation/tests/DuplicateNode.java
r3671 r3674 15 15 import java.util.List; 16 16 import java.util.Map; 17 import java.util.Set; 17 18 18 19 import javax.swing.JLabel; … … 33 34 import org.openstreetmap.josm.data.validation.Test; 34 35 import org.openstreetmap.josm.data.validation.TestError; 35 import org.openstreetmap.josm.data.validation.util.Bag;36 36 import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil; 37 37 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 38 import org.openstreetmap.josm.tools.MultiMap; 38 39 39 40 /** … … 138 139 List<TestError> errors = new ArrayList<TestError>(); 139 140 140 Bag<Map<String,String>, OsmPrimitive> bag = new Bag<Map<String,String>, OsmPrimitive>();141 MultiMap<Map<String,String>, OsmPrimitive> mm = new MultiMap<Map<String,String>, OsmPrimitive>(); 141 142 for (Node n: nodes) { 142 bag.add(n.getKeys(), n);143 mm.put(n.getKeys(), n); 143 144 } 144 145 … … 150 151 // the same tag set 151 152 // 152 for (Iterator<Map<String,String>> it = bag.keySet().iterator(); it.hasNext();) {153 for (Iterator<Map<String,String>> it = mm.keySet().iterator(); it.hasNext();) { 153 154 Map<String,String> tagSet = it.next(); 154 if ( bag.get(tagSet).size() > 1) {155 if (mm.get(tagSet).size() > 1) { 155 156 156 157 for (String type: types) { … … 158 159 } 159 160 160 for (OsmPrimitive p : bag.get(tagSet)) {161 for (OsmPrimitive p : mm.get(tagSet)) { 161 162 if (p.getType()==OsmPrimitiveType.NODE) { 162 163 Node n = (Node) p; … … 198 199 msg, 199 200 DUPLICATE_NODE_MIXED, 200 bag.get(tagSet)201 mm.get(tagSet) 201 202 )); 202 203 } else if (typeMap.get("highway")) { … … 209 210 msg, 210 211 DUPLICATE_NODE_HIGHWAY, 211 bag.get(tagSet)212 mm.get(tagSet) 212 213 )); 213 214 } else if (typeMap.get("railway")) { … … 220 221 msg, 221 222 DUPLICATE_NODE_RAILWAY, 222 bag.get(tagSet)223 mm.get(tagSet) 223 224 )); 224 225 } else if (typeMap.get("waterway")) { … … 231 232 msg, 232 233 DUPLICATE_NODE_WATERWAY, 233 bag.get(tagSet)234 mm.get(tagSet) 234 235 )); 235 236 } else if (typeMap.get("boundary")) { … … 242 243 msg, 243 244 DUPLICATE_NODE_BOUNDARY, 244 bag.get(tagSet)245 mm.get(tagSet) 245 246 )); 246 247 } else if (typeMap.get("power")) { … … 253 254 msg, 254 255 DUPLICATE_NODE_POWER, 255 bag.get(tagSet)256 mm.get(tagSet) 256 257 )); 257 258 } else if (typeMap.get("natural")) { … … 264 265 msg, 265 266 DUPLICATE_NODE_NATURAL, 266 bag.get(tagSet)267 mm.get(tagSet) 267 268 )); 268 269 } else if (typeMap.get("building")) { … … 275 276 msg, 276 277 DUPLICATE_NODE_BUILDING, 277 bag.get(tagSet)278 mm.get(tagSet) 278 279 )); 279 280 } else if (typeMap.get("landuse")) { … … 286 287 msg, 287 288 DUPLICATE_NODE_LANDUSE, 288 bag.get(tagSet)289 mm.get(tagSet) 289 290 )); 290 291 } else { … … 297 298 msg, 298 299 DUPLICATE_NODE_OTHER, 299 bag.get(tagSet)300 mm.get(tagSet) 300 301 )); 301 302 … … 308 309 // differing tag sets 309 310 // 310 if (! bag.isEmpty()) {311 if (!mm.isEmpty()) { 311 312 List<OsmPrimitive> duplicates = new ArrayList<OsmPrimitive>(); 312 for ( List<OsmPrimitive> l: bag.values()) {313 for (Set<OsmPrimitive> l: mm.values()) { 313 314 duplicates.addAll(l); 314 315 } -
trunk/src/org/openstreetmap/josm/data/validation/tests/DuplicateWay.java
r3671 r3674 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.util.ArrayList; 6 7 import java.util.Collection; 7 8 import java.util.HashSet; … … 9 10 import java.util.List; 10 11 import java.util.Map; 11 import java.util. Vector;12 import java.util.Set; 12 13 13 14 import org.openstreetmap.josm.command.ChangeCommand; … … 24 25 import org.openstreetmap.josm.data.validation.Test; 25 26 import org.openstreetmap.josm.data.validation.TestError; 26 import org.openstreetmap.josm.data.validation.util.Bag;27 27 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 28 import org.openstreetmap.josm.tools.MultiMap; 28 29 29 30 /** … … 36 37 public List<LatLon> coor; 37 38 public Map<String, String> keys; 38 public WayPair(List<LatLon> _coor, Map<String, String> _keys) {39 public WayPair(List<LatLon> _coor, Map<String, String> _keys) { 39 40 coor=_coor; 40 41 keys=_keys; … … 43 44 @Override 44 45 public int hashCode() { 45 return coor.hashCode() +keys.hashCode();46 return coor.hashCode() + keys.hashCode(); 46 47 } 47 48 … … 58 59 59 60 /** Bag of all ways */ 60 Bag<WayPair, OsmPrimitive> ways;61 MultiMap<WayPair, OsmPrimitive> ways; 61 62 62 63 /** … … 72 73 public void startTest(ProgressMonitor monitor) { 73 74 super.startTest(monitor); 74 ways = new Bag<WayPair, OsmPrimitive>(1000);75 ways = new MultiMap<WayPair, OsmPrimitive>(1000); 75 76 } 76 77 … … 78 79 public void endTest() { 79 80 super.endTest(); 80 for ( List<OsmPrimitive> duplicated : ways.values()) {81 for (Set<OsmPrimitive> duplicated : ways.values()) { 81 82 if (duplicated.size() > 1) { 82 83 TestError testError = new TestError(this, Severity.ERROR, tr("Duplicated ways"), DUPLICATE_WAY, duplicated); … … 91 92 if (!w.isUsable()) 92 93 return; 93 List<Node> wNodes =w.getNodes();94 Vector<LatLon> wLat=new Vector<LatLon>(wNodes.size());94 List<Node> wNodes = w.getNodes(); 95 List<LatLon> wLat = new ArrayList<LatLon>(wNodes.size()); 95 96 for (int i=0;i<wNodes.size();i++) { 96 97 wLat.add(wNodes.get(i).getCoor()); 97 98 } 98 Map<String, String> wkeys =w.getKeys();99 Map<String, String> wkeys = w.getKeys(); 99 100 wkeys.remove("created_by"); 100 WayPair wKey =new WayPair(wLat,wkeys);101 ways. add(wKey, w);101 WayPair wKey = new WayPair(wLat, wkeys); 102 ways.put(wKey, w); 102 103 } 103 104 -
trunk/src/org/openstreetmap/josm/data/validation/tests/OverlappingWays.java
r3671 r3674 5 5 6 6 import java.util.ArrayList; 7 import java.util.Collection; 7 8 import java.util.HashMap; 9 import java.util.LinkedHashSet; 8 10 import java.util.List; 9 11 import java.util.Map; … … 17 19 import org.openstreetmap.josm.data.validation.Test; 18 20 import org.openstreetmap.josm.data.validation.TestError; 19 import org.openstreetmap.josm.data.validation.util.Bag;20 21 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 22 import org.openstreetmap.josm.tools.MultiMap; 21 23 import org.openstreetmap.josm.tools.Pair; 22 24 … … 29 31 30 32 /** Bag of all way segments */ 31 Bag<Pair<Node,Node>, WaySegment> nodePairs;33 MultiMap<Pair<Node,Node>, WaySegment> nodePairs; 32 34 33 35 protected static int OVERLAPPING_HIGHWAY = 101; … … 49 51 public void startTest(ProgressMonitor monitor) { 50 52 super.startTest(monitor); 51 nodePairs = new Bag<Pair<Node,Node>, WaySegment>(1000);53 nodePairs = new MultiMap<Pair<Node,Node>, WaySegment>(1000); 52 54 } 53 55 54 56 @Override 55 57 public void endTest() { 56 Map<List<Way>, Li st<WaySegment>> ways_seen = new HashMap<List<Way>, List<WaySegment>>(500);58 Map<List<Way>, LinkedHashSet<WaySegment>> ways_seen = new HashMap<List<Way>, LinkedHashSet<WaySegment>>(500); 57 59 58 for (Li st<WaySegment> duplicated : nodePairs.values()) {60 for (LinkedHashSet<WaySegment> duplicated : nodePairs.values()) { 59 61 int ways = duplicated.size(); 60 62 … … 62 64 List<OsmPrimitive> prims = new ArrayList<OsmPrimitive>(); 63 65 List<Way> current_ways = new ArrayList<Way>(); 64 List<WaySegment> highlight;66 Collection<WaySegment> highlight; 65 67 int highway = 0; 66 68 int railway = 0; … … 148 150 continue; 149 151 } 150 nodePairs. add(Pair.sort(new Pair<Node,Node>(lastN, n)),152 nodePairs.put(Pair.sort(new Pair<Node,Node>(lastN, n)), 151 153 new WaySegment(w, i)); 152 154 lastN = n; -
trunk/src/org/openstreetmap/josm/data/validation/tests/SimilarNamedWays.java
r3671 r3674 15 15 import org.openstreetmap.josm.data.validation.Test; 16 16 import org.openstreetmap.josm.data.validation.TestError; 17 import org.openstreetmap.josm.data.validation.util.Bag;18 17 import org.openstreetmap.josm.data.validation.util.ValUtil; 19 18 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 19 import org.openstreetmap.josm.tools.MultiMap; 20 import org.openstreetmap.josm.tools.Utils; 20 21 21 22 /** … … 32 33 Map<Point2D,List<Way>> cellWays; 33 34 /** The already detected errors */ 34 Bag<Way, Way> errorWays;35 MultiMap<Way, Way> errorWays; 35 36 36 37 /** … … 46 47 super.startTest(monitor); 47 48 cellWays = new HashMap<Point2D,List<Way>>(1000); 48 errorWays = new Bag<Way, Way>();49 errorWays = new MultiMap<Way, Way>(); 49 50 } 50 51 … … 83 84 primitives.add(w2); 84 85 errors.add(new TestError(this, Severity.WARNING, tr("Similarly named ways"), SIMILAR_NAMED, primitives)); 85 errorWays. add(w, w2);86 errorWays.put(w, w2); 86 87 } 87 88 } … … 142 143 143 144 // Step 6 144 d[i][j] = min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + cost);145 d[i][j] = Utils.min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + cost); 145 146 } 146 147 } … … 149 150 return d[n][m]; 150 151 } 151 152 /** // FIXME: move to utils153 * Get minimum of three values154 * @param a First value155 * @param b Second value156 * @param c Third value157 * @return The minimum of the three values158 */159 private static int min(int a, int b, int c) {160 int mi = a;161 if (b < mi) {162 mi = b;163 } if (c < mi) {164 mi = c;165 }166 return mi;167 }168 152 } -
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 } -
trunk/src/org/openstreetmap/josm/data/validation/tests/UnclosedWays.java
r3671 r3674 17 17 import org.openstreetmap.josm.data.validation.Test; 18 18 import org.openstreetmap.josm.data.validation.TestError; 19 import org.openstreetmap.josm.data.validation.util.Bag;20 19 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 21 20 … … 26 25 */ 27 26 public class UnclosedWays extends Test { 28 /** The already detected errors */29 protected Bag<Way, Way> errorWays;30 27 31 28 /** … … 39 36 public void startTest(ProgressMonitor monitor) { 40 37 super.startTest(monitor); 41 errorWays = new Bag<Way, Way>();42 38 } 43 39 44 40 @Override 45 41 public void endTest() { 46 errorWays = null;47 42 super.endTest(); 48 43 } … … 133 128 errors.add(new TestError(this, Severity.WARNING, tr("Unclosed way"), 134 129 type, etype, mode, primitives, highlight)); 135 errorWays.add(w, w);136 130 } 137 131 } -
trunk/src/org/openstreetmap/josm/data/validation/tests/WronglyOrderedWays.java
r3673 r3674 12 12 import org.openstreetmap.josm.data.validation.Test; 13 13 import org.openstreetmap.josm.data.validation.TestError; 14 import org.openstreetmap.josm.data.validation.util.Bag;15 14 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 16 15 … … 26 25 protected static int WRONGLY_ORDERED_LAND = 1003; 27 26 28 /** The already detected errors */29 protected Bag<Way, Way> errorWays;30 31 27 /** 32 28 * Constructor … … 40 36 public void startTest(ProgressMonitor monitor) { 41 37 super.startTest(monitor); 42 errorWays = new Bag<Way, Way>();43 38 } 44 39 45 40 @Override 46 41 public void endTest() { 47 errorWays = null;48 42 super.endTest(); 49 43 } … … 96 90 primitives.add(w); 97 91 errors.add( new TestError(this, Severity.OTHER, errortype, type, primitives) ); 98 errorWays.add(w,w);99 92 } 100 93 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/validator/ValidatorTreePanel.java
r3671 r3674 8 8 import java.util.HashMap; 9 9 import java.util.HashSet; 10 import java.util.LinkedHashSet; 10 11 import java.util.List; 11 12 import java.util.Map; … … 23 24 import org.openstreetmap.josm.data.validation.Severity; 24 25 import org.openstreetmap.josm.data.validation.TestError; 25 import org.openstreetmap.josm.data.validation.util.Bag;26 26 import org.openstreetmap.josm.data.validation.util.MultipleNameVisitor; 27 import org.openstreetmap.josm.tools.MultiMap; 27 28 28 29 /** … … 138 139 } 139 140 140 Map<Severity, Bag<String, TestError>> errorTree = new HashMap<Severity, Bag<String, TestError>>();141 Map<Severity, HashMap<String, Bag<String, TestError>>> errorTreeDeep = new HashMap<Severity, HashMap<String, Bag<String, TestError>>>();141 Map<Severity, MultiMap<String, TestError>> errorTree = new HashMap<Severity, MultiMap<String, TestError>>(); 142 Map<Severity, HashMap<String, MultiMap<String, TestError>>> errorTreeDeep = new HashMap<Severity, HashMap<String, MultiMap<String, TestError>>>(); 142 143 for (Severity s : Severity.values()) { 143 errorTree.put(s, new Bag<String, TestError>(20));144 errorTreeDeep.put(s, new HashMap<String, Bag<String, TestError>>());144 errorTree.put(s, new MultiMap<String, TestError>(20)); 145 errorTreeDeep.put(s, new HashMap<String, MultiMap<String, TestError>>()); 145 146 } 146 147 … … 165 166 } 166 167 if (d != null) { 167 Bag<String, TestError> b = errorTreeDeep.get(s).get(m);168 MultiMap<String, TestError> b = errorTreeDeep.get(s).get(m); 168 169 if (b == null) { 169 b = new Bag<String, TestError>(20);170 b = new MultiMap<String, TestError>(20); 170 171 errorTreeDeep.get(s).put(m, b); 171 172 } 172 b. add(d, e);173 b.put(d, e); 173 174 } else { 174 errorTree.get(s). add(m, e);175 errorTree.get(s).put(m, e); 175 176 } 176 177 } … … 178 179 List<TreePath> expandedPaths = new ArrayList<TreePath>(); 179 180 for (Severity s : Severity.values()) { 180 Bag<String, TestError> severityErrors = errorTree.get(s);181 Map<String, Bag<String, TestError>> severityErrorsDeep = errorTreeDeep.get(s);181 MultiMap<String, TestError> severityErrors = errorTree.get(s); 182 Map<String, MultiMap<String, TestError>> severityErrorsDeep = errorTreeDeep.get(s); 182 183 if (severityErrors.isEmpty() && severityErrorsDeep.isEmpty()) { 183 184 continue; … … 192 193 } 193 194 194 for (Entry<String, Li st<TestError>> msgErrors : severityErrors.entrySet()) {195 for (Entry<String, LinkedHashSet<TestError>> msgErrors : severityErrors.entrySet()) { 195 196 // Message node 196 List<TestError> errs = msgErrors.getValue();197 Set<TestError> errs = msgErrors.getValue(); 197 198 String msg = msgErrors.getKey() + " (" + errs.size() + ")"; 198 199 DefaultMutableTreeNode messageNode = new DefaultMutableTreeNode(msg); … … 209 210 } 210 211 } 211 for (Entry<String, Bag<String, TestError>> bag : severityErrorsDeep.entrySet()) {212 for (Entry<String, MultiMap<String, TestError>> bag : severityErrorsDeep.entrySet()) { 212 213 // Group node 213 Bag<String, TestError> errorlist = bag.getValue();214 MultiMap<String, TestError> errorlist = bag.getValue(); 214 215 DefaultMutableTreeNode groupNode = null; 215 216 if (errorlist.size() > 1) { … … 222 223 } 223 224 224 for (Entry<String, Li st<TestError>> msgErrors : errorlist.entrySet()) {225 for (Entry<String, LinkedHashSet<TestError>> msgErrors : errorlist.entrySet()) { 225 226 // Message node 226 List<TestError> errs = msgErrors.getValue();227 Set<TestError> errs = msgErrors.getValue(); 227 228 String msg; 228 229 if (groupNode != null) { -
trunk/src/org/openstreetmap/josm/gui/layer/ValidatorLayer.java
r3671 r3674 19 19 import org.openstreetmap.josm.data.validation.Severity; 20 20 import org.openstreetmap.josm.data.validation.TestError; 21 import org.openstreetmap.josm.data.validation.util.Bag;22 21 import org.openstreetmap.josm.gui.MapView; 23 22 import org.openstreetmap.josm.gui.MapView.LayerChangeListener; … … 25 24 import org.openstreetmap.josm.gui.dialogs.LayerListPopup; 26 25 import org.openstreetmap.josm.tools.ImageProvider; 26 import org.openstreetmap.josm.tools.MultiMap; 27 27 28 28 /** … … 78 78 @Override 79 79 public String getToolTipText() { 80 Bag<Severity, TestError> errorTree = new Bag<Severity, TestError>();80 MultiMap<Severity, TestError> errorTree = new MultiMap<Severity, TestError>(); 81 81 List<TestError> errors = Main.map.validatorDialog.tree.getErrors(); 82 82 for (TestError e : errors) { 83 errorTree. add(e.getSeverity(), e);83 errorTree.put(e.getSeverity(), e); 84 84 } 85 85 -
trunk/src/org/openstreetmap/josm/tools/MultiMap.java
r3637 r3674 2 2 package org.openstreetmap.josm.tools; 3 3 4 import java.util.Collection; 4 5 import java.util.HashMap; 5 6 import java.util.LinkedHashSet; 6 7 import java.util.Map; 8 import java.util.Map.Entry; 7 9 import java.util.Set; 8 10 9 11 /** 10 * Maps keys to ordered sets of values. 12 * MultiMap - maps keys to multiple values 13 * 14 * Corresponds to Google guava LinkedHashMultimap and Apache Collections MultiValueMap 15 * but it is an independent (simplistic) implementation. 16 * 11 17 */ 12 public class MultiMap<A, B> 18 public class MultiMap<A, B> { 13 19 14 private final Map<A, LinkedHashSet<B>> map = new HashMap<A, LinkedHashSet<B>>(); 20 private final Map<A, LinkedHashSet<B>> map; 21 22 public MultiMap() { 23 map = new HashMap<A, LinkedHashSet<B>>(); 24 } 25 26 public MultiMap(int capacity) { 27 map = new HashMap<A, LinkedHashSet<B>>(capacity); 28 } 29 15 30 /** 16 31 * Map a key to a value. Can be called multiple times with the same key, but different value. … … 26 41 27 42 /** 28 * Put a key that maps to nothing. 43 * Put a key that maps to nothing. (Only if it is not already in the map) 44 * Afterwards containsKey(key) will return true and get(key) will return 45 * an empty Set instead of null. 29 46 */ 30 47 public void putVoid(A key) { … … 35 52 36 53 /** 37 * Returns a list of values for the given key 38 * or an empty list, if it maps to nothing. 54 * Get the keySet 55 */ 56 public Set<A> keySet() { 57 return map.keySet(); 58 } 59 60 /** 61 * Return the Set associated with the given key. Result is null if 62 * nothing has been mapped to this key. Modifications of the returned list 63 * changes the underling map, but you should better not do that. 64 */ 65 public Set<B> get(A key) { 66 return map.get(key); 67 } 68 69 /** 70 * Like get, but returns an empty Set if nothing has been mapped to the key. 39 71 */ 40 72 public LinkedHashSet<B> getValues(A key) { … … 44 76 } 45 77 46 public Set<A> keySet() {47 return map. keySet();78 public boolean isEmpty() { 79 return map.isEmpty(); 48 80 } 49 81 50 public Set<B> get(A key) { 51 return map.get(key); 82 public boolean containsKey(A key) { 83 return map.containsKey(key); 84 } 85 86 /** 87 * Returns true if the multimap contains a value for a key 88 * @param key The key 89 * @param value The value 90 * @return true if the key contains the value 91 */ 92 public boolean contains(A key, B value) { 93 Set<B> values = get(key); 94 return (values == null) ? false : values.contains(value); 95 } 96 97 public void clear() { 98 map.clear(); 99 } 100 101 public Set<Entry<A, LinkedHashSet<B>>> entrySet() { 102 return map.entrySet(); 103 } 104 105 /** 106 * number of keys 107 */ 108 public int size() { 109 return map.size(); 110 } 111 112 /** 113 * returns a collection of all value sets 114 */ 115 public Collection<LinkedHashSet<B>> values() { 116 return map.values(); 52 117 } 53 118 } -
trunk/src/org/openstreetmap/josm/tools/Utils.java
r3504 r3674 11 11 return false; 12 12 } 13 14 /** 15 * Get minimum of 3 values 16 */ 17 public static int min(int a, int b, int c) { 18 if (b < c) { 19 if (a < b) 20 return a; 21 return b; 22 } else { 23 if (a < c) { 24 return a; 25 } 26 return c; 27 } 28 } 13 29 }
Note:
See TracChangeset
for help on using the changeset viewer.