T
- type of hashed objectpublic class HashCoder<T> extends java.lang.Object implements HashCodeCalculator<T>, UniformMatcher<T>
HashCoderMap
.
This class provides substitute hash values and equals
implementation. To be null
-safe all three
arguments of HashCoder(HashCodeCalculator, Matcher, Function)
need to be null
-safe. The default implementations used
in the constructors with fewer arguments are null
-safe.
OBJECTS
IDENTICAL
Constructor and Description |
---|
HashCoder(java.util.function.Function<T,T> copier)
Constructor.
|
HashCoder(HashCodeCalculator<? super T> codeCalculator)
Constructor.
|
HashCoder(HashCodeCalculator<? super T> codeCalculator,
Matcher<? super T,? super T> matcher)
Constructor.
|
HashCoder(HashCodeCalculator<? super T> codeCalculator,
Matcher<? super T,? super T> matcher,
java.util.function.Function<T,T> copier)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
boolean |
areEqual(T object1,
T object2)
Are the given two objects considered equal?
|
T |
copy(T key)
Copy a key.
|
int |
getHashCode(T obj)
Get the hash code value of the given object.
|
static <V> HashCoder<V> |
natural()
Get a fast natural hash coder using just the object's methods
for hashing and equality, but not checking for
null values. |
static <V> HashCoder<V> |
naturalNullSafe()
Get a natural hash coder using just the object's methods
for hashing and equality, allowing for
null values. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
objects
identical
public HashCoder(@NotNull HashCodeCalculator<? super T> codeCalculator, @NotNull Matcher<? super T,? super T> matcher, @NotNull java.util.function.Function<T,T> copier)
codeCalculator
- calculator for hash codesmatcher
- equality checkercopier
- copier for incoming and outgoing keys,
useful to make keys immutable which
is a basic requirements for hash keyspublic HashCoder(@NotNull HashCodeCalculator<? super T> codeCalculator, @NotNull Matcher<? super T,? super T> matcher)
This used simple copying for the keys.
codeCalculator
- calculator for hash codesmatcher
- equality checkerpublic HashCoder(@NotNull HashCodeCalculator<? super T> codeCalculator)
Objects.equals(java.lang.Object, java.lang.Object)
and simple copying for the keys.codeCalculator
- hash code calculatorpublic HashCoder(@NotNull java.util.function.Function<T,T> copier)
Hashcode and equality checks are just using the standard implementation from the key objects.
copier
- copier for incoming and outgoing keyspublic int getHashCode(T obj)
HashCodeCalculator
getHashCode
in interface HashCodeCalculator<T>
obj
- object for which the hash code is requestedpublic boolean areEqual(T object1, T object2)
Matcher
public T copy(T key)
key
- key to copy@NotNull public static <V> HashCoder<V> natural()
null
values.natural
in interface HashCodeCalculator<T>
natural
in interface UniformMatcher<T>
V
- value type@NotNull public static <V> HashCoder<V> naturalNullSafe()
null
values.naturalNullSafe
in interface HashCodeCalculator<T>
naturalNullSafe
in interface UniformMatcher<T>
V
- value type