Class ScopedMap<K,V>

java.lang.Object
  extended by ScopedMap<K,V>

public class ScopedMap<K,V>
extends java.lang.Object

A ScopedMap is similar to a Map, but with nested scopes.


Constructor Summary
ScopedMap()
          makes a ScopedMap that maps no keys to values and is set to the global scope (nesting level 0)
 
Method Summary
 void enterScope()
          sets the ScopedMap to a new scope nested inside the previous one; the nesting level increases by one
 void exitScope()
          exits from the current scope back to the containing one; the nesting level, which must have been positive, decreases by one
 V get(K key)
          gets the value corresponding to the key, at the innermost scope for which there is one; if there is none, returns null
 V getLocal(K key)
          gets the value corresponding to the key at the current scope (not any surrounding one); if there is none, returns null
 int getNestingLevel()
          returns the current nesting level
 void put(K key, V value)
          puts the key/value pair in at the current scope; if the key is already in at the current nesting level, the new value replaces the old one; neither the key nor the value may be null
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ScopedMap

public ScopedMap()
makes a ScopedMap that maps no keys to values and is set to the global scope (nesting level 0)

Method Detail

enterScope

public void enterScope()
sets the ScopedMap to a new scope nested inside the previous one; the nesting level increases by one


exitScope

public void exitScope()
exits from the current scope back to the containing one; the nesting level, which must have been positive, decreases by one


put

public void put(K key,
                V value)
puts the key/value pair in at the current scope; if the key is already in at the current nesting level, the new value replaces the old one; neither the key nor the value may be null


get

public V get(K key)
gets the value corresponding to the key, at the innermost scope for which there is one; if there is none, returns null


getLocal

public V getLocal(K key)
gets the value corresponding to the key at the current scope (not any surrounding one); if there is none, returns null


getNestingLevel

public int getNestingLevel()
returns the current nesting level