Ignore:
Timestamp:
2012-03-08T21:59:15+01:00 (12 years ago)
Author:
simon04
Message:

fix #7201 - combining ways screws up the order of ref tags (handling cases "US 101; CA 2" + "US 101" correctly)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/TagCollection.java

    r4749 r5058  
    77import java.util.Arrays;
    88import java.util.Collection;
    9 import java.util.Collections;
    109import java.util.HashMap;
    1110import java.util.HashSet;
    1211import java.util.Iterator;
     12import java.util.LinkedHashMap;
     13import java.util.LinkedHashSet;
    1314import java.util.List;
    1415import java.util.Map;
    1516import java.util.Map.Entry;
    1617import java.util.Set;
     18import org.openstreetmap.josm.tools.Utils;
    1719
    1820/**
     
    712714        // See #7201 combining ways screws up the order of ref tags
    713715        Set<String> originalValues = getValues(key);
    714         if (originalValues.size() == 1)
     716        if (originalValues.size() == 1) {
    715717            return originalValues.iterator().next();
    716 
    717         StringBuilder buffer = new StringBuilder();
    718         Set<String> valSet = new HashSet<String>();
    719         for (String vs : originalValues) {
    720             valSet.addAll(Arrays.asList(vs.split(";")));
    721         }
    722         List<String> values = new ArrayList<String>(valSet);
     718        }
     719
     720        Set<String> values = new LinkedHashSet<String>();
     721        Map<String, Collection<String>> originalSplitValues = new LinkedHashMap<String, Collection<String>>();
     722        for (String v : originalValues) {
     723            List<String> vs = Arrays.asList(v.split(";\\s*"));
     724            originalSplitValues.put(v, vs);
     725            values.addAll(vs);
     726        }
    723727        values.remove("");
    724         Collections.sort(values);
    725         Iterator<String> iter = values.iterator();
    726         while (iter.hasNext()) {
    727             buffer.append(iter.next());
    728             if (iter.hasNext()) {
    729                 buffer.append(";");
    730             }
    731         }
    732         return buffer.toString();
     728        // try to retain an already existing key if it contains all needed values (remove this if it causes performance problems)
     729        for (Entry<String, Collection<String>> i : originalSplitValues.entrySet()) {
     730            if (i.getValue().containsAll(values)) {
     731                return i.getKey();
     732            }
     733        }
     734        return Utils.join(";", values);
    733735    }
    734736
Note: See TracChangeset for help on using the changeset viewer.