|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.sadun.util.BaseObjectWithId
A base implementation of ObjectWithId
.
This partial implementation stores the object id in the protected
field #id
, and can be used both for classes requiring id based equality only
or requring also type-equality.
It also provides a default ObjectWithIdMetadata
in #metadata
, defininig:
metadata
(that is, a string with which every id must start) by
Subclasses may set #metadata
independently in a static intializer; if the id prefix is set
to null, no check is made on the id pattern when a new object is constructed.
Field Summary | |
protected java.lang.String |
objectId
The id of the object. |
protected static java.util.Map |
objectWithIdMetadataMap
|
Constructor Summary | |
protected |
BaseObjectWithId(java.lang.String id)
Create an instance with the given id and which will equate only
to object of the same type.
|
protected |
BaseObjectWithId(java.lang.String id,
boolean requireSameTypeForEquality)
Create an instance of the class with the given id which will or will not perform a type comparison in the equals(Object) method, depending on the value of the
requireSameTypeForEquality parameter.
|
Method Summary | |
protected void |
checkPrefix(java.lang.String id,
ObjectWithIdMetadata metadata)
This method is used at construction to verify whether the given id is suitable for the object, and shoud throw an IllegalArgumentException if it not. |
protected void |
clearModified()
Subclasses may use this method to set the "modified" status of the object to true. |
boolean |
equals(java.lang.Object obj)
Verifies if two object are the same, by comparing their ids. |
protected boolean |
equalWithNoObjectWithId(java.lang.Object obj)
Subclasses may override this method to implement an equality check with some other type than ObjectWithId .
|
java.lang.String |
getId()
Return the unique id of the object. |
ObjectWithIdMetadata |
getMetadata()
Return the value of the #metadata field.
|
int |
hashCode()
Return an hash code for the object, obtained by its id. |
boolean |
isModified()
This method return true if the object "modified" status has been set by setModified() . |
protected void |
setModified()
Subclasses may use this method to set the "modified" status of the object to true. |
Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected static transient java.util.Map objectWithIdMetadataMap
protected java.lang.String objectId
Constructor Detail |
protected BaseObjectWithId(java.lang.String id, boolean requireSameTypeForEquality)
equals(Object)
method, depending on the value of the
requireSameTypeForEquality parameter.
Unless #metadata
returns a null id prefix
,
the constructor also checks that the given id matches the class (see class comment).
id
- the unique id of the objectrequireSameTypeForEquality
- if true, equals(Object)
will perform also a type comparsino besides an id comparison.protected BaseObjectWithId(java.lang.String id)
equate
only
to object of the same type.
Unless #metadata
is null, the constructor also checks that the given
id matches the class id prefix
(see class comment).
id
- the unique id of the objectMethod Detail |
protected void checkPrefix(java.lang.String id, ObjectWithIdMetadata metadata)
This method can be overridden by subclasses.
This implementation accepts only prefixes which start with the id prefix specified by the metadata.
metadata
- the metadata for the object
java.lang.IllegalArgumentException
- if the id is invalid.public java.lang.String getId()
getId
in interface ObjectWithId
ObjectWithId.getId()
public final boolean equals(java.lang.Object obj)
construction
parameter
requireSameTypeForEquality, the comparison may also require that the
compared object has the same class as this object.
obj
- the object to compare
protected boolean equalWithNoObjectWithId(java.lang.Object obj)
ObjectWithId
.
This implementation returns false.
obj
- the object to compare (which is not an ObjectWithId
.
public final int hashCode()
public ObjectWithIdMetadata getMetadata()
#metadata
field.
The metadata is set on a per-class basis.
getMetadata
in interface ObjectWithId
metadata
for the object.ObjectWithId.getMetadata()
protected final void setModified()
Typically this is done in setters.
protected final void clearModified()
public final boolean isModified()
setModified()
.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |