Changeset 19597 in osm for applications/editors/josm
- Timestamp:
- 2010-01-23T15:12:03+01:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/tests/DuplicateNode.java
r19226 r19597 38 38 39 39 /** The map of potential duplicates. 40 * 40 * 41 41 * If there is exactly one node for a given pos, the map includes a pair <pos, Node>. 42 * If there are multiple nodes for a given pos, the map includes a pair 43 * <pos, NodesByEqualTagsMap> 42 * If there are multiple nodes for a given pos, the map includes a pair 43 * <pos, NodesByEqualTagsMap> 44 44 */ 45 45 Map<LatLon,Object> potentialDuplicates; … … 59 59 potentialDuplicates = new HashMap<LatLon, Object>(); 60 60 } 61 62 61 62 63 63 @Override 64 public void endTest() { 64 public void endTest() { 65 65 for (Entry<LatLon, Object> entry: potentialDuplicates.entrySet()) { 66 66 Object v = entry.getValue(); … … 69 69 // error 70 70 continue; 71 } 72 73 // multiple nodes at the same position -> report errors 71 } 72 73 // multiple nodes at the same position -> report errors 74 74 // 75 75 NodesByEqualTagsMap map = (NodesByEqualTagsMap)v; … … 84 84 if (n.isUsable()) { 85 85 LatLon rounded = n.getCoor().getRoundedToOsmPrecision(); 86 if (potentialDuplicates.get(rounded) == null) { 86 if (potentialDuplicates.get(rounded) == null) { 87 87 // in most cases there is just one node at a given position. We 88 // avoid to create an extra object and add remember the node 89 // itself at this position 88 // avoid to create an extra object and add remember the node 89 // itself at this position 90 90 potentialDuplicates.put(rounded, n); 91 91 } else if (potentialDuplicates.get(rounded) instanceof Node) { … … 99 99 potentialDuplicates.put(rounded, map); 100 100 } else if (potentialDuplicates.get(rounded) instanceof NodesByEqualTagsMap) { 101 // we have multiple nodes at the same position. 102 // 101 // we have multiple nodes at the same position. 102 // 103 103 NodesByEqualTagsMap map = (NodesByEqualTagsMap)potentialDuplicates.get(rounded); 104 104 map.add(n); 105 } 105 } 106 106 } 107 107 } … … 116 116 Collection<OsmPrimitive> sel = new LinkedList<OsmPrimitive>(testError.getPrimitives()); 117 117 LinkedHashSet<Node> nodes = new LinkedHashSet<Node>(OsmPrimitive.getFilteredList(sel, Node.class)); 118 Node target = MergeNodesAction.selectTargetNode(nodes); 118 119 // Use first existing node or first node if all nodes are new 120 Node target = null; 121 for (Node n: nodes) { 122 if (!n.isNew()) { 123 target = n; 124 break; 125 } 126 } 127 if (target == null) { 128 nodes.iterator().next(); 129 } 130 119 131 if(checkAndConfirmOutlyingDeletes(nodes)) 120 132 return MergeNodesAction.mergeNodes(Main.main.getEditLayer(), nodes, target); … … 157 169 return true; 158 170 } 159 171 160 172 static private class NodesByEqualTagsMap { 161 173 /** 162 174 * a bag of primitives with the same position. The bag key is represented 163 175 * by the tag set of the primitive. This allows for easily find nodes at 164 * the same position with the same tag sets later. 176 * the same position with the same tag sets later. 165 177 */ 166 178 private Bag<Map<String,String>, OsmPrimitive> bag; … … 169 181 bag = new Bag<Map<String,String>, OsmPrimitive>(); 170 182 } 171 183 172 184 public void add(Node n) { 173 185 bag.add(n.getKeys(), n); 174 186 } 175 187 176 188 public List<TestError> buildTestErrors(Test parentTest) { 177 189 List<TestError> errors = new ArrayList<TestError>(); 178 190 // check whether we have multiple nodes at the same position with 179 // the same tag set 180 // 191 // the same tag set 192 // 181 193 for (Iterator<Map<String,String>> it = bag.keySet().iterator(); it.hasNext(); ) { 182 194 Map<String,String> tagSet = it.next(); 183 195 if (bag.get(tagSet).size() > 1) { 184 196 errors.add(new TestError( 185 parentTest, 197 parentTest, 186 198 Severity.ERROR, 187 tr("Duplicated nodes"), 188 DUPLICATE_NODE, 199 tr("Duplicated nodes"), 200 DUPLICATE_NODE, 189 201 bag.get(tagSet) 190 202 )); 191 203 it.remove(); 192 204 } 193 205 194 206 } 195 207 196 208 // check whether we have multiple nodes at the same position with 197 // differing tag sets 209 // differing tag sets 198 210 // 199 211 if (!bag.isEmpty()) { … … 204 216 if (duplicates.size() > 1) { 205 217 errors.add(new TestError( 206 parentTest, 218 parentTest, 207 219 Severity.WARNING, 208 220 tr("Nodes at same position"), … … 213 225 } 214 226 return errors; 215 } 227 } 216 228 } 217 229 }
Note:
See TracChangeset
for help on using the changeset viewer.