Changeset 2341 in josm
- Timestamp:
- 2009-10-28T19:33:49+01:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/MergeNodesAction.java
r2333 r2341 3 3 4 4 import static org.openstreetmap.josm.gui.conflict.tags.TagConflictResolutionUtil.combineTigerTags; 5 import static org.openstreetmap.josm.gui.help.HelpUtil.ht;6 5 import static org.openstreetmap.josm.gui.conflict.tags.TagConflictResolutionUtil.completeTagCollectionForEditing; 7 6 import static org.openstreetmap.josm.gui.conflict.tags.TagConflictResolutionUtil.normalizeTagCollectionBeforeEditing; … … 14 13 import java.util.Collection; 15 14 import java.util.HashSet; 15 import java.util.LinkedHashSet; 16 16 import java.util.LinkedList; 17 17 import java.util.List; … … 54 54 return; 55 55 Collection<OsmPrimitive> selection = getCurrentDataSet().getSelected(); 56 Set<Node> selectedNodes = OsmPrimitive.getFilteredSet(selection, Node.class); 56 LinkedHashSet<Node> selectedNodes = OsmPrimitive.getFilteredSet(selection, Node.class); 57 57 if (selectedNodes.size() < 2) { 58 58 JOptionPane.showMessageDialog( … … 74 74 75 75 /** 76 * Selects a node out of a collection of candidate nodes. The selected 77 * node will become the target node the remaining nodes are merged to. 78 * 76 * Find which node to merge into (i.e. which one will be left) 77 * The last selected node will become the target node the remaining 78 * nodes are merged to. 79 * 79 80 * @param candidates the collection of candidate nodes 80 81 * @return the selected target node 81 82 */ 82 public static Node selectTargetNode(Collection<Node> candidates) { 83 // Find which node to merge into (i.e. which one will be left) 84 // - this should be combined from two things: 85 // 1. It will be the first node in the list that has a 86 // positive ID number, OR the first node. 87 // 2. It will be at the position of the first node in the 88 // list. 89 // 90 // *However* - there is the problem that the selection list is 91 // _not_ in the order that the nodes were clicked on, meaning 92 // that the user doesn't know which node will be chosen (so 93 // (2) is not implemented yet.) :-( 83 public static Node selectTargetNode(LinkedHashSet<Node> candidates) { 94 84 Node targetNode = null; 95 for (Node n: candidates) { 96 if (!n.isNew()) { 97 targetNode = n; 98 break; 99 } 100 } 101 if (targetNode == null) { 102 // an arbitrary node 103 targetNode = candidates.iterator().next(); 85 for (Node n : candidates) { // pick last one 86 targetNode = n; 104 87 } 105 88 return targetNode; -
trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java
r2309 r2341 11 11 import java.util.HashMap; 12 12 import java.util.HashSet; 13 import java.util.LinkedHashSet; 13 14 import java.util.LinkedList; 14 15 import java.util.List; … … 83 84 * @return the sub-set of OSM primitives of type <code>type</code> 84 85 */ 85 static public <T extends OsmPrimitive> Set<T> getFilteredSet(Collection<OsmPrimitive> set, Class<T> type) { 86 if (set == null) return Collections.emptySet(); 87 HashSet<T> ret = new HashSet<T>(); 88 for(OsmPrimitive p: set) { 89 if (type.isInstance(p)) { 90 ret.add(type.cast(p)); 86 static public <T extends OsmPrimitive> LinkedHashSet<T> getFilteredSet(Collection<OsmPrimitive> set, Class<T> type) { 87 LinkedHashSet<T> ret = new LinkedHashSet<T>(); 88 if (set != null) { 89 for(OsmPrimitive p: set) { 90 if (type.isInstance(p)) { 91 ret.add(type.cast(p)); 92 } 91 93 } 92 94 }
Note:
See TracChangeset
for help on using the changeset viewer.