Class NametableStack.LocalNametable
- java.lang.Object
-
- org.onemind.commons.java.datastructure.NametableStack.LocalNametable
-
- All Implemented Interfaces:
Nametable
- Enclosing class:
- NametableStack
private static class NametableStack.LocalNametable extends java.lang.Object implements Nametable
The local nametable defines a scope where local variables mask out the global variables, but the global variable can still be accessed. This is useful for implementing function context- Author:
- TiongHiang Lee (thlee@onemindsoft.org)
-
-
Constructor Summary
Constructors Modifier Constructor Description private
LocalNametable(Nametable global, int scope)
Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Object
access(java.lang.String name)
Access the value associated with namejava.util.Map
asMap()
Return map representation of this nametablejava.lang.Object
assign(java.lang.String name, java.lang.Object value)
Assign a variable in the name tableboolean
containsName(java.lang.String key)
Whether the nametable contains the namevoid
declare(java.lang.String name, java.lang.Object value)
Declare a variable in the name tableprivate Nametable
getGlobal()
Get the globaljava.lang.String
toString()
void
undeclare(java.lang.String name)
Undeclare the name
-
-
-
Field Detail
-
_locals
private final java.util.Map _locals
the local variables
-
_global
private final Nametable _global
the global map
-
_scope
private final int _scope
the scope
-
-
Constructor Detail
-
LocalNametable
private LocalNametable(Nametable global, int scope)
Constructor- Parameters:
global
- the globalscope
- the scope # where this local nametabe is openned
-
-
Method Detail
-
getGlobal
private Nametable getGlobal()
Get the global- Returns:
- the global
-
containsName
public boolean containsName(java.lang.String key)
Whether the nametable contains the name- Specified by:
containsName
in interfaceNametable
- Parameters:
key
- the name- Returns:
- true if contains the name
-
declare
public void declare(java.lang.String name, java.lang.Object value)
Declare a variable in the name table
-
assign
public java.lang.Object assign(java.lang.String name, java.lang.Object value)
Assign a variable in the name table
-
access
public java.lang.Object access(java.lang.String name)
Access the value associated with name
-
undeclare
public void undeclare(java.lang.String name)
Undeclare the name
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-