|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | ENUM CONSTANTS | FIELD | METHOD | DETAIL: ENUM CONSTANTS | FIELD | METHOD | |||||||||
java.lang.Objectjava.lang.Enum<BasicEquals>
net.sf.staccatocommons.lang.value.BasicEquals
public enum BasicEquals
Enumeration of equalty-test scenarios that helps on building effective
Object.equals(Object) method.
Normal usage scenario is the following:
public boolean equals(Object obj) {
BasicEquals be = BasicEquals.from(this, obj);
if (be.isEqualsDone())
return be.toEquals();
MyClass that = (MyClass) obj;
... test equalty based on internal state ...
return ....;
}
BasicEquals observes the following rules:
BasicEquals implements rule nÂș 3 using a class-comparison strategy -
as opposed to instanceof-comparison strategy. In many scenarios this is just
enough, but this may not be the better strategy always, so client code should
take care about it.
EqualsBuilder,
Object.equals(Object)| Enum Constant Summary | |
|---|---|
ALWAYS
BasicEquals test result where the two objects are always equal,
because their are the same object |
|
MAYBE
BasicEquals test result where the two objects may be equal if and
only if the have a similar internal state |
|
NEVER
BasicEquals test result where the two objects can never be equal,
as either have different classes, or the second one is null |
|
| Method Summary | ||
|---|---|---|
static
|
from(T this_,
Object that)
Performs a BasicEquals test |
|
abstract boolean |
isEqualsDone()
Answers if this basic equalty-test result is enough to determine if the two objects given are equal or not |
|
abstract boolean |
toEquals()
Returns the equals test based on this basic equals test result. |
|
static BasicEquals |
valueOf(String name)
Returns the enum constant of this type with the specified name. |
|
static BasicEquals[] |
values()
Returns an array containing the constants of this enum type, in the order they are declared. |
|
| Methods inherited from class java.lang.Enum |
|---|
clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf |
| Methods inherited from class java.lang.Object |
|---|
getClass, notify, notifyAll, wait, wait, wait |
| Enum Constant Detail |
|---|
public static final BasicEquals ALWAYS
BasicEquals test result where the two objects are always equal,
because their are the same object
public static final BasicEquals NEVER
BasicEquals test result where the two objects can never be equal,
as either have different classes, or the second one is null
public static final BasicEquals MAYBE
BasicEquals test result where the two objects may be equal if and
only if the have a similar internal state
| Method Detail |
|---|
public static BasicEquals[] values()
for (BasicEquals c : BasicEquals.values()) System.out.println(c);
public static BasicEquals valueOf(String name)
name - the name of the enum constant to be returned.
IllegalArgumentException - if this enum type has no constant
with the specified name
NullPointerException - if the argument is null
@NonNull
public static <T> BasicEquals from(@NonNull
T this_,
Object that)
BasicEquals test
T - this_ - the "left hand" object to test equalty, that is, the object to
wich the equals message has been sentthat - the "right hand" objet of the equlty test, that is, the object
that is parameter of the the equals message the
NEVER if that is null or its class is not the
same that this_.getClass(), ALWAYS if both
objects are the same, or MAYBE otherwisepublic abstract boolean toEquals()
isEqualsDone().
ALWAYS or false if this is NEVER
IllegalStateException - of this is MAYBEpublic abstract boolean isEqualsDone()
true for NEVER and ALWAYS,
false for MAYBE
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | ENUM CONSTANTS | FIELD | METHOD | DETAIL: ENUM CONSTANTS | FIELD | METHOD | |||||||||