diff options
author | schinz <schinz@epfl.ch> | 2003-05-14 12:59:38 +0000 |
---|---|---|
committer | schinz <schinz@epfl.ch> | 2003-05-14 12:59:38 +0000 |
commit | fdd7ca356b5ed7a17c8a8d7a6166b35038313f12 (patch) | |
tree | f86c41987cee0e9b03fcc4d857107b3f8902a7ab /sources/ch/epfl/lamp/util/StackedMap.java | |
parent | 9de54c767175739a24141b615f1cff626b38d046 (diff) | |
download | scala-fdd7ca356b5ed7a17c8a8d7a6166b35038313f12.tar.gz scala-fdd7ca356b5ed7a17c8a8d7a6166b35038313f12.tar.bz2 scala-fdd7ca356b5ed7a17c8a8d7a6166b35038313f12.zip |
*** empty log message ***
Diffstat (limited to 'sources/ch/epfl/lamp/util/StackedMap.java')
-rw-r--r-- | sources/ch/epfl/lamp/util/StackedMap.java | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/sources/ch/epfl/lamp/util/StackedMap.java b/sources/ch/epfl/lamp/util/StackedMap.java new file mode 100644 index 0000000000..171976d7a0 --- /dev/null +++ b/sources/ch/epfl/lamp/util/StackedMap.java @@ -0,0 +1,47 @@ +package ch.epfl.lamp.util; + +import java.util.*; + +/** + * A stack of hash maps. + * + * @author Michel Schinz + * @version 1.0 + */ + +public class StackedHashMap extends AbstractMap implements Map { + protected LinkedList/*<HashMap>*/ maps = new LinkedList(); + protected HashMap topmostMap = new HashMap(); + + public void push() { + maps.addFirst(topmostMap); + topmostMap = new HashMap(topmostMap); + } + + public void push(Map map) { + push(); + topmostMap.putAll(map); + } + + public void pop() { + topmostMap = (HashMap)maps.removeFirst(); + } + + public Object put(Object key, Object value) { + return topmostMap.put(key, value); + } + + public void putAll(Object[] keys, Object[] values) { + assert keys.length == values.length; + for (int i = 0; i < keys.length; ++i) + topmostMap.put(keys[i], values[i]); + } + + public Object get(Object key) { + return topmostMap.get(key); + } + + public Set entrySet() { + return topmostMap.entrySet(); + } +} |