Changeset 36132 in osm for applications/editors/josm/plugins/merge-overlap/src/mergeoverlap/MergeOverlapAction.java
- Timestamp:
- 2023-09-07T16:52:05+02:00 (22 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/merge-overlap/src/mergeoverlap/MergeOverlapAction.java
r35583 r36132 34 34 import org.openstreetmap.josm.data.osm.Way; 35 35 import org.openstreetmap.josm.gui.MainApplication; 36 import org.openstreetmap.josm.tools.Logging; 36 37 import org.openstreetmap.josm.tools.Pair; 37 38 import org.openstreetmap.josm.tools.Shortcut; … … 80 81 Way way = (Way) osm; 81 82 ways.add(way); 82 List<Relation> rels = new ArrayList<>(); 83 for (Relation r : Utils.filteredCollection(way.getReferrers(), Relation.class)) { 84 rels.add(r); 85 } 83 List<Relation> rels = new ArrayList<>(Utils.filteredCollection(way.getReferrers(), Relation.class)); 86 84 relations.put(way, rels); 87 85 } … … 208 206 combineResult = combineWaysWorker(combine); 209 207 } catch (UserCancelException ex) { 208 Logging.trace(ex); 210 209 return; 211 210 } … … 215 214 } 216 215 217 for (Relation old: newRelations.keySet()) {218 cmds.add(new ChangeCommand( old, newRelations.get(old)));216 for (Map.Entry<Relation, Relation> entry : newRelations.entrySet()) { 217 cmds.add(new ChangeCommand(entry.getKey(), entry.getValue())); 219 218 } 220 219 … … 226 225 } 227 226 if (!del.isEmpty()) { 228 cmds.add( newDeleteCommand(del));227 cmds.add(DeleteCommand.delete(del)); 229 228 } 230 229 … … 258 257 } 259 258 260 private boolean addNodes(NodePos start, NodePos end, Way way, 259 private static boolean addNodes(NodePos start, NodePos end, Way way, 261 260 Set<Node> nodes, boolean hasFirst) { 262 261 if (way.isClosed() || (start.node != way.getNode(0) && start.node != way.getNode(way.getNodesCount() - 1))) { … … 274 273 } 275 274 276 private boolean follows(Way way1, Way way2, NodePos np1, NodePos np2, 275 private static boolean follows(Way way1, Way way2, NodePos np1, NodePos np2, 277 276 int incr) { 278 277 if (way2.isClosed() && incr == 1 && np1.opositPos == way2.getNodesCount() - 2) { … … 290 289 291 290 /** 292 * @param ways 291 * @param ways The ways to be combined 293 292 * @return null if ways cannot be combined. Otherwise returns the combined 294 293 * ways and the commands to combine 295 * @throws UserCancelException 294 * @throws UserCancelException If the user cancelled the operation 296 295 */ 297 296 private Pair<Way, List<Command>> combineWaysWorker(Collection<Way> ways) throws UserCancelException { … … 434 433 */ 435 434 private boolean duplicateParentRelations(Collection<Way> ways) { 436 Set<Relation> relations = new HashSet<>();435 Set<Relation> duplicateRelations = new HashSet<>(); 437 436 for (Way w : ways) { 438 437 List<Relation> rs = getParentRelations(w); 439 438 for (Relation r : rs) { 440 if ( relations.contains(r)) {439 if (duplicateRelations.contains(r)) { 441 440 return true; 442 441 } 443 442 } 444 relations.addAll(rs);443 duplicateRelations.addAll(rs); 445 444 } 446 445 return false; … … 455 454 List<Relation> rels = new ArrayList<>(); 456 455 for (Relation r : relations.get(way)) { 457 if (newRelations.containsKey(r)) { 458 rels.add(newRelations.get(r)); 459 } else { 460 rels.add(r); 461 } 456 rels.add(newRelations.getOrDefault(r, r)); 462 457 } 463 458 return rels; … … 479 474 480 475 public static Way getOld(Way w, Map<Way, Way> oldWays) { 481 if (oldWays.containsKey(w)) { 482 return oldWays.get(w); 483 } else { 484 return w; 485 } 476 return oldWays.getOrDefault(w, w); 486 477 } 487 478
Note:
See TracChangeset
for help on using the changeset viewer.