source: josm/trunk/src/org/openstreetmap/josm/tools/MultiMap.java@ 3486

Last change on this file since 3486 was 3083, checked in by bastiK, 14 years ago

added svn:eol-style=native to source files

  • Property svn:eol-style set to native
File size: 1.0 KB
Line 
1// License: GPL. See LICENSE file for details.
2package org.openstreetmap.josm.tools;
3
4import java.util.HashMap;
5import java.util.LinkedHashSet;
6
7/**
8 * Maps keys to ordered sets of values.
9 */
10public class MultiMap<A, B> extends HashMap<A, LinkedHashSet<B>> {
11 /**
12 * Map a key to a value. Can be called multiple times with the same key, but different value.
13 */
14 public void put(A key, B value) {
15 LinkedHashSet<B> vals = get(key);
16 if (vals == null) {
17 vals = new LinkedHashSet<B>();
18 put(key, vals);
19 }
20 vals.add(value);
21 }
22
23 /**
24 * Put a key that maps to nothing.
25 */
26 public void putVoid(A key) {
27 if (containsKey(key))
28 return;
29 put(key, new LinkedHashSet<B>());
30 }
31
32 /**
33 * Returns a list of values for the given key
34 * or an empty list, if it maps to nothing.
35 */
36 public LinkedHashSet<B> getValues(A key) {
37 if (!containsKey(key))
38 return new LinkedHashSet<B>();
39 return get(key);
40 }
41}
Note: See TracBrowser for help on using the repository browser.