Changeset 5487 in josm for trunk/src


Ignore:
Timestamp:
2012-09-01T18:02:59+02:00 (12 years ago)
Author:
Don-vip
Message:

see #8015 - Find duplicate (direction-independant) ways in reverse order

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/validation/tests/DuplicateWay.java

    r5480 r5487  
    66import java.util.ArrayList;
    77import java.util.Collection;
     8import java.util.Collections;
    89import java.util.HashSet;
    910import java.util.LinkedList;
     
    7778
    7879    /** Bag of all ways */
    79     MultiMap<WayPair, OsmPrimitive> ways;
     80    private MultiMap<WayPair, OsmPrimitive> ways;
    8081
    8182    /** Bag of all ways, regardless of tags */
    82     MultiMap<WayPairNoTags, OsmPrimitive> waysNoTags;
     83    private MultiMap<WayPairNoTags, OsmPrimitive> waysNoTags;
     84   
     85    /** Set of known hashcodes for list of coordinates **/
     86    private Set<Integer> knownHashCodes;
    8387
    8488    /**
     
    96100        ways = new MultiMap<WayPair, OsmPrimitive>(1000);
    97101        waysNoTags = new MultiMap<WayPairNoTags, OsmPrimitive>(1000);
     102        knownHashCodes = new HashSet<Integer>(1000);
    98103    }
    99104
     
    136141        ways = null;
    137142        waysNoTags = null;
     143        knownHashCodes = null;
    138144    }
    139145
     
    150156        if (!w.isUsable())
    151157            return;
    152         List<Node> wNodes = w.getNodes();
    153         List<LatLon> wLat = new ArrayList<LatLon>(wNodes.size());
     158        List<Node> wNodes = w.getNodes();                            // The original list of nodes for this way
     159        List<Node> wNodesToUse = new ArrayList<Node>(wNodes.size()); // The list that will be considered for this test
    154160        if (w.isClosed()) {
    155161            // In case of a closed way, build the list of lat/lon starting from the node with the lowest id
     
    165171            }
    166172            for (int i=lowestIndex; i<wNodes.size()-1; i++) {
    167                 wLat.add(wNodes.get(i).getCoor());
     173                wNodesToUse.add(wNodes.get(i));
    168174            }
    169175            for (int i=0; i<lowestIndex; i++) {
    170                 wLat.add(wNodes.get(i).getCoor());
    171             }
    172             wLat.add(wNodes.get(lowestIndex).getCoor());
    173         } else {
    174             for (int i=0; i<wNodes.size(); i++) {
    175                 wLat.add(wNodes.get(i).getCoor());
    176             }
     176                wNodesToUse.add(wNodes.get(i));
     177            }
     178            wNodesToUse.add(wNodes.get(lowestIndex));
     179        }
     180        // Build the list of lat/lon
     181        List<LatLon> wLat = new ArrayList<LatLon>(wNodesToUse.size());
     182        for (int i=0; i<wNodesToUse.size(); i++) {
     183            wLat.add(wNodesToUse.get(i).getCoor());
     184        }
     185        // If this way has not direction-dependant keys, make sure the list is ordered the same for all ways (fix #8015)
     186        if (!w.hasDirectionKeys()) {
     187                int hash = wLat.hashCode();
     188                if (!knownHashCodes.contains(hash)) {
     189                List<LatLon> reversedwLat = new ArrayList<LatLon>(wLat);
     190                        Collections.reverse(reversedwLat);
     191                int reverseHash = reversedwLat.hashCode();
     192                if (!knownHashCodes.contains(reverseHash)) {
     193                        // Neither hash or reversed hash is known, remember hash
     194                        knownHashCodes.add(hash);
     195                } else {
     196                        // Reversed hash is known, use the reverse list then
     197                        wLat = reversedwLat;
     198                }
     199                }
    177200        }
    178201        Map<String, String> wkeys = w.getKeys();
Note: See TracChangeset for help on using the changeset viewer.