public final class EqualUtils extends Object
equals
.
Rewritten from http://www.javapractices.com/topic/TopicAction.do?Id=17.
Example use case in a class called Car:
public boolean equals(Object aThat){ if ( this == aThat ) return true; if ( !(aThat instanceof Car) ) return false; Car that = (Car)aThat; return EqualsUtil.areEqual(this.name, that.name) && EqualsUtil.areEqual(this.numDoors, that.numDoors) && EqualsUtil.areEqual(this.gasMileage, that.gasMileage) && EqualsUtil.areEqual(this.color, that.color) && Arrays.equals(this.maintenanceChecks, that.maintenanceChecks); //array! }Arrays are not handled by this class. This is because the
Arrays.equals
methods should be used for
array fields.Constructor and Description |
---|
EqualUtils() |
Modifier and Type | Method and Description |
---|---|
static boolean |
areEqual(boolean aThis,
boolean aThat) |
static boolean |
areEqual(char aThis,
char aThat) |
static boolean |
areEqual(double aThis,
double aThat) |
static boolean |
areEqual(float aThis,
float aThat) |
static boolean |
areEqual(long aThis,
long aThat) |
static boolean |
areEqual(Object aThis,
Object aThat)
Possibly-null object field.
|
public static boolean areEqual(boolean aThis, boolean aThat)
public static boolean areEqual(char aThis, char aThat)
public static boolean areEqual(long aThis, long aThat)
public static boolean areEqual(float aThis, float aThat)
public static boolean areEqual(double aThis, double aThat)