Package squidpony
Class IColorCenter.Skeleton.GranularHasher
java.lang.Object
squidpony.IColorCenter.Skeleton.GranularHasher
- All Implemented Interfaces:
Serializable
,CrossHash.IHasher
- Enclosing class:
- IColorCenter.Skeleton<T>
protected class IColorCenter.Skeleton.GranularHasher extends Object implements CrossHash.IHasher
- See Also:
- Serialized Form
-
Constructor Summary
Constructors Modifier Constructor Description protected
GranularHasher()
-
Method Summary
Modifier and Type Method Description boolean
areEqual(Object left, 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(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 callingObject.hashCode()
on data.
-
Constructor Details
-
GranularHasher
protected GranularHasher()
-
-
Method Details
-
hash
Description copied from interface:CrossHash.IHasher
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 callingObject.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();
- Specified by:
hash
in interfaceCrossHash.IHasher
- Parameters:
data
- the Object to hash; this method should take any type but often has special behavior for one type- Returns:
- a 32-bit int hash code of data
-
areEqual
Description copied from interface:CrossHash.IHasher
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. The body of implementations for this method can be fairly small; for byte arrays, it looks like: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 theCrossHash.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));
- Specified by:
areEqual
in interfaceCrossHash.IHasher
- Parameters:
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 type- Returns:
- true if left is equal to right (preferably by value, but reference equality may sometimes be needed)
-