|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.jdo.tck.util.EqualityHelper
This is a utility class to support equality checking. An EqualityHelper object defines the context of a deepEquals call, because it keeps track of objects that have already been processed. This avoids endless recursion when comparing cyclic data structures for deep equality.
Furthermore, EqualityHelper provides convenience methods for checking deep equality, equality and close enough (for floating point values).
Field Summary | |
static double |
DOUBLE_EPSILON
Used when comparing double values close enough. |
static float |
FLOAT_EPSILON
Used when comparing float values close enough. |
Constructor Summary | |
EqualityHelper()
|
Method Summary | |
void |
clearProcessed()
Clears the collection of processed instances of this EqualityHelper . |
boolean |
closeEnough(double d1,
double d2)
Returns true if the specified float values are close
enough to be considered to be equal for a deep equals
comparison. |
boolean |
closeEnough(float f1,
float f2)
Returns true if the specified float values are close
enough to be considered to be equal for a deep equals
comparison. |
boolean |
closeEnough(java.lang.Object o1,
java.lang.Object o2)
Returns true if the specified objects are close
enough to be considered to be equal for a deep equals
comparison. |
boolean |
deepEquals(java.util.Collection mine,
java.util.Collection other)
Returns true if the specified collections are "deep
equal". |
boolean |
deepEquals(DeepEquality me,
DeepEquality other)
Returns true if the specified instances are "deep
equal". |
boolean |
deepEquals(java.util.Map mine,
java.util.Map other)
Returns true if the specified maps are "deep
equal". |
boolean |
deepEquals(java.lang.Object me,
java.lang.Object other)
Returns true if the specified instances are "deep
equal". |
boolean |
equals(java.math.BigDecimal bd1,
java.math.BigDecimal bd2)
Returns true , if compare called for the specified
BigDecimal objects returns 0 . |
boolean |
equals(java.lang.Object o1,
java.lang.Object o2)
Returns true if the specified objects are equal. |
boolean |
isProcessed(java.lang.Object obj)
Returns true if the specified instance has been
processed already in the context of this
EqualityHelper . |
void |
markProcessed(java.lang.Object obj)
Marks the specified instance as processed in the context of this EqualityHelper . |
boolean |
shallowEquals(java.util.Collection mine,
java.util.Collection other)
Returns true if the specified collections are "shallow
equal". |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static float FLOAT_EPSILON
public static double DOUBLE_EPSILON
Constructor Detail |
public EqualityHelper()
Method Detail |
public boolean isProcessed(java.lang.Object obj)
true
if the specified instance has been
processed already in the context of this
EqualityHelper
.
obj
- the instance to be checked.
true
if the instance has been processed
already; false
otherwise.public void markProcessed(java.lang.Object obj)
EqualityHelper
. This means the instance is added to the
collection of processed instances.
obj
- instance marked as processedpublic void clearProcessed()
EqualityHelper
. No instance is marked as processed in
the context of this EqualityHelper
after calling this
method.
public boolean deepEquals(DeepEquality me, DeepEquality other)
true
if the specified instances are "deep
equal".
me
- one object to be tested for deep equalityother
- the other object to be tested for deep equality
true
if the objects are deep equal.public boolean deepEquals(java.lang.Object me, java.lang.Object other)
true
if the specified instances are "deep
equal". The method compares the two instances via the deepEquals
method if they implement DeepEquals; compares the two instances via
deepEquals if they implement Collection or Map, and otherwise
compares the instances using equals.
me
- one object to be tested for deep equalityother
- the other object to be tested for deep equality
true
if the objects are deep equal.public boolean deepEquals(java.util.Collection mine, java.util.Collection other)
true
if the specified collections are "deep
equal". Two collections are deep equal, if they have the same size
and their corresponding elements are deep equal after sorting
using the natural ordering of the elements. The method throws a
ClassCastException
if the elements are not Comparable
or if they are not mutually comparable.
mine
- one collection to be tested for deep equalityother
- the other collection to be tested for deep equality
true
if the collections are deep equal.
java.lang.ClassCastException
- if the collections contain elements that
are not mutually comparable.public boolean deepEquals(java.util.Map mine, java.util.Map other)
true
if the specified maps are "deep
equal". Two maps are deep equal, if they have the same size and the
values of the corresponding keys compare deep equal. The method
throws a ClassCastException
if keys or values are not
Comparable or if they are not mutually comparable.
mine
- one map to be tested for deep equalityother
- the other map to be tested for deep equality
true
if the maps are deep equal.
java.lang.ClassCastException
- if the maps contain keys or values that
are not mutually comparable.public boolean shallowEquals(java.util.Collection mine, java.util.Collection other)
true
if the specified collections are "shallow
equal". Two collections are shallow equal, if they have the same size
and their corresponding elements are equal after sorting using the
natural ordering.
mine
- one collection to be tested for shallow equalityother
- the other collection to be tested for shallow equality
true
if the collections are deep equal.public boolean equals(java.lang.Object o1, java.lang.Object o2)
true
if the specified objects are equal.
This is a helper method checking for identical and null
objects before delegating to the regular equals method.
o1
- one object to be tested for equalityo2
- the other object to be tested for equality
true
if the specified objects are equal.public boolean equals(java.math.BigDecimal bd1, java.math.BigDecimal bd2)
true
, if compare called for the specified
BigDecimal objects returns 0
. Please note, two
BigDecimal instances are not equal (using equals) if their scale
differs, and this method compares the values, ignoring scale.
bd1
- one object to be tested for equalitybd2
- the other object to be tested for equality
true
if the specified BigDecimal objects are
equal.public boolean closeEnough(java.lang.Object o1, java.lang.Object o2)
true
if the specified objects are close
enough to be considered to be equal for a deep equals
comparison. The method delegates to the method taking double
or float values if the specified objects are Float or Double
wrappers. Otherwise it delegates to equals.
o1
- one object to be tested for close enougho2
- the other object to be tested for close enough
true
if the specified values are close enough.public boolean closeEnough(double d1, double d2)
true
if the specified float values are close
enough to be considered to be equal for a deep equals
comparison. Floating point values are not exact, so comparing them
using ==
might not return useful results. This method
checks that both double values are within some percent of each
other.
d1
- one double to be tested for close enoughd2
- the other double to be tested for close enough
true
if the specified values are close enough.public boolean closeEnough(float f1, float f2)
true
if the specified float values are close
enough to be considered to be equal for a deep equals
comparison. Floating point values are not exact, so comparing them
using ==
might not return useful results. This method
checks that both float values are within some percent of each
other.
f1
- one float to be tested for close enoughf2
- the other float to be tested for close enough
true
if the specified values are close enough.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |