removed illegal use of double-star
[sbp.git] / src / edu / berkeley / sbp / util / HashMapBag.java
1 package edu.berkeley.sbp.util;
2 import java.util.*;
3
4 /** a mapping from keys of type <tt>K</tt> to <i>sets</i> of values of type <tt>T</tt> */
5 public final class HashMapBag<K,V> implements MapBag<K,V> {
6
7     private final HashMap<K,HashSet<V>> hm = new HashMap<K,HashSet<V>>();
8
9     public void add(K k, V v) {
10         HashSet<V> hs = hm.get(k);
11         if (hs==null) hm.put(k, hs = new HashSet<V>());
12         hs.add(v);
13     }
14
15     public void addAll(K k, Iterable<V> iv) {
16         for(V v : iv) add(k, v);
17     }
18
19     public HashSet<V> getAll(K k) {
20         HashSet<V> ret = hm.get(k);
21         if (ret==null) return new HashSet<V>();
22         return ret;
23     }
24
25     public Iterator<K> iterator() { return hm.keySet().iterator(); }
26 }