java.util.List.hashCode
. If you need order independent hash code just summate, multiply or XOR all elements. Suppose we have class:
class Thing { long id; String name; float weight; }
The hash code calulation can be expressed in 2 forms. For maximum performance:
public int hashCode() { int hashCode = HashCode.EMPTY_HASH_CODE; hashCode = HashCode.combine(hashCode, id); hashCode = HashCode.combine(hashCode, name); hashCode = HashCode.combine(hashCode, weight); return hashCode; }
For convenience:
@see java.util.List#hashCode()
public int hashCode() { return new HashCode().append(id).append(name).append(weight).hashCode(); }
|
|