|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.norecess.citkit.environment.Environment<T>
public class Environment<T>
Implements a variable environment for a Hobbes interpreter. Variables must be
defined in the source before they can be used or re-set; this is handled by
add(ISymbol, Object). Variables are retrieved with
get(ISymbol). Variable are reset with a new value through
set(ISymbol, Object).
The InvalidVariableException class is used as a general "you did
something wrong with a variable" problem. It applies in three situations: (1)
a variable is redeclared in the same scope; (2) an undeclared variable is
accessed; and (3) an undeclared variable's value is re-set.
| Constructor Summary | |
|---|---|
Environment()
|
|
Environment(IEnvironment<T> previous)
|
|
Environment(java.util.Map<ISymbol,T> currentScope,
IEnvironment<T> previous)
|
|
| Method Summary | |
|---|---|
void |
add(ISymbol variable,
T value)
Adds a new variable to the current environment. |
Environment<T> |
create()
Creates a nested environment. |
void |
define(ISymbol variable,
T value)
Defines the variable in the top level environment. |
boolean |
equals(java.lang.Object o)
|
T |
get(ISymbol variable)
Returns the value associated with the specified variable. |
int |
hashCode()
|
T |
set(ISymbol variable,
T value)
Changes the value associated with the specified variable. |
java.lang.String |
toString()
|
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public Environment()
public Environment(IEnvironment<T> previous)
public Environment(java.util.Map<ISymbol,T> currentScope,
IEnvironment<T> previous)
| Method Detail |
|---|
public boolean equals(java.lang.Object o)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Object
public void define(ISymbol variable,
T value)
IEnvironment
define in interface IEnvironment<T>variable - the variable to define.value - the value to set it to.
public void add(ISymbol variable,
T value)
throws InvalidVariableException
IEnvironment
add in interface IEnvironment<T>variable - the new variable to add to the environment.value - the new value to associate with the new variable.
InvalidVariableException - when the variable is already declared in the current
scope.
public T get(ISymbol variable)
throws InvalidVariableException
IEnvironment
get in interface IEnvironment<T>variable - the variable to search for.
InvalidVariableException - when the variable is undeclared (in this or any previous
scope).
public T set(ISymbol variable,
T value)
throws InvalidVariableException
IEnvironment
set in interface IEnvironment<T>variable - the variable to search for.value - the new value for the variable.
InvalidVariableException - when the variable is undeclared (in this or any previous
scope).public java.lang.String toString()
toString in class java.lang.Objectpublic Environment<T> create()
IEnvironment
create in interface IEnvironment<T>
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||