1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package net.sf.zel.vm;
19
20 import java.util.Collection;
21 import java.util.HashMap;
22 import java.util.Map;
23 import java.util.Set;
24
25
26
27
28
29 public final class StackedMap<K,V>
30 implements Map<K,V>
31 {
32
33 private final SimpleStack<Map<K, V>> stack;
34
35 public StackedMap()
36 {
37 stack = new SimpleStack<Map<K, V>>();
38 stack.push(new HashMap<K, V>());
39 }
40
41
42 public void push()
43 {
44 stack.push(new HashMap<K, V>());
45 }
46
47 public Map<K,V> pop()
48 {
49 return stack.pop();
50 }
51
52
53
54 @Override
55 public void putAll(Map m)
56 {
57 stack.peek().putAll(m);
58 }
59
60 @Override
61 public void clear()
62 {
63 stack.clear();
64 stack.push(new HashMap());
65 }
66
67 @Override
68 public Set keySet()
69 {
70 throw new UnsupportedOperationException("Not supported yet.");
71 }
72
73 @Override
74 public Collection values()
75 {
76 throw new UnsupportedOperationException("Not supported yet.");
77 }
78
79 @Override
80 public Set entrySet()
81 {
82 throw new UnsupportedOperationException("Not supported yet.");
83 }
84
85 @Override
86 public V get(final Object key)
87 {
88 int i = stack.getPtr() - 1;
89 while (i >= 0)
90 {
91 Map<K, V> m = stack.getFromPtr(i);
92 @SuppressWarnings("element-type-mismatch")
93 V o = m.get(key);
94 if (o != null)
95 {
96 return o;
97 }
98 i--;
99 }
100 return null;
101 }
102
103 @Override
104 public int size()
105 {
106 throw new UnsupportedOperationException("Not supported yet.");
107 }
108
109 @Override
110 public boolean isEmpty()
111 {
112 throw new UnsupportedOperationException("Not supported yet.");
113 }
114
115
116 @Override
117 public V put(final K key, final V value)
118 {
119 return stack.peek().put(key, value);
120 }
121
122 @Override
123 public boolean containsKey(final Object key)
124 {
125 throw new UnsupportedOperationException("Not supported yet.");
126 }
127
128 @Override
129 public boolean containsValue(final Object value)
130 {
131 throw new UnsupportedOperationException("Not supported yet.");
132 }
133
134 @Override
135 @SuppressWarnings("element-type-mismatch")
136 public V remove(final Object key)
137 {
138 return stack.peek().remove(key);
139 }
140
141 }
142