T - the class this Pojomator is generated for.BasePojomatorpublic interface Pojomator<T>
Object methods,
Object.equals(Object), Object.hashCode() and Object.toString(), as
well as a useful method to aid in debugging, doDiff(Object, Object).
Object is annotated with @SkipArrayCheck, then
Pojomatic will not check to see if it's value might be of array type. Typically, the reason for annotating a property
with @SkipArrayCheck would be to gain a slight performance advantage by avoiding a call to
Object.getClass().isArray().| Modifier and Type | Method | Description |
|---|---|---|
Differences |
doDiff(T instance,
T other) |
Compute the differences between
instance and other among the properties
examined by doEquals(Object, Object). |
boolean |
doEquals(T instance,
Object other) |
|
int |
doHashCode(T instance) |
Compute the hashCode for a given instance of
T. |
String |
doToString(T instance) |
Compute the
toString representation for a given instance of T. |
boolean |
isCompatibleForEquality(Class<?> otherClass) |
Compute whether
otherClass is compatible for equality with T. |
String |
toString() |
Return a simple String representation of this Pojomator.
|
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().instance - the instance to compute the hashCode for - must not be nullinstanceNullPointerException - if instance is nullObject.hashCode()String doToString(T instance)
toString representation for a given instance of T.
The format used depends on the
EnhancedPojoFormatter used for the POJO, and the EnhancedPropertyFormatter of each property.
For example, suppose a class Person has properties String name and
int age which are included in its String representation.
No EnhancedPojoFormatter or EnhancedPropertyFormatter are specified, so the defaults are used.
In particular, instances of DefaultEnhancedPropertyFormatter will be created for
name and age (referred to here as nameFormatter and
ageFormatter, respectively). Let nameProperty and
ageProperty refer to the instances of PropertyElement referring to the
properties name and age respectively.
For a non-null Person instance, the String representation will be created by
creating an instance of DefaultEnhancedPojoFormatter for the Person class (referred to
here as personFormatter), a StringBuilder (referred to here as builder), and then invoking the
following methods in order:
personFormatter.appendToStringPrefix(builder, Person.class)personFormatter.appendPropertyPrefix(builder, nameProperty)nameFormatter.appendFormatted(builder, name)personFormatter.appendPropertySuffix(builder, nameProperty)personFormatter.appendPropertyPrefix(builder, ageProperty)ageFormatter.appendFormatted(age)personFormatter.appendPropertySuffix(builder, ageProperty)personFormatter.appendToStringSuffix(builder, Person.class)instance - the instance to compute the toString representation for - must not be nulltoString representation of instanceNullPointerException - if instance is nullObject.toString(),
Property.name()boolean doEquals(T instance, Object other)
instance and other are equal to each other in the sense of
Object's equals method. For two instances to be
considered equal, the first requirement is that their classes must be compatible for equality,
as described in the documentation for isCompatibleForEquality(Class).
More precisely, if other is null, this method returns false. Otherwise, if
isCompatibleForEquals(other.getClass()) would return
false, then this method will return false. Otherwise, this method will return true provided
that each property of instance which has a PojomaticPolicy other than
TO_STRING or NONE is equal to the corresponding property of other in
the following sense:
null, orp in instance is an object not of array type, and
instanceP.equals(otherP) returns true.p is Object, the property is annotated with
@SkipArrayCheck, and instanceP.equals(otherP) returns true.Object, and the property is
not annotated with @SkipArrayCheck, and:
instanceP.getClass().equals(otherP.getClass()),instanceP.length == otherP.length, andinstanceP is equal to the corresponding element of otherP.
Note that Pojomator's treatment of multi-dimensional arrays can differ from
Arrays.deepEquals(Object[], Object[]), in that the latter only looks at array length and element-wise
equality, but not array type. For example, Arrays.deepEquals() would consider new Integer[0] and
new boolean[0][][]) to be equal, where as Pojomatic does not. Version 1.0 of Pojomatic simply delegated to
Arrays.deepEquals(), and hence would have considered those two arrays to be equal.
instance - the instance to test against - must not be nullother - the instance to testtrue if instance should be considered equal to other, and
false otherwise.NullPointerException - if instance is nullObject.equals(Object)boolean isCompatibleForEquality(Class<?> otherClass)
otherClass is compatible for equality with T.
Classes A and B are compatible for equality if
they share a common superclass C, and for every class D which
is a proper subclass of C and a superclass of A or B (including
the classes A and B themselves), the following hold:
D has not added additional properties for inclusion in the equals calculation, andD has not been annotated with OverridesEqualsT is an interface or is annotated with SubclassCannotOverrideEquals,
then all subclasses of T are automatically assumed by T's Pojomator
to be compatible for equals with each other and with T. Note that in this case.
to add an OverridesEquals annotation or additional
properties for inclusion in equals to a subclass of T will
result in a violation of the contract for Object.equals(Object).otherClass - the class to check for compatibility for equality with Ttrue if otherClass is compatible for equality with T, and
false otherwise.Differences doDiff(T instance, T other)
instance and other among the properties
examined by doEquals(Object, Object). Assuming that instance and other
are both non-null and have types which are compatible for equals, it is guaranteed that invoking
Differences.areEqual() on the returned object will return true iff
instance.equals(other).instance - the instance to diff againstother - the instance to diffinstance and other
among the properties examined by doEquals(Object, Object).NullPointerException - if instance or other is null
(this behavior may change in future releases).IllegalArgumentException - the type of instance or of other is not a
class which is compatible for equality with T
(this behavior may change in future releases).doEquals(Object, Object)String toString()
Copyright © 2008–2018. All rights reserved.