ai.krr
Class NamedSymbol

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

public class NamedSymbol
extends SyntaxAdaptableSymbol

This class implements part of the foundations for symbolic programming in Java. A NamedSymbol consists of a String that is its name and the NameSpace to which it belongs. NamedSymbols are memory unique objects, i.e. there are no two NamedSymbols that are equal, but not the same Object in memory.

NamedSymbols are maintained in their NameSpace. This is why there is no public constructor provided by the class; instead, the NameSpace that will own the NamedSymbol may create a new NamedSymbol. However, a NamedSymbol may be created as strictly internal in which case it does not belong to a NameSpace. Use the static function getInternalSymbol(java.lang.String) to get hold of this type of symbol.

NamedSymbols are primarily ordered by the NameSpace they belong to, and secondarily by their name.

Author:
Gerhard Wickler
See Also:
NameSpace

Constructor Summary
protected NamedSymbol(NameSpace ns, java.lang.String name)
           This constructor creates a new NamedSymbol that has the given name and belongs to the given NameSpace.
 
Method Summary
protected  java.lang.Object clone()
           This class does not support cloning and an Exception will be thrown if this method is called.
 int compareTo(NamedSymbol namedSy)
           This function compares this NamedSymbol to the given NamedSymbol.
 int compareTo(Symbol sy)
           This function compares this NamedSymbol to the given Symbol.
 int getClassOrderIndex()
           This function returns the index used for ordering Symbols across different classes.
static NamedSymbol getInternalSymbol(java.lang.String name)
           This function must be used to obtain a new or the existing internal NamedSymbol for the given name.
 java.lang.String getName()
           This function returns the name of this NamedSymbol.
 NameSpace getNameSpace()
           This function returns the NameSpace to which this NamedSymbol belongs.
 int hashCode()
           This function computes a hash value for this symbol by combining the hashCode() of the name with the hashCode() of the NameSpace.
 boolean isInternal()
           This function returns whether this NamedSymbol is internal.
 boolean isNamedSymbol()
           This function tests whether this Symbol is a NamedSymbol.
 java.lang.String toString()
           This function returns a printable representation of this NamedSymbol which is the URI for its NameSpace followed by the hash character followed by the name of the symbol.
 java.lang.String toString(java.util.Map<NameSpace,java.lang.String> proxies)
           This function returns a printable representation of this NamedSymbol which is an abbreviation for the NameSpace from the given Map followed by the colon character followed by the name of the symbol.
 
Methods inherited from class ai.krr.SyntaxAdaptableSymbol
isBooleanSymbol, isNumericSymbol, prettyPrint, read, write
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

NamedSymbol

protected NamedSymbol(NameSpace ns,
                      java.lang.String name)

This constructor creates a new NamedSymbol that has the given name and belongs to the given NameSpace. The given name must not be null or the empty String. The NameSpace may be null in which case this NamedSymbol is is considered to be strictly internal.

Parameters:
ns - the NameSpace that owns this NamedSymbol
name - the name given to this NamedSymbol; null for internal
Method Detail

clone

protected java.lang.Object clone()
                          throws java.lang.CloneNotSupportedException

This class does not support cloning and an Exception will be thrown if this method is called.

Overrides:
clone in class java.lang.Object
Returns:
nothing
Throws:
java.lang.CloneNotSupportedException - will be thrown

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 224.

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

isNamedSymbol

public boolean isNamedSymbol()

This function tests whether this Symbol is a NamedSymbol.

Specified by:
isNamedSymbol in interface Symbol
Overrides:
isNamedSymbol in class SyntaxAdaptableSymbol
Returns:
always true

compareTo

public int compareTo(Symbol sy)

This function compares this NamedSymbol to the given Symbol. The order between different kinds of Symbols is arbitrarily defined as (ascending): BooleanSymbol, NumericSymbol, CharacterSymbol, StringSymbol, AnonymousSymbol, NamedSymbol.

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

getNameSpace

public final NameSpace getNameSpace()

This function returns the NameSpace to which this NamedSymbol belongs.

Returns:
the NameSpace that owns this NamedSymbol; null for internal

getName

public final java.lang.String getName()

This function returns the name of this NamedSymbol. The result is not the same as that of toString() as the name does not include any reference to the NameSpace.

Returns:
String the name of this NamedSymbol

isInternal

public boolean isInternal()

This function returns whether this NamedSymbol is internal. This is true iff it does not belong to a NameSpace.

Returns:
true if the NameSpace is null

compareTo

public int compareTo(NamedSymbol namedSy)

This function compares this NamedSymbol to the given NamedSymbol. Two NamedSymbols in the same NameSpace are compared by name. Otherwise the order is determined by the order of the NameSpaces. Internal NamedSymbols that have no NameSpace precede other NamedSymbols.

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

hashCode

public final int hashCode()

This function computes a hash value for this symbol by combining the hashCode() of the name with the hashCode() of the NameSpace.

Overrides:
hashCode in class java.lang.Object
Returns:
a simple hash value

toString

public java.lang.String toString()

This function returns a printable representation of this NamedSymbol which is the URI for its NameSpace followed by the hash character followed by the name of the symbol.

Overrides:
toString in class java.lang.Object
Returns:
ns + '#' + name

toString

public java.lang.String toString(java.util.Map<NameSpace,java.lang.String> proxies)

This function returns a printable representation of this NamedSymbol which is an abbreviation for the NameSpace from the given Map followed by the colon character followed by the name of the symbol.

Parameters:
proxies - the abbreviation table for NameSpace URIs
Returns:
ns-abbreviation + ':' + name

getInternalSymbol

public static NamedSymbol getInternalSymbol(java.lang.String name)

This function must be used to obtain a new or the existing internal NamedSymbol for the given name. Note: the given String must not be null or the empty String.

Parameters:
name - the name of the internal symbol that will be returned
Returns:
the one and only NamedSymbol identified by the given String