public final class ObjectUtil extends Object
All equals() methods in this class take the two fields to compare for equality as arguments and return whether they are equal. Consequently, the equals() method of class AClass should be implemented (taking advantage of the equals() methods in this class) as follows:
public boolean equals(Object o) { if (o == this) return true; // if this class AClass is a direct sub-class of Object: if (o == null) return false; if (!o.getClass().equals(this.getClass())) return false; // else if this class AClass extends another class than Object: //if (!super.equals(o)) return false; AClass that = (AClass) o; // only compare fields of this class AClass (not of super-classes): //if (!ObjectUtil.equals(this.field, that.field)) return false; // this and that are identical if we made it 'til here return true; }
All hashCode() methods in this class take the current hashCode value as the first argument and the field to take into account as the second argument and return the newly calculated hashCode value (which now includes the influence of the given field). Consequently, the hashCode() method of class AClass should be implemented (taking advantage of the hashCode() methods in this class) as follows:
public int hashCode() { // if this class AClass is a direct sub-class of Object: int hc = 0; // else if this class AClass extends another class than Object: //int hc = super.hashCode(); // only take into account fields of this class AClass (not of super-class): //hc = ObjectUtil.hashCode(hc, field); return hc; }
Modifier and Type | Field and Description |
---|---|
static int |
PRIME
the current hashCode is always first multiplied with this prime before the hashCode value for a particular field is
added.
|
Constructor and Description |
---|
ObjectUtil() |
Modifier and Type | Method and Description |
---|---|
static boolean |
equals(boolean[] a1,
boolean[] a2) |
static boolean |
equals(boolean b1,
boolean b2) |
static boolean |
equals(double[] a1,
double[] a2) |
static boolean |
equals(double d1,
double d2) |
static boolean |
equals(float[] a1,
float[] a2) |
static boolean |
equals(float f1,
float f2) |
static boolean |
equals(int[] a1,
int[] a2) |
static boolean |
equals(int i1,
int i2) |
static boolean |
equals(long[] a1,
long[] a2) |
static boolean |
equals(long l1,
long l2) |
static boolean |
equals(Object[] a1,
Object[] a2) |
static boolean |
equals(Object o1,
Object o2) |
static int |
hashCode(int currentHashCodeValue,
boolean b) |
static int |
hashCode(int currentHashCodeValue,
boolean[] a) |
static int |
hashCode(int currentHashCodeValue,
double d) |
static int |
hashCode(int currentHashCodeValue,
double[] a) |
static int |
hashCode(int currentHashCodeValue,
float f) |
static int |
hashCode(int currentHashCodeValue,
float[] a) |
static int |
hashCode(int currentHashCodeValue,
int i) |
static int |
hashCode(int currentHashCodeValue,
int[] a) |
static int |
hashCode(int currentHashCodeValue,
long l) |
static int |
hashCode(int currentHashCodeValue,
long[] a) |
static int |
hashCode(int currentHashCodeValue,
Object o) |
static int |
hashCode(int currentHashCodeValue,
Object[] a) |
public static final int PRIME
public ObjectUtil()
public static boolean equals(boolean b1, boolean b2)
public static boolean equals(int i1, int i2)
public static boolean equals(long l1, long l2)
public static boolean equals(float f1, float f2)
public static boolean equals(double d1, double d2)
public static boolean equals(boolean[] a1, boolean[] a2)
public static boolean equals(int[] a1, int[] a2)
public static boolean equals(long[] a1, long[] a2)
public static boolean equals(float[] a1, float[] a2)
public static boolean equals(double[] a1, double[] a2)
public static int hashCode(int currentHashCodeValue, boolean b)
public static int hashCode(int currentHashCodeValue, int i)
public static int hashCode(int currentHashCodeValue, long l)
public static int hashCode(int currentHashCodeValue, float f)
public static int hashCode(int currentHashCodeValue, double d)
public static int hashCode(int currentHashCodeValue, boolean[] a)
public static int hashCode(int currentHashCodeValue, int[] a)
public static int hashCode(int currentHashCodeValue, long[] a)
public static int hashCode(int currentHashCodeValue, float[] a)
public static int hashCode(int currentHashCodeValue, double[] a)
Copyright © 2014 BioJava. All rights reserved.