ai.krr
Class AnonymousSymbol

java.lang.Object
  extended by ai.krr.SyntaxAdaptableSymbol
      extended by ai.krr.AnonymousSymbol
All Implemented Interfaces:
Symbol, inf.compilers.SyntaxAdaptable, java.lang.Comparable<Symbol>

public class AnonymousSymbol
extends SyntaxAdaptableSymbol

This class implements part of the foundations for symbolic programming in Java. A Symbol of this kind does not have a unique user-defined reference and consists of a type (a NamedSymbol) and a unique index (an int) for this AnonymousSymbol that is generated at construction time and cannot be changed.

As for the order of AnonymousSymbols, they are primarily ordered by their type. If they are of the same type, their index is used to determine the order between them.

Author:
Gerhard Wickler

Constructor Summary
AnonymousSymbol(NamedSymbol type)
           This constructor creates a new AnonymousSymbol of the given type.
 
Method Summary
 int compareTo(AnonymousSymbol aSy)
           This function compares this AnonymousSymbol to the given AnonymousSymbol.
 int compareTo(Symbol sy)
           This function compares this AnonymousSymbol to the given Symbol.
 int getClassOrderIndex()
           This function returns the index used for ordering Symbols across different classes.
 NamedSymbol getType()
           This function returns the type (a NamedSymbol) of this AnonymousSymbol.
 int hashCode()
           This function returns the hash code of this Symbol.
 java.lang.String toString()
           This function returns a printable representation of this AnonymousSymbol which is the type of this AnonymousSymbol followed by the index (without space).
 
Methods inherited from class ai.krr.SyntaxAdaptableSymbol
isBooleanSymbol, isNamedSymbol, isNumericSymbol, prettyPrint, read, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AnonymousSymbol

public AnonymousSymbol(NamedSymbol type)

This constructor creates a new AnonymousSymbol of the given type. Note: to create an AnonymousSymbol of an unknown type, specify some generic type, e.g. Thing.

Parameters:
type - the NamedSymbol that represents the category to which this Symbol belongs
Method Detail

getClassOrderIndex

public int getClassOrderIndex()

This function returns the index used for ordering Symbols across different classes. This index of this class is defined to be 160.

Returns:
an integer indicating how this type of Symbol is to be ordered with respect to different types of Symbol

compareTo

public int compareTo(Symbol sy)

This function compares this AnonymousSymbol to the given Symbol. Only NamedSymbols are considered to come after AnonymousSymbols in the order defined here. All other types of Symbols are considered to come before AnonymousSymbols.

Parameters:
sy - the Symbol to which this AnonymousSymbol is to be compared
Returns:
0 if the two AnonymousSymbols are identical; -1 if the given Symbol should come after this AnonymousSymbol; and +1 if the given Symbol should come before this AnonymousSymbol

getType

public final NamedSymbol getType()

This function returns the type (a NamedSymbol) of this AnonymousSymbol.

Returns:
the NamedSymbol representing the category of this symbol

compareTo

public int compareTo(AnonymousSymbol aSy)

This function compares this AnonymousSymbol to the given AnonymousSymbol. If they have different type then the order of the types determines the order between the two symbols here. Otherwise they are ordered by their index.

Parameters:
aSy - the AnonymousSymbol to which this AnonymousSymbol is compared
Returns:
0 if the two AnonymousSymbols are identical; -1 if the given Symbol should come after this AnonymousSymbol; and +1 if the given Symbol should come before this AnonymousSymbol

hashCode

public final int hashCode()

This function returns the hash code of this Symbol.

Overrides:
hashCode in class java.lang.Object
Returns:
a positive integer that may be used for hashing

toString

public java.lang.String toString()

This function returns a printable representation of this AnonymousSymbol which is the type of this AnonymousSymbol followed by the index (without space).

Overrides:
toString in class java.lang.Object
Returns:
type + index