org.norecess.citkit.symboltable
Class EmptySymbolTable<T>

java.lang.Object
  extended by org.norecess.citkit.symboltable.EmptySymbolTable<T>
All Implemented Interfaces:
SymbolTable<T>

public class EmptySymbolTable<T>
extends java.lang.Object
implements SymbolTable<T>

This class allows other symbol-table implementations to avoid null checks. Think of this class like a header node in a linked list: it exists to make certain algorithms a bit cleaner, but you don't actually store any useful information in it.

Do not bother creating your own instances of this class. A good SymbolTable implementation will use this class automatically (e.g., HashSymbolTable.HashSymbolTable() does).

Author:
Jeremy D. Frens

Constructor Summary
EmptySymbolTable()
          Standard constructor.
 
Method Summary
 void add(java.lang.String name, T value)
          Always throws an exception.
 void add(Symbol variable, T value)
          Always throws an exception.
 boolean equals(java.lang.Object other)
           
 T get(ISymbol variable)
          For this implementation, this method always returns null since the variable is not found.
 T get(java.lang.String name)
          Always returns null.
 java.util.Set<Symbol> getSymbols()
          Returns an empty list of symbols since there are no symbols in an empty symbol table.
 java.lang.String getVariablesAsString()
          Returns an empty string since an empty symbol table has no variables to turn into a string.
 int hashCode()
           
 T set(java.lang.String name, T value)
          Returns null.
 T set(Symbol variable, T value)
          Based on previous implementations, this method returns null.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EmptySymbolTable

public EmptySymbolTable()
Standard constructor.

Method Detail

equals

public boolean equals(java.lang.Object other)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

add

public void add(Symbol variable,
                T value)
Always throws an exception. Variables must not be added to this empty symbol table. If it weren't for this class, implementations would use a null reference for the previous symbol table, and you would get NullPointerExceptions instead.

Specified by:
add in interface SymbolTable<T>
Parameters:
variable - the new variable to add to the symbol table.
value - the new value to associate with the new variable.
Throws:
java.lang.IllegalStateException - always throws this exception because it keeps no state information.

add

public void add(java.lang.String name,
                T value)
Always throws an exception.

Specified by:
add in interface SymbolTable<T>
See Also:
add(Symbol, Object)

get

public T get(ISymbol variable)
For this implementation, this method always returns null since the variable is not found.

Specified by:
get in interface SymbolTable<T>
Parameters:
variable - the name of the variable which won't be found.
Returns:
null

get

public T get(java.lang.String name)
Always returns null.

Specified by:
get in interface SymbolTable<T>
See Also:
get(ISymbol)

getSymbols

public java.util.Set<Symbol> getSymbols()
Returns an empty list of symbols since there are no symbols in an empty symbol table.

Specified by:
getSymbols in interface SymbolTable<T>
Returns:
empty set.

getVariablesAsString

public java.lang.String getVariablesAsString()
Returns an empty string since an empty symbol table has no variables to turn into a string.

Specified by:
getVariablesAsString in interface SymbolTable<T>

set

public T set(Symbol variable,
             T value)
Based on previous implementations, this method returns null. This can be construed as misleading since the variable was never defined, and no value has been changed.

Specified by:
set in interface SymbolTable<T>
Parameters:
variable - the variable that was never defined.
value - the new value that will be ignored.
Returns:
null.

set

public T set(java.lang.String name,
             T value)
Returns null.

Specified by:
set in interface SymbolTable<T>
See Also:
set(Symbol, Object)