- Timestamp:
- 2010-10-24T10:25:26+02:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/MultiMap.java
r3083 r3637 4 4 import java.util.HashMap; 5 5 import java.util.LinkedHashSet; 6 import java.util.Map; 7 import java.util.Set; 6 8 7 9 /** 8 10 * Maps keys to ordered sets of values. 9 11 */ 10 public class MultiMap<A, B> extends HashMap<A, LinkedHashSet<B>> { 12 public class MultiMap<A, B> { 13 14 private final Map<A, LinkedHashSet<B>> map = new HashMap<A, LinkedHashSet<B>>(); 11 15 /** 12 16 * Map a key to a value. Can be called multiple times with the same key, but different value. 13 17 */ 14 18 public void put(A key, B value) { 15 LinkedHashSet<B> vals = get(key);19 LinkedHashSet<B> vals = map.get(key); 16 20 if (vals == null) { 17 21 vals = new LinkedHashSet<B>(); 18 put(key, vals);22 map.put(key, vals); 19 23 } 20 24 vals.add(value); … … 25 29 */ 26 30 public void putVoid(A key) { 27 if ( containsKey(key))31 if (map.containsKey(key)) 28 32 return; 29 put(key, new LinkedHashSet<B>());33 map.put(key, new LinkedHashSet<B>()); 30 34 } 31 35 … … 35 39 */ 36 40 public LinkedHashSet<B> getValues(A key) { 37 if (! containsKey(key))41 if (!map.containsKey(key)) 38 42 return new LinkedHashSet<B>(); 39 return get(key); 43 return map.get(key); 44 } 45 46 public Set<A> keySet() { 47 return map.keySet(); 48 } 49 50 public Set<B> get(A key) { 51 return map.get(key); 40 52 } 41 53 }
Note:
See TracChangeset
for help on using the changeset viewer.