Id. So if you have a person, create a PersonId
extending Id.
- Version:
- $Id: Id.java,v 1.5 2003/02/13 22:13:42 bratseth Exp $
- Author:
- Jon S Bratseth
- See Also:
- Serialized Form
Constructor Summary |
Id(java.lang.String uniqueValue)
Create a unique id from a unique string |
Method Summary |
int |
compareTo(java.lang.Object object)
Comparable is implemented to support consistent ordering of id collections.
|
java.lang.Object |
createTypeInstance()
Creates an instance of the type this is an id for.
|
boolean |
equals(java.lang.Object id)
|
java.lang.Class |
getType()
Returns the type of this id as a class.
|
java.lang.String |
getTypeName()
Returns the type of this id.
|
int |
hashCode()
|
java.lang.String |
stringValue()
Returns the string value of this id |
java.lang.String |
toString()
Returns a string describing this id |
Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Id
public Id(java.lang.String uniqueValue)
- Create a unique id from a unique string
hashCode
public int hashCode()
- Overrides:
hashCode
in class java.lang.Object
equals
public boolean equals(java.lang.Object id)
- Overrides:
equals
in class java.lang.Object
compareTo
public int compareTo(java.lang.Object object)
- Comparable is implemented to support consistent ordering of id collections.
This is useful even if most id's are not instended for humans.
- Specified by:
compareTo
in interface java.lang.Comparable
getTypeName
public java.lang.String getTypeName()
Returns the type of this id.
The type is by definition the short class
name of this class preceeding "Id".
So if you have an id class org.foo.BarId,
the type name returned is "Bar".
The type of a non-subclassed id is the empty string.
A different naming scheme can be facilitated by
overriding this method (and probably createTypeInstance
and getType as well).
getType
public java.lang.Class getType()
- Returns the type of this id as a class.
This is not the class of this id, but of the type it is an id of.
- Returns:
- the class
- Throws:
java.lang.RuntimeException
- if it can not find the class
createTypeInstance
public java.lang.Object createTypeInstance()
- Creates an instance of the type this is an id for.
The type name must be the same as the id name minus the
"Id", and it must have a constructor taking an id as the only
argument
- Returns:
- the new type instance or null if no such contructor exists
- Throws:
ReflectionException
- if the type could not be created
stringValue
public java.lang.String stringValue()
- Returns the string value of this id
toString
public java.lang.String toString()
- Returns a string describing this id
- Overrides:
toString
in class java.lang.Object
Spif 1.01 (2003-04-03). http://spif.sf.net