DataType - the type of the data held by the DataWithUid
instancepublic final class DataWithUid<DataType> extends Object
equals are considered to be equivalent
objects).
This class overrides equals and
hashCode, so that two DataWithUid instances are
considered equivalent, if and only if, their ID equal (according to their
equals method).
ID and
the data is immutable, then the DataWithUid is
completely immutable.
| Constructor and Description |
|---|
DataWithUid(DataType data)
|
DataWithUid(DataType data,
Object id)
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
equals(Object obj)
Checks whether the passed object is a
DataWithUid and has an
equivalent ID or not. |
DataType |
getData()
Returns the data specified at construction time.
|
Object |
getID()
Returns the ID which is used to determine if two
data
is to be considered equivalent. |
int |
hashCode()
Returns a hash code which can be used in has tables and is compatible
with the
equals method. |
String |
toString()
Returns the string representation of this
DataWithUid in no
particular format. |
public DataWithUid(DataType data)
public DataWithUid(DataType data, Object id)
data - the data held by the DataWithUid instance. This
argument is allowed to be null.id - the ID identifying the given data. That is, only this ID needs
to be compared to determine if two data is equivalent. This argument
can be null but note that null ID can only be
equivalent to another null ID.public DataType getData()
ID.null if null was specified at construction time.public Object getID()
data
is to be considered equivalent. That is, if the IDs are equivalent
according to their equals method, the data
they identify should be considered equal as well. Note that it is allowed
for the data objects to have an equals method
inconsistent with the IDs.data
is to be considered equivalent. This method may return null and
null values can be equivalent only to other null
values.public boolean equals(Object obj)
DataWithUid and has an
equivalent ID or not. That is, this method returns true, if and
only if, the passed object is an instance of DataWithUid and
its ID is also equals to the ID of this DataWithUid.equals in class Objectobj - the object to which this DataWithUid is to be compared
to. This argument can be null, in which case this method
returns false.true, the passed object is an instance of
DataWithUid and its ID is also equals to the ID of this
DataWithUid, false otherwisepublic int hashCode()
equals method.hashCode in class Objectequals methodObject.equals(Object),
Object.hashCode()public String toString()