|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.pojomatic.Pojomatic
public class Pojomatic
Static methods for implementing the Object.equals(Object)
,
Object.hashCode()
and Object.toString()
methods on a
annotated POJO. The actual work for a given class is done by a Pojomator
created for
that class. This class is careful to create only a single Pojomator
per POJO class.
The overhead for looking up the Pojomator
by POJO class is light, so a typical use in a
POJO class would be
@Override public int hashCode() {
return Pojomatic.hashCode(this);
}
@Override public boolean equals(Object other) {
return Pojomatic.equals(this, other);
}
@Override public String toString() {
return Pojomatic.toString(this);
}
Pojomator
instance
which is created lazily and cached on a per-class basis. The performance penalty for this is
negligible, but if an interface is annotated for Pojomation, using the Pojomator
directly
is required, since the Pojomator
for a class will only reference properties in the class
and it's superclasses, but not any implemented interfaces. To do this, first define a static
constant POJOMATOR
in the interface:
import org.pojomatic.annotations.AutoProperty;
import org.pojomatic.Pojomator;
import org.pojomatic.Pojomatic;
@AutoProperty
public interface Interface {
static Pojomator<Interface> POJOMATOR = Pojomatic.pojomator(Interface.class);
...
}
POJOMATOR
in the implementing classes:
public class Implementation implements Interface {
@Override public int hashCode() {
return POJOMATOR.doHashCode(this);
}
@Override public boolean equals(Object other) {
return POJOMATOR.doEquals(this, other);
}
@Override public String toString() {
return POJOMATOR.doToString(this);
}
...
}
Pojomator
Method Summary | ||
---|---|---|
static boolean |
areCompatibleForEquals(java.lang.Class<?> classA,
java.lang.Class<?> classB)
Compute whether classA and classB are compatible for equality as specified
by the documentation for Pojomator.isCompatibleForEquality(Class) . |
|
static
|
diff(T pojo,
S other)
Compute the differences between pojo and other among the properties
examined by equals(Object, Object) for type T . |
|
static
|
equals(T pojo,
java.lang.Object other)
Compute whether pojo and other are equal to each other in the sense of
Object 's equals method. |
|
static
|
hashCode(T pojo)
Compute the hashCode for a POJO. |
|
static
|
pojomator(java.lang.Class<T> pojoClass)
Get the Pojomator for pojoClass . |
|
static
|
toString(T pojo)
Compute the toString representation for a POJO. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static <T> java.lang.String toString(T pojo) throws NoPojomaticPropertiesException
toString
representation for a POJO.
T
- the type of the POJOpojo
- the POJO - must not be null
toString
representation of pojo
.
NoPojomaticPropertiesException
- if pojo
's class has no properties annotated for
use with PojomaticPojomator.doToString(Object)
public static <T> int hashCode(T pojo) throws NoPojomaticPropertiesException
hashCode
for a POJO.
T
- the type of the POJOpojo
- the POJO - must not be null
hashCode
for pojo
.
NoPojomaticPropertiesException
- if pojo
's class has no properties annotated for
use with PojomaticPojomator.doHashCode(Object)
public static <T> boolean equals(T pojo, java.lang.Object other) throws NoPojomaticPropertiesException
pojo
and other
are equal to each other in the sense of
Object
's equals
method.
T
- the type of the POJOpojo
- the POJO - must not be nullother
- the object to compare to for equality
pojo
and other
are equal to each other in the sense of
Object
's equals
method.
NoPojomaticPropertiesException
- if pojo
's class has no properties annotated for
use with PojomaticPojomator.doEquals(Object, Object)
public static boolean areCompatibleForEquals(java.lang.Class<?> classA, java.lang.Class<?> classB)
classA
and classB
are compatible for equality as specified
by the documentation for Pojomator.isCompatibleForEquality(Class)
.
classA
- the first class to check for compatibility for equalityclassB
- the second class to check for compatibility for equality
true
if the two classes are compatible for equality, or false
otherwise.public static <T,S extends T> Differences diff(T pojo, S other) throws java.lang.NullPointerException, NoPojomaticPropertiesException
pojo
and other
among the properties
examined by equals(Object, Object)
for type T
.
T
- the static type of the first object to compareS
- the static type of the first object to comparepojo
- the instance to diff againstother
- the instance to diff
instance
and other
among the properties examined by equals(Object, Object)
for type T
.
java.lang.NullPointerException
- if pojo
or other
are null
(this behavior may change in future releases).
NoPojomaticPropertiesException
- if pojo
's class has no properties
annotated for use with Pojomatic, or if the types of pojo
and other
are not
compatible for equality with each other (this behavior may change in future releases).public static <T> Pojomator<T> pojomator(java.lang.Class<T> pojoClass) throws NoPojomaticPropertiesException
Pojomator
for pojoClass
. The same instance will be returned every time
for a given value of pojoClass
.
T
- the type represented by pojoClass
pojoClass
- the class to create a Pojomator
for.
Pojomator<T>
NoPojomaticPropertiesException
- if pojoClass
has no properties annotated for use
with Pojomatic
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |