|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.mit.csail.sdg.alloy4.Env<K,V>
V
- - the type for Valuepublic final class Env<K,V>
Mutable; implements a undoable map based on hashCode() and equals(); null key and values are allowed.
To be more precise, every key is internally mapped to a list of values.
The put(X,Y) method appends Y onto the end of X's list.
The get(X) method returns the last element in X's list.
The remove(X) method removes the last element in X's list.
This is very useful for representing lexical scoping: when a local variable is introduced with the same name as an existing variable, the new variable "hides" the old mapping; and when the new variable falls out of scope, the previous mapping is once again "revealed".
Constructor Summary | |
---|---|
Env()
Constructs an initially empty environment. |
Method Summary | |
---|---|
void |
clear()
Removes all mappings. |
Env<K,V> |
dup()
Make a shallow copy of this environment. |
V |
get(K key)
Returns the latest value associated with the key (and returns null if none). |
boolean |
has(K key)
Returns true if the key is mapped to one or more values. |
void |
put(K key,
V value)
Associates the key with the value (which can be null). |
void |
remove(K key)
Removes the latest mapping for the key (and if the key had previous mappings, they become visible). |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Env()
Method Detail |
---|
public boolean has(K key)
public V get(K key)
Since null is also a possible value, if you get null as the answer, you need to call has(key) to determine whether the key really has a mapping or not.
public void put(K key, V value)
public void remove(K key)
public void clear()
public Env<K,V> dup()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |