diff options
Diffstat (limited to 'sources')
-rw-r--r-- | sources/ch/epfl/lamp/util/Pair.java | 24 | ||||
-rw-r--r-- | sources/ch/epfl/lamp/util/StackedMap.java | 47 |
2 files changed, 71 insertions, 0 deletions
diff --git a/sources/ch/epfl/lamp/util/Pair.java b/sources/ch/epfl/lamp/util/Pair.java new file mode 100644 index 0000000000..0e0b0a3f93 --- /dev/null +++ b/sources/ch/epfl/lamp/util/Pair.java @@ -0,0 +1,24 @@ +/* ____ ____ ____ ____ ______ *\ +** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** +** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** +** /_____/\____/\___/\____/____/ ** +\* */ + +// $Id$ + +package ch.epfl.lamp.util; + +/** + * Pairs of values. + * + * @author Michel Schinz + * @version 1.0 + */ + +public class Pair { + public final Object fst, snd; + public Pair(Object fst, Object snd) { + this.fst = fst; + this.snd = snd; + } +} 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(); + } +} |