|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.pojomatic.internal.PojomatorImpl<T>
public class PojomatorImpl<T>
Constructor Summary | |
---|---|
PojomatorImpl(java.lang.Class<T> clazz)
Creates an instance for clazz . |
Method Summary | |
---|---|
Differences |
doDiff(T instance,
T other)
Compute the differences between instance and other among the properties
examined by Pojomator.doEquals(Object, Object) . |
boolean |
doEquals(T instance,
java.lang.Object other)
Compute whether instance and other are equal to each other in the sense of
Object 's equals method. |
int |
doHashCode(T instance)
Compute the hashCode for a given instance of T . |
java.lang.String |
doToString(T instance)
Compute the toString representation for a given instance of T |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public PojomatorImpl(java.lang.Class<T> clazz) throws java.lang.IllegalArgumentException
clazz
.
clazz
- the class
java.lang.IllegalArgumentException
- if clazz
has no properties annotated for use
with PojomaticMethod Detail |
---|
public boolean doEquals(T instance, java.lang.Object other)
instance
and other
are equal to each other in the sense of
Object
's equals
method.
For this to return true, the following must hold:
other
must be non-null, and an instance of T
instance
which has a PojomaticPolicy
other than
TO_STRING
or NONE
must be equal
to the corresponding property of other
in the following sense:
null
, or
equals method of Arrays
returns true, orArrays.deepEquals(Object[], Object[])
returns true, orp
in instance
is an object not of array type, and
instanceP.equals(otherP)
returns true.
doEquals
in interface Pojomator<T>
instance
- the instance to test against - must not be null
other
- the instance to test
true
if instance
should be considered equal to other
, and
false
otherwise.
java.lang.NullPointerException
- if instance
is nullObject.equals(Object)
public int doHashCode(T instance)
T
.
This is done by computing the hashCode of each property which has a PojomaticPolicy
of
HASHCODE_EQUALS
or ALL
(using 0 when the property is null), and combining them in a fashion similar to that of
List.hashCode()
.
doHashCode
in interface Pojomator<T>
instance
- the instance to compute the hashCode for - must not be null
instance
java.lang.NullPointerException
- if instance
is nullObject.hashCode()
public java.lang.String doToString(T instance)
toString
representation for a given instance of T
The format used depends on the
PojoFormatter
used for the POJO, and the PropertyFormatter
of each property.
For example, suppose a class Person
has properties firstName
and
lastName
which are included in its String
representation.
No PojoFormatter
or PropertyFormatter
are specified, so the defaults are used.
In particular, instances of DefaultPropertyFormatter
will be created for
firstName
and lastName
(referred to here as firstNameFormatter
and
lastNameFormatter
, respectively). Let firstNameProperty
and
lastNameProperty
refer to the instances of PropertyElement
referring to the
properties firstName
and lastName
respectively.
For a non-null Person
instance, the String
representation will be created by
creating an instance of DefaultPojoFormatter
for the Person
class (referred to
here as personFormatter
), and then concatenating the results of following:
personFormatter.getToStringPrefix(Person.class)
personFormatter.getPropertyPrefix(firstNameProperty)
firstNameFormatter.format(firstName)
personFormatter.getPropertySuffix(firstNameProperty)
personFormatter.getPropertyPrefix(lastNameProperty)
lastNameFormatter.format(lastName)
personFormatter.getPropertySuffix(lasttNameProperty)
personFormatter.getToStringSuffix(Person.class)
doToString
in interface Pojomator<T>
instance
- the instance to compute the toString
representation for - must not be null
toString
representation of instance
java.lang.NullPointerException
- if instance
is nullProperty.name()
public Differences doDiff(T instance, T other)
Pojomator
instance
and other
among the properties
examined by Pojomator.doEquals(Object, Object)
. It is guaranteed that invoking
Differences.areEqual()
on the returned object will return true iff
instance.equals(other)
.
doDiff
in interface Pojomator<T>
instance
- the instance to diff against - must not be null
other
- the instance to diff
instance
and other
among the properties examined by Pojomator.doEquals(Object, Object)
.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |