@NotThreadSafe public final class HashCodeGenerator extends Object implements IHashCodeGenerator
append(Object) for all objects use
getHashCode() to retrieve the calculated hash code. Once the hash
code was calculated no modifications are allowed.
A real world example for a final class derived from Object or a base
class looks like this:
@Override
public int hashCode ()
{
return new HashCodeGenerator (this).append (member1).append (member2).getHashCode ();
}
For a derived class, the typical code looks like this, assuming the base
class also uses HashCodeGenerator:
@Override
public int hashCode ()
{
return HashCodeGenerator.getDerived (super.hashCode ()).append (member3).append (member4).getHashCode ();
}
| Modifier and Type | Field and Description |
|---|---|
static int |
INITIAL_HASHCODE
Use a prime number as the start.
|
ILLEGAL_HASHCODE| Constructor and Description |
|---|
HashCodeGenerator(Class<?> aClass)
This constructor requires a class name, because in case a class has no
instance variables the hash code may be the same for different instances of
different classes.
|
HashCodeGenerator(Object aSrcObject)
This is a sanity constructor that allows for any object to be passed in the
constructor (e.g.
|
| Modifier and Type | Method and Description |
|---|---|
HashCodeGenerator |
append(boolean x)
Atomic type hash code generation.
|
HashCodeGenerator |
append(boolean[] x)
Array hash code generation.
|
HashCodeGenerator |
append(byte x)
Atomic type hash code generation.
|
HashCodeGenerator |
append(byte[] x)
Array hash code generation.
|
HashCodeGenerator |
append(char x)
Atomic type hash code generation.
|
HashCodeGenerator |
append(char[] x)
Array hash code generation.
|
HashCodeGenerator |
append(double x)
Atomic type hash code generation.
|
HashCodeGenerator |
append(double[] x)
Array hash code generation.
|
HashCodeGenerator |
append(Enum<?> x)
Object hash code generation.
|
HashCodeGenerator |
append(Enum<?>[] x)
Array hash code generation.
|
HashCodeGenerator |
append(float x)
Atomic type hash code generation.
|
HashCodeGenerator |
append(float[] x)
Array hash code generation.
|
HashCodeGenerator |
append(int x)
Atomic type hash code generation.
|
HashCodeGenerator |
append(int[] x)
Array hash code generation.
|
HashCodeGenerator |
append(Iterable<?> x) |
HashCodeGenerator |
append(long x)
Atomic type hash code generation.
|
HashCodeGenerator |
append(long[] x)
Array hash code generation.
|
HashCodeGenerator |
append(Map<?,?> x) |
HashCodeGenerator |
append(Node x) |
HashCodeGenerator |
append(Object x)
Object hash code generation.
|
HashCodeGenerator |
append(Object[] x)
Array hash code generation.
|
HashCodeGenerator |
append(short x)
Atomic type hash code generation.
|
HashCodeGenerator |
append(short[] x)
Array hash code generation.
|
HashCodeGenerator |
append(StringBuffer x)
Type specific hash code generation because parameter class has no
overloaded equals method.
|
HashCodeGenerator |
append(StringBuilder x)
Type specific hash code generation because parameter class has no
overloaded equals method.
|
boolean |
equals(Object o)
Deprecated.
Don't call this
|
static HashCodeGenerator |
getDerived(int nSuperHashCode)
Create a
HashCodeGenerator for derived classes where the base class
also uses the HashCodeGenerator. |
int |
getHashCode()
Retrieve the final hash code.
|
int |
hashCode()
Deprecated.
Don't call this
|
boolean |
isClosed() |
public static final int INITIAL_HASHCODE
public HashCodeGenerator(@Nonnull Object aSrcObject)
this) from which the class is extracted as
the initial value of the hash code.aSrcObject - The source object from which the class is extracted. May not be
null.public HashCodeGenerator(@Nonnull Class<?> aClass)
aClass - The class this instance is about to create a hash code for. May not
be null.public boolean isClosed()
@Nonnull public HashCodeGenerator append(boolean x)
append in interface IAppendable<IHashCodeGenerator>x - Array to add@Nonnull public HashCodeGenerator append(byte x)
append in interface IAppendable<IHashCodeGenerator>x - Array to add@Nonnull public HashCodeGenerator append(char x)
append in interface IAppendable<IHashCodeGenerator>x - Array to add@Nonnull public HashCodeGenerator append(double x)
append in interface IAppendable<IHashCodeGenerator>x - Array to add@Nonnull public HashCodeGenerator append(float x)
append in interface IAppendable<IHashCodeGenerator>x - Array to add@Nonnull public HashCodeGenerator append(int x)
append in interface IAppendable<IHashCodeGenerator>x - Array to add@Nonnull public HashCodeGenerator append(long x)
append in interface IAppendable<IHashCodeGenerator>x - Array to add@Nonnull public HashCodeGenerator append(short x)
append in interface IAppendable<IHashCodeGenerator>x - Array to add@Nonnull public HashCodeGenerator append(@Nullable Object x)
append in interface IAppendable<IHashCodeGenerator>x - Array to add@Nonnull public HashCodeGenerator append(@Nullable Enum<?> x)
append in interface IAppendable<IHashCodeGenerator>x - Array to add@Nonnull public HashCodeGenerator append(@Nullable boolean[] x)
append in interface IAppendable<IHashCodeGenerator>x - Array to add@Nonnull public HashCodeGenerator append(@Nullable byte[] x)
append in interface IAppendable<IHashCodeGenerator>x - Array to add@Nonnull public HashCodeGenerator append(@Nullable char[] x)
append in interface IAppendable<IHashCodeGenerator>x - Array to add@Nonnull public HashCodeGenerator append(@Nullable double[] x)
append in interface IAppendable<IHashCodeGenerator>x - Array to add@Nonnull public HashCodeGenerator append(@Nullable float[] x)
append in interface IAppendable<IHashCodeGenerator>x - Array to add@Nonnull public HashCodeGenerator append(@Nullable int[] x)
append in interface IAppendable<IHashCodeGenerator>x - Array to add@Nonnull public HashCodeGenerator append(@Nullable long[] x)
append in interface IAppendable<IHashCodeGenerator>x - Array to add@Nonnull public HashCodeGenerator append(@Nullable short[] x)
append in interface IAppendable<IHashCodeGenerator>x - Array to add@Nonnull public HashCodeGenerator append(@Nullable Object[] x)
append in interface IAppendable<IHashCodeGenerator>x - Array to add@Nonnull public HashCodeGenerator append(@Nullable Enum<?>[] x)
append in interface IAppendable<IHashCodeGenerator>x - Array to add@Nonnull public HashCodeGenerator append(@Nullable StringBuffer x)
x - object to add@Nonnull public HashCodeGenerator append(@Nullable StringBuilder x)
x - object to add@Nonnull public HashCodeGenerator append(@Nullable Iterable<?> x)
append in interface IAppendable<IHashCodeGenerator>x - to be included in the hash code generation.@Nonnull public HashCodeGenerator append(@Nullable Map<?,?> x)
append in interface IAppendable<IHashCodeGenerator>x - to be included in the hash code generation.@Nonnull public HashCodeGenerator append(@Nullable Node x)
append in interface IAppendable<IHashCodeGenerator>x - to be included in the hash code generation.public int getHashCode()
getHashCode in interface IHashCodeGeneratorIHashCodeGenerator.ILLEGAL_HASHCODE. If the calculated hash code would be
IHashCodeGenerator.ILLEGAL_HASHCODE it is changed to -1 instead.@Deprecated public boolean equals(Object o)
HashCodeGenerator objects :)@Deprecated public int hashCode()
getHashCode()hashCode in class ObjectgetHashCode()getHashCode()@Nonnull public static HashCodeGenerator getDerived(int nSuperHashCode)
HashCodeGenerator for derived classes where the base class
also uses the HashCodeGenerator. This avoid calculating the hash
code of the class name more than once.nSuperHashCode - Always pass in super.hashCode ()nullCopyright © 2014–2020 Philip Helger. All rights reserved.