changes: generated annotated code but it still causes type errors + re-formatting...
[IRC.git] / Robust / src / Analysis / SSJava / MultiSourceMap.java
1 package Analysis.SSJava;
2
3 import java.util.HashSet;
4 import java.util.Hashtable;
5 import java.util.Set;
6
7 public class MultiSourceMap<T, V> {
8
9   Hashtable<T, Set<V>> map;
10
11   public MultiSourceMap() {
12     map = new Hashtable<T, Set<V>>();
13   }
14
15   public void put(T key, Set<V> set) {
16     map.put(key, set);
17   }
18
19   public void put(T key, T setKey, Set<V> set) {
20
21     if (!map.containsKey(setKey)) {
22       map.put(setKey, set);
23     }
24     map.put(key, set);
25   }
26
27   public void put(T key, T setKey, V value) {
28
29     if (setKey == null) {
30       if (map.containsKey(key)) {
31         Set<V> set = map.get(key);
32         set.add(value);
33       } else {
34         // first insert
35         Set<V> set = new HashSet<V>();
36         set.add(value);
37         map.put(key, set);
38       }
39     } else {
40       assert map.containsKey(setKey);
41       Set<V> set = map.get(setKey);
42       set.add(value);
43       map.put(key, set);
44     }
45   }
46
47   public Set<V> get(T key) {
48     return map.get(key);
49   }
50
51   public String toString() {
52     return map.toString();
53   }
54
55
56   public Set<T> keySet() {
57     return map.keySet();
58   }
59
60   public void union(T newKey, Set<V> writeSet) {
61
62     if (map.containsKey(newKey)) {
63       map.get(newKey).addAll(writeSet);
64     } else {
65       put(newKey, writeSet);
66     }
67
68   }
69 }