diff --git a/src/org/openstreetmap/josm/data/osm/Tag.java b/src/org/openstreetmap/josm/data/osm/Tag.java
index 8216955..7f7df4e 100644
a
|
b
|
public class Tag {
|
78 | 78 | return this.key.equals(key); |
79 | 79 | } |
80 | 80 | |
81 | | /** |
82 | | * Normalizes the key and the value of the tag by |
83 | | * <ul> |
84 | | * <li>removing leading and trailing white space</li> |
85 | | * <ul> |
86 | | * |
87 | | */ |
88 | | public void normalize() { |
89 | | key = key.trim(); |
90 | | value = value.trim(); |
91 | | } |
92 | | |
93 | 81 | @Override |
94 | 82 | public int hashCode() { |
95 | 83 | final int prime = 31; |
diff --git a/src/org/openstreetmap/josm/data/osm/TagCollection.java b/src/org/openstreetmap/josm/data/osm/TagCollection.java
index 0435382..442265a 100644
a
|
b
|
import static org.openstreetmap.josm.tools.I18n.tr;
|
6 | 6 | import java.util.ArrayList; |
7 | 7 | import java.util.Arrays; |
8 | 8 | import java.util.Collection; |
9 | | import java.util.Collections; |
10 | 9 | import java.util.HashMap; |
11 | 10 | import java.util.HashSet; |
12 | 11 | import java.util.Iterator; |
| 12 | import java.util.LinkedHashMap; |
| 13 | import java.util.LinkedHashSet; |
13 | 14 | import java.util.List; |
14 | 15 | import java.util.Map; |
15 | 16 | import java.util.Map.Entry; |
16 | 17 | import java.util.Set; |
| 18 | import org.openstreetmap.josm.tools.Utils; |
17 | 19 | |
18 | 20 | /** |
19 | 21 | * TagCollection is a collection of tags which can be used to manipulate |
… |
… |
public class TagCollection implements Iterable<Tag> {
|
711 | 713 | |
712 | 714 | // See #7201 combining ways screws up the order of ref tags |
713 | 715 | Set<String> originalValues = getValues(key); |
714 | | if (originalValues.size() == 1) |
| 716 | if (originalValues.size() == 1) { |
715 | 717 | return originalValues.iterator().next(); |
| 718 | } |
716 | 719 | |
717 | | StringBuilder buffer = new StringBuilder(); |
718 | | Set<String> valSet = new HashSet<String>(); |
719 | | for (String vs : originalValues) { |
720 | | valSet.addAll(Arrays.asList(vs.split(";"))); |
| 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); |
721 | 726 | } |
722 | | List<String> values = new ArrayList<String>(valSet); |
723 | 727 | 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(";"); |
| 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(); |
730 | 732 | } |
731 | 733 | } |
732 | | return buffer.toString(); |
| 734 | return Utils.join(";", values); |
733 | 735 | } |
734 | 736 | |
735 | 737 | @Override |