tenua.symbol
Class SymbolTable

java.lang.Object
  extended by tenua.symbol.SymbolTable

public class SymbolTable
extends java.lang.Object


Constructor Summary
SymbolTable()
           
 
Method Summary
static void ensureDefault(java.lang.String name, double val)
          Saves a default value to the user preferences if one was not previously saved
 Symbol get(java.lang.String key)
          returns the Symbol associated with key
 VariableMemento getMemento()
          returns a memento of all the variable default values
 java.lang.String lookup(java.lang.Object s)
          Looks for an Object in the symbol table
 Symbol put(double d)
          adds an unnamed constant to the SymbolTable
 Symbol put(java.lang.String name)
          adds a new variable
 Symbol put(java.lang.String name, double d)
          adds a named constant to the SymbolTable
 Symbol put(java.lang.String key, Symbol s)
          inserts n in the SymbolTable associated with key, replacing the previous association
 void saveToPreferences(VariableMemento v)
          Saves all the current values of the variables into the user preferences
 Vec subset(java.util.List names, VariableMemento v)
          returns a Vec that represents a subset of the values in the symbol table
 Vec subset(java.lang.String[] names, VariableMemento v)
          returns a Vec that represents a subset of the values in the symbol table
 java.lang.String[] variableList()
          returns an array of names of all the variables
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SymbolTable

public SymbolTable()
Method Detail

get

public Symbol get(java.lang.String key)
returns the Symbol associated with key


put

public Symbol put(java.lang.String key,
                  Symbol s)
inserts n in the SymbolTable associated with key, replacing the previous association

Parameters:
key - the name
s - the symbol
Returns:
the new value in this SymbolTable of key

put

public Symbol put(double d)
           throws tenua.symbol.UnexpectedSymbolException
adds an unnamed constant to the SymbolTable

Parameters:
d - the value to add
Returns:
the Symbol created
Throws:
UnexpectedSymbolException - if a Symbol with the name Double.toString(d) already exists but is not a Value

put

public Symbol put(java.lang.String name,
                  double d)
adds a named constant to the SymbolTable

Parameters:
name - the name of the constant
d - its value
Returns:
the Symbol created
Throws:
UnexpectedSymbolException - if the name was previously defined

put

public Symbol put(java.lang.String name)
adds a new variable

Parameters:
name - the name of the new Symbol
Returns:
the Symbol created
Throws:
UnexpectedSymbolException - if name was previously defined to something that is not a variable or value

lookup

public java.lang.String lookup(java.lang.Object s)
Looks for an Object in the symbol table

Parameters:
s - the Object to look for
Returns:
the name of the Object if found; null otherwise

getMemento

public VariableMemento getMemento()
returns a memento of all the variable default values


subset

public Vec subset(java.util.List names,
                  VariableMemento v)
returns a Vec that represents a subset of the values in the symbol table

Parameters:
names - List of String of the names of the symbols
v - the VariableMemento to use
Returns:
the Vec. Vec.get(i) will the same as get(name[i]).getValue(v) and Vec.set(i,d) will be the same as ((Variable) get(name[i])).assign (v, d)
Throws:
UnexpectedSymbolException - if a name is not a Value

subset

public Vec subset(java.lang.String[] names,
                  VariableMemento v)
returns a Vec that represents a subset of the values in the symbol table

Parameters:
names - String[] of the names of the symbols
v - the VariableMemento to use
Returns:
the Vec. Vec.get(i) will the same as get(name[i]).getValue(v) and Vec.set(i,d) will be the same as ((Variable) get(name[i])).assign (v, d)
Throws:
UnexpectedSymbolException - if a name is not a Value

variableList

public java.lang.String[] variableList()
returns an array of names of all the variables


ensureDefault

public static void ensureDefault(java.lang.String name,
                                 double val)
Saves a default value to the user preferences if one was not previously saved

Parameters:
name - the name of the variable to save
val - the value

saveToPreferences

public void saveToPreferences(VariableMemento v)
Saves all the current values of the variables into the user preferences

Parameters:
v - the VariableMemento to use (if null, uses the default values)