Ticket #18223: 18223.patch
File 18223.patch, 5.8 KB (added by , 5 years ago) |
---|
-
src/org/openstreetmap/josm/data/validation/OsmValidator.java
313 313 final Pattern elemId2Pattern = Pattern.compile("^[0-9]+$"); 314 314 for (Entry<String, String> e: ignoredErrors.entrySet()) { 315 315 String key = e.getKey(); 316 String value = e.getValue(); 317 ArrayList<String> ignoredWayList = new ArrayList<>(); 316 // key starts with a code, it maybe followed by a string (eg. a MapCSS rule) and 317 // optionally with a list of one or more OSM element IDs 318 String description = e.getValue(); 319 320 ArrayList<String> ignoredElementList = new ArrayList<>(); 318 321 String[] osmobjects = elemId1Pattern.split(key); 319 322 for (int i = 1; i < osmobjects.length; i++) { 320 323 String osmid = osmobjects[i]; … … 323 326 int index = key.indexOf(osmid); 324 327 if (index < key.lastIndexOf(']')) continue; 325 328 char type = key.charAt(index - 1); 326 ignored WayList.add(type + osmid);329 ignoredElementList.add(type + osmid); 327 330 } 328 331 } 329 for (String osmignore : ignored WayList) {332 for (String osmignore : ignoredElementList) { 330 333 key = key.replace(':' + osmignore, ""); 331 334 } 332 335 … … 333 336 DefaultMutableTreeNode trunk; 334 337 DefaultMutableTreeNode branch; 335 338 336 if ( value != null && !value.isEmpty()) {337 trunk = inTree(root, value);339 if (description != null && !description.isEmpty()) { 340 trunk = inTree(root, description); 338 341 branch = inTree(trunk, key); 339 342 trunk.add(branch); 340 343 } else { … … 341 344 trunk = inTree(root, key); 342 345 branch = trunk; 343 346 } 344 ignoredWayList.forEach(osmignore -> branch.add(new DefaultMutableTreeNode(osmignore))); 345 347 if (!ignoredElementList.isEmpty()) { 348 String item; 349 if (ignoredElementList.size() == 1) { 350 item = ignoredElementList.iterator().next(); 351 } else { 352 // combination of two or more objects, keep them together 353 item = ignoredElementList.toString(); // [ID1, ID2, ..., IDn] 354 } 355 branch.add(new DefaultMutableTreeNode(item)); 356 } 346 357 root.add(trunk); 347 358 } 348 359 return new JTree(root); … … 377 388 private static Map<String, String> buildIgnore(TreeModel model, DefaultMutableTreeNode node) { 378 389 HashMap<String, String> rHashMap = new HashMap<>(); 379 390 380 String osmids = node.getUserObject().toString();381 String description = "";382 383 if (!model.getRoot().equals(node)) {384 description = ((DefaultMutableTreeNode) node.getParent()).getUserObject().toString();385 } else {386 description = node.getUserObject().toString();387 }388 if (tr("Ignore list").equals(description)) description = "";389 if (!osmids.matches("^[0-9]+(_.*|$)")) {390 description = osmids;391 osmids = "";392 }393 394 395 StringBuilder sb = new StringBuilder();396 391 for (int i = 0; i < model.getChildCount(node); i++) { 397 392 DefaultMutableTreeNode child = (DefaultMutableTreeNode) model.getChild(node, i); 398 393 if (model.getChildCount(child) == 0) { 399 String ignoreName = child.getUserObject().toString(); 400 if (ignoreName.matches("^(r|w|n)_.*")) { 401 sb.append(':').append(child.getUserObject().toString()); 402 } else if (ignoreName.matches("^[0-9]+(_.*|)$")) { 403 rHashMap.put(ignoreName, description); 394 // create an entry for the error list 395 String key = node.getUserObject().toString(); 396 String description; 397 398 if (!model.getRoot().equals(node)) { 399 description = ((DefaultMutableTreeNode) node.getParent()).getUserObject().toString(); 400 } else { 401 description = key; // we get here when reading old file ignorederrors 404 402 } 403 if (tr("Ignore list").equals(description)) 404 description = ""; 405 if (!key.matches("^[0-9]+(_.*|$)")) { 406 description = key; 407 key = ""; 408 } 409 410 String item = child.getUserObject().toString(); 411 String entry = null; 412 if (item.matches("^\\[(r|w|n)_.*")) { 413 // list of elements (produced with list.toString() method) 414 entry = key + ":" + item.substring(1, item.lastIndexOf(']')).replace(", ", ":"); 415 } else if (item.matches("^(r|w|n)_.*")) { 416 // single element 417 entry = key + ":" + item; 418 } else if (item.matches("^[0-9]+(_.*|)$")) { 419 // no element ids 420 entry = item; 421 } 422 if (entry != null) { 423 rHashMap.put(entry, description); 424 } else { 425 Logging.warn("ignored unexpected item in validator ignore list management dialog:'" + item + "'"); 426 } 405 427 } else { 406 428 rHashMap.putAll(buildIgnore(model, child)); 407 429 } 408 430 } 409 osmids += sb.toString();410 if (!osmids.isEmpty() && osmids.indexOf(':') != 0) rHashMap.put(osmids, description);411 431 return rHashMap; 412 432 } 413 433