FileDocCategorySizeDatePackage
EqualsUtil.javaAPI DocJaudiotagger 2.0.42177Wed Mar 30 16:11:42 BST 2011org.jaudiotagger.utils

EqualsUtil

public final class EqualsUtil extends Object
Collected methods which allow easy implementation of equals.

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.fName, that.fName) &&
EqualsUtil.areEqual(this.fNumDoors, that.fNumDoors) &&
EqualsUtil.areEqual(this.fGasMileage, that.fGasMileage) &&
EqualsUtil.areEqual(this.fColor, that.fColor) &&
Arrays.equals(this.fMaintenanceChecks, that.fMaintenanceChecks); //array!
}

Arrays are not handled by this class. This is because the Arrays.equals methods should be used for array fields.

Fields Summary
Constructors Summary
Methods Summary
public static booleanareEqual(boolean aThis, boolean aThat)

        //System.out.println("boolean");
        return aThis == aThat;
    
public static booleanareEqual(char aThis, char aThat)

        //System.out.println("char");
        return aThis == aThat;
    
public static booleanareEqual(long aThis, long aThat)

        /*
        * Implementation Note
        * Note that byte, short, and int are handled by this method, through
        * implicit conversion.
        */
        //System.out.println("long");
        return aThis == aThat;
    
public static booleanareEqual(float aThis, float aThat)

        //System.out.println("float");
        return Float.floatToIntBits(aThis) == Float.floatToIntBits(aThat);
    
public static booleanareEqual(double aThis, double aThat)

        //System.out.println("double");
        return Double.doubleToLongBits(aThis) == Double.doubleToLongBits(aThat);
    
public static booleanareEqual(java.lang.Object aThis, java.lang.Object aThat)
Possibly-null object field.

Includes type-safe enumerations and collections, but does not include arrays. See class comment.

        //System.out.println("Object");
        return aThis == null ? aThat == null : aThis.equals(aThat);