bug fixes
[IRC.git] / Robust / src / IR / Tree / ChainHashMap.java
1 package IR.Tree;
2
3 import java.util.*;
4
5 public class ChainHashMap<K,V> extends AbstractMap<K,V> {
6   private ChainHashMap<K,V> parent;
7   private HashMap<K,V> table;
8
9   public ChainHashMap() {
10     table=new HashMap<K,V>();
11   }
12
13   public ChainHashMap<K,V> makeChild() {
14     ChainHashMap<K,V> chm=new ChainHashMap<K,V>();
15     chm.parent=this;
16     return chm;
17   }
18
19   public ChainHashMap<K,V> getParent() {
20     return parent;
21   }
22
23   public V put(K key, V value) {
24     return table.put(key, value);
25   }
26
27   public V get(Object o) {
28     K key=(K) o;
29     if (table.containsKey(key))
30       return table.get(key);
31     else if (parent!=null)
32       return parent.get(key);
33     else
34       return null;
35   }
36
37   public boolean containsKey(Object o) {
38     K key=(K)o;
39     if (table.containsKey(key))
40       return true;
41     else if (parent!=null)
42       return parent.containsKey(key);
43     else
44       return false;
45   }
46
47   public Set<Map.Entry<K,V>> entrySet() {
48     throw new Error("ChainHashMap does not support entrySet");
49   }
50 }