@NotThreadSafe public final class JCHashCodeGenerator extends Object
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 JCHashCodeGenerator:
@Override
public int hashCode ()
{
return HashCodeGenerator.getDerived (super.hashCode ()).append (member3).append (member4).getHashCode ();
}
| Modifier and Type | Field and Description |
|---|---|
static int |
ILLEGAL_HASHCODE
Represents an illegal hash code that is never to be returned!
|
static int |
INITIAL_HASHCODE
Use a prime number as the start.
|
| Constructor and Description |
|---|
JCHashCodeGenerator(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.
|
JCHashCodeGenerator(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 |
|---|---|
JCHashCodeGenerator |
append(boolean x)
Atomic type hash code generation.
|
JCHashCodeGenerator |
append(boolean[] x)
Array hash code generation.
|
JCHashCodeGenerator |
append(byte x)
Atomic type hash code generation.
|
JCHashCodeGenerator |
append(byte[] x)
Array hash code generation.
|
JCHashCodeGenerator |
append(char x)
Atomic type hash code generation.
|
JCHashCodeGenerator |
append(char[] x)
Array hash code generation.
|
JCHashCodeGenerator |
append(double x)
Atomic type hash code generation.
|
JCHashCodeGenerator |
append(double[] x)
Array hash code generation.
|
JCHashCodeGenerator |
append(Enum<?> x)
Object hash code generation.
|
JCHashCodeGenerator |
append(Enum<?>[] x)
Array hash code generation.
|
JCHashCodeGenerator |
append(float x)
Atomic type hash code generation.
|
JCHashCodeGenerator |
append(float[] x)
Array hash code generation.
|
JCHashCodeGenerator |
append(int x)
Atomic type hash code generation.
|
JCHashCodeGenerator |
append(int[] x)
Array hash code generation.
|
JCHashCodeGenerator |
append(Iterable<?> x) |
JCHashCodeGenerator |
append(long x)
Atomic type hash code generation.
|
JCHashCodeGenerator |
append(long[] x)
Array hash code generation.
|
JCHashCodeGenerator |
append(Map<?,?> x) |
JCHashCodeGenerator |
append(Node x) |
JCHashCodeGenerator |
append(Object x)
Object hash code generation.
|
JCHashCodeGenerator |
append(Object[] x)
Array hash code generation.
|
JCHashCodeGenerator |
append(short x)
Atomic type hash code generation.
|
JCHashCodeGenerator |
append(short[] x)
Array hash code generation.
|
JCHashCodeGenerator |
append(StringBuffer x)
Type specific hash code generation because parameter class has no
overloaded equals method.
|
JCHashCodeGenerator |
append(StringBuilder x)
Type specific hash code generation because parameter class has no
overloaded equals method.
|
boolean |
equals(Object o)
Deprecated.
|
static JCHashCodeGenerator |
getDerived(int nSuperHashCode)
Create a
JCHashCodeGenerator for derived classes where the base class
also uses the JCHashCodeGenerator. |
int |
getHashCode()
Retrieve the final hash code.
|
static int |
getHashCode(int nSuperHashCode,
Object... aMembers)
Static helper method to create the hashcode of an object with a single
invocation.
|
static int |
getHashCode(Object aThis,
Object... aMembers)
Static helper method to create the hashcode of an object with a single
invocation.
|
Integer |
getHashCodeObj() |
int |
hashCode()
Deprecated.
|
public static final int ILLEGAL_HASHCODE
public static final int INITIAL_HASHCODE
public JCHashCodeGenerator(@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 JCHashCodeGenerator(@Nonnull Class<?> aClass)
aClass - The class this instance is about to create a hash code for. May not
be null.@Nonnull public JCHashCodeGenerator append(boolean x)
x - Array to add@Nonnull public JCHashCodeGenerator append(byte x)
x - Array to add@Nonnull public JCHashCodeGenerator append(char x)
x - Array to add@Nonnull public JCHashCodeGenerator append(double x)
x - Array to add@Nonnull public JCHashCodeGenerator append(float x)
x - Array to add@Nonnull public JCHashCodeGenerator append(int x)
x - Array to add@Nonnull public JCHashCodeGenerator append(long x)
x - Array to add@Nonnull public JCHashCodeGenerator append(short x)
x - Array to add@Nonnull public JCHashCodeGenerator append(@Nullable Object x)
x - Array to add@Nonnull public JCHashCodeGenerator append(@Nullable Enum<?> x)
x - Array to add@Nonnull public JCHashCodeGenerator append(@Nullable boolean[] x)
x - Array to add@Nonnull public JCHashCodeGenerator append(@Nullable byte[] x)
x - Array to add@Nonnull public JCHashCodeGenerator append(@Nullable char[] x)
x - Array to add@Nonnull public JCHashCodeGenerator append(@Nullable double[] x)
x - Array to add@Nonnull public JCHashCodeGenerator append(@Nullable float[] x)
x - Array to add@Nonnull public JCHashCodeGenerator append(@Nullable int[] x)
x - Array to add@Nonnull public JCHashCodeGenerator append(@Nullable long[] x)
x - Array to add@Nonnull public JCHashCodeGenerator append(@Nullable short[] x)
x - Array to add@Nonnull public JCHashCodeGenerator append(@Nullable Object[] x)
x - Array to add@Nonnull public JCHashCodeGenerator append(@Nullable Enum<?>[] x)
x - Array to add@Nonnull public JCHashCodeGenerator append(@Nullable StringBuffer x)
x - object to add@Nonnull public JCHashCodeGenerator append(@Nullable StringBuilder x)
x - object to add@Nonnull public JCHashCodeGenerator append(@Nullable Iterable<?> x)
x - to be included in the hash code generation.@Nonnull public JCHashCodeGenerator append(@Nullable Map<?,?> x)
x - to be included in the hash code generation.@Nonnull public JCHashCodeGenerator append(@Nullable Node x)
x - to be included in the hash code generation.public int getHashCode()
ILLEGAL_HASHCODE. If the calculated hash code would be
ILLEGAL_HASHCODE it is changed to -1 instead.@Nonnull public Integer getHashCodeObj()
getHashCode() but as an Integer
object. Never null.@Deprecated public boolean equals(Object o)
JCHashCodeGenerator objects :)@Deprecated public int hashCode()
getHashCode()hashCode in class ObjectgetHashCode()getHashCode()@Nonnull public static JCHashCodeGenerator getDerived(int nSuperHashCode)
JCHashCodeGenerator for derived classes where the base class
also uses the JCHashCodeGenerator. This avoid calculating the hash
code of the class name more than once.nSuperHashCode - Always pass in super.hashCode ()nullpublic static int getHashCode(@Nonnull Object aThis, @Nullable Object... aMembers)
aThis - thisaMembers - A list of all members. Primitive types must be boxed.public static int getHashCode(@Nonnull int nSuperHashCode, @Nullable Object... aMembers)
nSuperHashCode - The result of super.hashCode()aMembers - A list of all members. Primitive types must be boxed.Copyright © 2013–2015 Philip Helger. All rights reserved.