protected class IColorCenter.Skeleton.GranularHasher extends java.lang.Object implements CrossHash.IHasher
Modifier | Constructor and Description |
---|---|
protected |
GranularHasher() |
Modifier and Type | Method and Description |
---|---|
boolean |
areEqual(java.lang.Object left,
java.lang.Object right)
Not all types you might want to use an IHasher on meaningfully implement .equals(), such as array types; in
these situations the areEqual method helps quickly check for equality by potentially having special logic for
the type this is meant to check.
|
int |
hash(java.lang.Object data)
If data is a type that this IHasher can specifically hash, this method should use that specific hash; in
other situations, it should simply delegate to calling
Object.hashCode() on data. |
public int hash(java.lang.Object data)
CrossHash.IHasher
Object.hashCode()
on data. The body of an
implementation of this method can be very small; for an IHasher that is meant for byte arrays, the body could
be: return (data instanceof byte[]) ? CrossHash.Lightning.hash((byte[]) data) : data.hashCode();
hash
in interface CrossHash.IHasher
data
- the Object to hash; this method should take any type but often has special behavior for one typepublic boolean areEqual(java.lang.Object left, java.lang.Object right)
CrossHash.IHasher
return left == right
|| ((left instanceof byte[] && right instanceof byte[])
? Arrays.equals((byte[]) left, (byte[]) right)
: Objects.equals(left, right));
, but for multidimensional arrays you should use the
CrossHash.equalityHelper(Object[], Object[], IHasher)
method with an IHasher for the inner arrays that are 1D
or otherwise already-hash-able, as can be seen in the body of the implementation for 2D char arrays, where
charHasher is an existing IHasher that handles 1D arrays:
return left == right
|| ((left instanceof char[][] && right instanceof char[][])
? equalityHelper((char[][]) left, (char[][]) right, charHasher)
: Objects.equals(left, right));
areEqual
in interface CrossHash.IHasher
left
- allowed to be null; most implementations will have special behavior for one typeright
- allowed to be null; most implementations will have special behavior for one typeCopyright © Eben Howard 2012–2022. All rights reserved.