All Packages Class Hierarchy This Package Previous Next Index
Class JavaAgent.resource.fopl.Symbol
java.lang.Object
|
+----JavaAgent.resource.fopl.Symbol
- public class Symbol
- extends Object
This class implements the foundations for symbolic programming in
Java. At the moment a Symbol is basically a String that is its name.
Using the Symbol class should be slightly more efficient than using
Strings and there may be extensions in future.
The cunning thing about Symbols is that there is only one Symbol
with any given name. They are memory-unique objects. This saves memory
if the same Symbol is used frequently and allows for efficient equality
testing by comparing handles instead of content.
- See Also:
- UnnamedSymbol
-
theName
- the name of the Symbol
-
Symbol(String)
-
This protected constructor is used mainly by the static function
get() to create new Symbols.
-
clone()
- Cloning a Symbol returns the same Symbol, not a copy!
-
equals(Object)
-
This function tests whether two Symbols are the same.
-
get(String)
-
This function must be used to get hold of Symbols with the given
name.
-
hashCode()
-
The hashCode() of a Symbol is the hashCode() of the
String that is its name.
-
toString()
-
A Symbol is printed as the String that is its name.
theName
protected String theName
- the name of the Symbol
Symbol
protected Symbol(String aName) throws IllegalArgumentException
- This protected constructor is used mainly by the static function
get() to create new Symbols.
- Parameters:
- aName - the name of the new Symbol
- Throws: IllegalArgumentException
- An exception will occur if the
supplied String is empty or null.
get
public static Symbol get(String aName) throws IllegalArgumentException
- This function must be used to get hold of Symbols with the given
name. It effectively replaces a public constructor. For example,
Symbol mySy = Symbol.get("Foo");
initializes mySy with the Symbol named "Foo".
If a Symbol with the given name has been gotten before, this very
Symbol will be returned. Otherwise get() will use the protected
constructor to create the new Symbol.
- Parameters:
- aName - the name of the Symbol seeked
- Returns:
- the Symbol with the given name
- Throws: IllegalArgumentException
- An exception will occur if the
supplied String is empty or null.
clone
public Object clone()
- Cloning a Symbol returns the same Symbol, not a copy!
- Returns:
- this Symbol
- Overrides:
- clone in class Object
equals
public boolean equals(Object otherSy)
- This function tests whether two Symbols are the same. The test
compares the physical address in memory and should thus be more
efficient than String comparison. Note that there cannot be two
different Symbols with the same name.
- Parameters:
- otherSy - the Object this one is compared to
- Returns:
- whether the other Object is the same as this
- Overrides:
- equals in class Object
toString
public String toString()
- A Symbol is printed as the String that is its name.
- Returns:
- the String that is the name of this Symbol
- Overrides:
- toString in class Object
hashCode
public int hashCode()
- The hashCode() of a Symbol is the hashCode() of the
String that is its name.
- Returns:
- the hashCode of this Symbol's name
- Overrides:
- hashCode in class Object
All Packages Class Hierarchy This Package Previous Next Index