Changeset 7721 in josm for trunk/src/org/openstreetmap/josm/data
- Timestamp:
- 2014-11-12T02:35:45+01:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/validation/tests/DuplicateWay.java
r7509 r7721 167 167 if (!w.isUsable()) 168 168 return; 169 List<Node> wNodes = w.getNodes(); // The original list of nodes for this way 170 List<Node> wNodesToUse = new ArrayList<>(wNodes.size()); // The list that will be considered for this test 171 if (w.isClosed()) { 172 // In case of a closed way, build the list of lat/lon starting from the node with the lowest id 173 // to ensure this list will produce the same hashcode as the list obtained from another closed 174 // way with the same nodes, in the same order, but that does not start from the same node (fix #8008) 175 int lowestIndex = 0; 176 long lowestNodeId = wNodes.get(0).getUniqueId(); 177 for (int i=1; i<wNodes.size(); i++) { 178 if (wNodes.get(i).getUniqueId() < lowestNodeId) { 179 lowestNodeId = wNodes.get(i).getUniqueId(); 180 lowestIndex = i; 181 } 182 } 183 for (int i=lowestIndex; i<wNodes.size()-1; i++) { 184 wNodesToUse.add(wNodes.get(i)); 185 } 186 for (int i=0; i<lowestIndex; i++) { 187 wNodesToUse.add(wNodes.get(i)); 188 } 189 wNodesToUse.add(wNodes.get(lowestIndex)); 190 } else { 191 wNodesToUse.addAll(wNodes); 192 } 193 // Build the list of lat/lon 194 List<LatLon> wLat = new ArrayList<>(wNodesToUse.size()); 195 for (Node node : wNodesToUse) { 196 wLat.add(node.getCoor()); 197 } 169 List<LatLon> wLat = getOrderedNodes(w); 198 170 // If this way has not direction-dependant keys, make sure the list is ordered the same for all ways (fix #8015) 199 171 if (!w.hasDirectionKeys()) { … … 201 173 if (!knownHashCodes.contains(hash)) { 202 174 List<LatLon> reversedwLat = new ArrayList<>(wLat); 203 175 Collections.reverse(reversedwLat); 204 176 int reverseHash = reversedwLat.hashCode(); 205 177 if (!knownHashCodes.contains(reverseHash)) { … … 218 190 WayPairNoTags wKeyN = new WayPairNoTags(wLat); 219 191 waysNoTags.put(wKeyN, w); 192 } 193 194 /** 195 * Replies the ordered list of nodes of way w such as it is easier to find duplicated ways. 196 * In case of a closed way, build the list of lat/lon starting from the node with the lowest id 197 * to ensure this list will produce the same hashcode as the list obtained from another closed 198 * way with the same nodes, in the same order, but that does not start from the same node (fix #8008) 199 * @param w way 200 * @return the ordered list of nodes of way w such as it is easier to find duplicated ways 201 * @since 7721 202 */ 203 public static List<LatLon> getOrderedNodes(Way w) { 204 List<Node> wNodes = w.getNodes(); // The original list of nodes for this way 205 List<Node> wNodesToUse = new ArrayList<>(wNodes.size()); // The list that will be considered for this test 206 if (w.isClosed()) { 207 int lowestIndex = 0; 208 long lowestNodeId = wNodes.get(0).getUniqueId(); 209 for (int i=1; i<wNodes.size(); i++) { 210 if (wNodes.get(i).getUniqueId() < lowestNodeId) { 211 lowestNodeId = wNodes.get(i).getUniqueId(); 212 lowestIndex = i; 213 } 214 } 215 for (int i=lowestIndex; i<wNodes.size()-1; i++) { 216 wNodesToUse.add(wNodes.get(i)); 217 } 218 for (int i=0; i<lowestIndex; i++) { 219 wNodesToUse.add(wNodes.get(i)); 220 } 221 wNodesToUse.add(wNodes.get(lowestIndex)); 222 } else { 223 wNodesToUse.addAll(wNodes); 224 } 225 // Build the list of lat/lon 226 List<LatLon> wLat = new ArrayList<>(wNodesToUse.size()); 227 for (Node node : wNodesToUse) { 228 wLat.add(node.getCoor()); 229 } 230 return wLat; 220 231 } 221 232
Note:
See TracChangeset
for help on using the changeset viewer.