Parsing Engine

danbikel.lisp
Class Symbol

java.lang.Object
  extended bydanbikel.lisp.Sexp
      extended bydanbikel.lisp.Symbol
All Implemented Interfaces:
Externalizable, Serializable
Direct Known Subclasses:
IntSymbol, StringSymbol

public abstract class Symbol
extends Sexp

Symbol objects associate strings or integers with unique references. This abstract base class, from which StringSymbol and IntSymbol are derived, allows for Symbol objects that contain either an int or a String.

N.B.: The values in the internal map maintained by this class are actually weak references to unique Symbol objects. This allows the reclamation of symbols that are unreachable via strong (or soft) references. In this way, the programmer need never be concerned about the symbol map monotonically growing simply because the program continues to instantiate new symbols.

See Also:
StringSymbol, IntSymbol, Serialized Form

Constructor Summary
Symbol()
           
 
Method Summary
static Symbol add(int intValue)
          A convenience method for add(Integer): the specified int is first wrapped in an Integer object and then added to the internal symbol map.
static Symbol add(Integer intKey)
          A synonym for get(Integer).
static Symbol add(String str)
          A synonym for get(String).
static void clean()
          Cleans the internal symbol map by removing all symbols to which there are no hard or soft references.
 Sexp deepCopy()
          Returns a deep copy of this S-expression.
static Symbol get(int intValue)
          A convenience method for add(Integer): the specified int is first wrapped in an Integer object and then added to the internal symbol map.
static Symbol get(Integer intKey)
          Returns the unique Symbol whose integer value is that of intKey.
static Symbol get(String str)
          Returns the unique Symbol whose string key is str.
abstract  Integer getInteger()
          Gets the Integer object associated with this Symbol.
protected abstract  Object getSymKey()
          Gets the unique key for this symbol used by the internal symbol map.
 boolean isList()
          Returns false, as no instance of a subclass of this abstract base class can be a list.
 boolean isSymbol()
          Returns true, as any instance of a subclass of this abstract base class is a symbol.
abstract  String toString()
          Gets the string representation of this symbol.
 
Methods inherited from class danbikel.lisp.Sexp
getCanonical, list, main, read, read, readExternal, symbol, writeExternal
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Symbol

public Symbol()
Method Detail

getInteger

public abstract Integer getInteger()
Gets the Integer object associated with this Symbol.

Returns:
the Integer object associated with this Symbol if it's an instance of IntSymbol, else null.

toString

public abstract String toString()
Gets the string representation of this symbol.

Returns:
the print representation of this symbol.

getSymKey

protected abstract Object getSymKey()
Gets the unique key for this symbol used by the internal symbol map.

Returns:
the unique key for this symbol used by the internal symbol map.

deepCopy

public final Sexp deepCopy()
Description copied from class: Sexp
Returns a deep copy of this S-expression.

Specified by:
deepCopy in class Sexp
Returns:
a deep copy of this S-expression.

isList

public final boolean isList()
Returns false, as no instance of a subclass of this abstract base class can be a list.

Specified by:
isList in class Sexp
Returns:
false, as no instance of a subclass of this abstract base class can be a list.

isSymbol

public final boolean isSymbol()
Returns true, as any instance of a subclass of this abstract base class is a symbol.

Specified by:
isSymbol in class Sexp
Returns:
true, as any instance of a subclass of this abstract base class is a symbol.

get

public static final Symbol get(String str)
Returns the unique Symbol whose string key is str. If the symbol does not already exist in the internal symbol map, it is added and returned.

Parameters:
str - the print name of the string symbol to get
Returns:
the unique Symbol whose string key is str.

add

public static final Symbol add(String str)
A synonym for get(String).

Parameters:
str - the print name of the string symbol to get
Returns:
the unique Symbol whose string key is str.

get

public static final Symbol get(Integer intKey)
Returns the unique Symbol whose integer value is that of intKey. If the symbol does not already exist in the internal symbol map, it is added and returned.

Parameters:
intKey - the integer value of the symbol to get
Returns:
the unique Symbol whose integer value is that of intKey.

add

public static final Symbol add(Integer intKey)
A synonym for get(Integer).

Parameters:
intKey - the integer value of the symbol to get
Returns:
the unique Symbol whose integer value is that of intKey.

add

public static final Symbol add(int intValue)
A convenience method for add(Integer): the specified int is first wrapped in an Integer object and then added to the internal symbol map.

Parameters:
intValue - the integer value to be wrapped with an Integer and added to the symbol map
Returns:
the unique Symbol whose integer value is that of intValue.

get

public static final Symbol get(int intValue)
A convenience method for add(Integer): the specified int is first wrapped in an Integer object and then added to the internal symbol map.

Parameters:
intValue - the integer value to be wrapped with an Integer and added to the symbol map
Returns:
the unique Symbol whose integer value is that of intValue.

clean

public static final void clean()
Cleans the internal symbol map by removing all symbols to which there are no hard or soft references.


Parsing Engine

Author: Dan Bikel.