Class NametableStack
- java.lang.Object
-
- org.onemind.commons.java.datastructure.NametableStack
-
public class NametableStack extends java.lang.Object
A nametable stack contains key-value mapping that has a scope. A new scope can be opened for putting new mappings and all the mappings added in this scope can be wiped out easily with a closeScope command. In effect this is like a stack of Maps, hence the name NametableStack. NOTE: the implementation use a map and list to achieve the behaviour.- Version:
- $Id: NametableStack.java,v 1.7 2005/06/22 22:57:37 thlee Exp $ $Name: $
- Author:
- TiongHiang Lee (thlee@onemindsoft.org)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
NametableStack.LocalNametable
The local nametable defines a scope where local variables mask out the global variables, but the global variable can still be accessed.
-
Field Summary
Fields Modifier and Type Field Description private java.util.ArrayList
_list
the list of maps *private static java.util.logging.Logger
_logger
the logger *private Nametable
_nametable
the map *
-
Constructor Summary
Constructors Constructor Description NametableStack()
NametableStack(java.util.Map m)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Object
access(java.lang.String name)
Resolve the value associated with key namejava.util.Map
asMap()
Return map representation of the nametable stackjava.lang.Object
assign(java.lang.String name, java.lang.Object value)
Assign name/value pairvoid
closeLocalScope(int i)
void
closeScope(int l)
Close a scopeboolean
containsName(java.lang.String name)
Whether the map contains key namevoid
declare(java.lang.String name, java.lang.Object value)
Declare name value pairint
newLocalScope()
int
newScope()
Open a new scope for mappings.java.lang.String
toString()
-
-
-
Field Detail
-
_logger
private static final java.util.logging.Logger _logger
the logger *
-
_nametable
private Nametable _nametable
the map *
-
_list
private java.util.ArrayList _list
the list of maps *
-
-
Method Detail
-
newScope
public int newScope()
Open a new scope for mappings. Return an integer that represents a scope id- Returns:
- the new scope
-
newLocalScope
public int newLocalScope()
-
closeLocalScope
public void closeLocalScope(int i)
-
closeScope
public void closeScope(int l)
Close a scope- Parameters:
l
- the scope id
-
declare
public void declare(java.lang.String name, java.lang.Object value)
Declare name value pair- Parameters:
name
-value
-
-
assign
public java.lang.Object assign(java.lang.String name, java.lang.Object value)
Assign name/value pair- Parameters:
name
-value
-- Returns:
-
access
public java.lang.Object access(java.lang.String name)
Resolve the value associated with key name- Parameters:
name
- the key- Returns:
- the value associated with key
-
containsName
public boolean containsName(java.lang.String name)
Whether the map contains key name- Parameters:
name
- the key- Returns:
- true if map contains key name
-
asMap
public java.util.Map asMap()
Return map representation of the nametable stack- Returns:
- the map
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-