Package com.helger.base.hashcode
Class HashCodeCalculator
java.lang.Object
com.helger.base.hashcode.HashCodeCalculator
This class provides the hash code generation for different data types.
- Author:
- Philip Helger
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe hash code value to be used fornullvalues.static final intUse a prime number as the start.static final intEach value is multiplied with this value. 31 because it can easily be optimized to(1 << 5) - 1. -
Method Summary
Modifier and TypeMethodDescriptionstatic intappend(int nPrevHashCode, boolean x) Atomic type hash code generation.static intappend(int nPrevHashCode, boolean @Nullable [] x) Atomic type hash code generation.static intappend(int nPrevHashCode, boolean @Nullable [] x, int nOfs, int nLen) Atomic type hash code generation.static intappend(int nPrevHashCode, byte x) Atomic type hash code generation.static intappend(int nPrevHashCode, byte @Nullable [] x) Atomic type hash code generation.static intappend(int nPrevHashCode, byte @Nullable [] x, int nOfs, int nLen) Atomic type hash code generation.static intappend(int nPrevHashCode, char x) Atomic type hash code generation.static intappend(int nPrevHashCode, char @Nullable [] x) Atomic type hash code generation.static intappend(int nPrevHashCode, char @Nullable [] x, int nOfs, int nLen) Atomic type hash code generation.static intappend(int nPrevHashCode, double x) Atomic type hash code generation.static intappend(int nPrevHashCode, double @Nullable [] x) Atomic type hash code generation.static intappend(int nPrevHashCode, double @Nullable [] x, int nOfs, int nLen) Atomic type hash code generation.static intappend(int nPrevHashCode, float x) Atomic type hash code generation.static intappend(int nPrevHashCode, float @Nullable [] x) Atomic type hash code generation.static intappend(int nPrevHashCode, float @Nullable [] x, int nOfs, int nLen) Atomic type hash code generation.static intappend(int nPrevHashCode, int x) Atomic type hash code generation.static intappend(int nPrevHashCode, int @Nullable [] x) Atomic type hash code generation.static intappend(int nPrevHashCode, int @Nullable [] x, int nOfs, int nLen) Atomic type hash code generation.static intappend(int nPrevHashCode, long x) Atomic type hash code generation.static intappend(int nPrevHashCode, long @Nullable [] x) Atomic type hash code generation.static intappend(int nPrevHashCode, long @Nullable [] x, int nOfs, int nLen) Atomic type hash code generation.static intappend(int nPrevHashCode, short x) Atomic type hash code generation.static intappend(int nPrevHashCode, short @Nullable [] x) Atomic type hash code generation.static intappend(int nPrevHashCode, short @Nullable [] x, int nOfs, int nLen) Atomic type hash code generation.static intObject hash code generation.static intArray hash code generation.static intAtomic type hash code generation.static inthashCode(boolean x) static inthashCode(boolean @NonNull [] x, int nOfs, int nLen) Compute a hash code for a sub-array of booleans.static inthashCode(byte x) static inthashCode(byte @NonNull [] x, int nOfs, int nLen) Compute a hash code for a sub-array of bytes.static inthashCode(char x) static inthashCode(char @NonNull [] x, int nOfs, int nLen) Compute a hash code for a sub-array of chars.static longhashCode(double x) static inthashCode(double @NonNull [] x, int nOfs, int nLen) Compute a hash code for a sub-array of doubles.static inthashCode(float x) static inthashCode(float @NonNull [] x, int nOfs, int nLen) Compute a hash code for a sub-array of floats.static inthashCode(int @NonNull [] x, int nOfs, int nLen) Compute a hash code for a sub-array of ints.static inthashCode(long @NonNull [] x, int nOfs, int nLen) Compute a hash code for a sub-array of longs.static inthashCode(short x) static inthashCode(short @NonNull [] x, int nOfs, int nLen) Compute a hash code for a sub-array of shorts.static intCompute a hash code for a sub-array of objects.static int
-
Field Details
-
INITIAL_HASHCODE
public static final int INITIAL_HASHCODEUse a prime number as the start.- See Also:
-
MULTIPLIER
public static final int MULTIPLIEREach value is multiplied with this value. 31 because it can easily be optimized to(1 << 5) - 1.- See Also:
-
HASHCODE_NULL
public static final int HASHCODE_NULLThe hash code value to be used fornullvalues. Do not use 0 as e.g.BigDecimal ("0")also results in a 0 hash code.- See Also:
-
-
Method Details
-
hashCode
public static int hashCode(boolean x) - Parameters:
x- The value to hash.- Returns:
- The hash code for the boolean value.
-
hashCode
public static int hashCode(byte x) - Parameters:
x- The value to hash.- Returns:
- The hash code for the byte value.
-
hashCode
public static int hashCode(char x) - Parameters:
x- The value to hash.- Returns:
- The hash code for the char value.
-
hashCode
public static long hashCode(double x) - Parameters:
x- The value to hash.- Returns:
- The hash code for the double value.
-
hashCode
public static int hashCode(float x) - Parameters:
x- The value to hash.- Returns:
- The hash code for the float value.
-
hashCode
public static int hashCode(short x) - Parameters:
x- The value to hash.- Returns:
- The hash code for the short value.
-
hashCode
- Parameters:
x- The object to hash. May benull.- Returns:
- The hash code for the object, or
HASHCODE_NULLifnull.
-
append
public static int append(int nPrevHashCode, boolean x) Atomic type hash code generation.- Parameters:
nPrevHashCode- The previous hash code used as the basis for calculationx- Array to add- Returns:
- The updated hash code
-
append
public static int append(int nPrevHashCode, byte x) Atomic type hash code generation.- Parameters:
nPrevHashCode- The previous hash code used as the basis for calculationx- Array to add- Returns:
- The updated hash code
-
append
public static int append(int nPrevHashCode, char x) Atomic type hash code generation.- Parameters:
nPrevHashCode- The previous hash code used as the basis for calculationx- Array to add- Returns:
- The updated hash code
-
append
public static int append(int nPrevHashCode, double x) Atomic type hash code generation.- Parameters:
nPrevHashCode- The previous hash code used as the basis for calculationx- Array to add- Returns:
- The updated hash code
-
append
public static int append(int nPrevHashCode, float x) Atomic type hash code generation.- Parameters:
nPrevHashCode- The previous hash code used as the basis for calculationx- Array to add- Returns:
- The updated hash code
-
append
public static int append(int nPrevHashCode, int x) Atomic type hash code generation.- Parameters:
nPrevHashCode- The previous hash code used as the basis for calculationx- Array to add- Returns:
- The updated hash code
-
append
public static int append(int nPrevHashCode, long x) Atomic type hash code generation.- Parameters:
nPrevHashCode- The previous hash code used as the basis for calculationx- Array to add- Returns:
- The updated hash code
-
append
public static int append(int nPrevHashCode, short x) Atomic type hash code generation.- Parameters:
nPrevHashCode- The previous hash code used as the basis for calculationx- Array to add- Returns:
- The updated hash code
-
append
Object hash code generation.- Parameters:
nPrevHashCode- The previous hash code used as the basis for calculationx- Object to add. May benull.- Returns:
- The updated hash code
-
hashCode
public static int hashCode(boolean @NonNull [] x, @Nonnegative int nOfs, @Nonnegative int nLen) Compute a hash code for a sub-array of booleans.- Parameters:
x- The array. May not benull.nOfs- The offset. Must be ≥ 0.nLen- The length. Must be ≥ 0.- Returns:
- The computed hash code.
-
hashCode
public static int hashCode(byte @NonNull [] x, @Nonnegative int nOfs, @Nonnegative int nLen) Compute a hash code for a sub-array of bytes.- Parameters:
x- The array. May not benull.nOfs- The offset. Must be ≥ 0.nLen- The length. Must be ≥ 0.- Returns:
- The computed hash code.
-
hashCode
public static int hashCode(char @NonNull [] x, @Nonnegative int nOfs, @Nonnegative int nLen) Compute a hash code for a sub-array of chars.- Parameters:
x- The array. May not benull.nOfs- The offset. Must be ≥ 0.nLen- The length. Must be ≥ 0.- Returns:
- The computed hash code.
-
hashCode
public static int hashCode(double @NonNull [] x, @Nonnegative int nOfs, @Nonnegative int nLen) Compute a hash code for a sub-array of doubles.- Parameters:
x- The array. May not benull.nOfs- The offset. Must be ≥ 0.nLen- The length. Must be ≥ 0.- Returns:
- The computed hash code.
-
hashCode
public static int hashCode(float @NonNull [] x, @Nonnegative int nOfs, @Nonnegative int nLen) Compute a hash code for a sub-array of floats.- Parameters:
x- The array. May not benull.nOfs- The offset. Must be ≥ 0.nLen- The length. Must be ≥ 0.- Returns:
- The computed hash code.
-
hashCode
public static int hashCode(int @NonNull [] x, @Nonnegative int nOfs, @Nonnegative int nLen) Compute a hash code for a sub-array of ints.- Parameters:
x- The array. May not benull.nOfs- The offset. Must be ≥ 0.nLen- The length. Must be ≥ 0.- Returns:
- The computed hash code.
-
hashCode
public static int hashCode(long @NonNull [] x, @Nonnegative int nOfs, @Nonnegative int nLen) Compute a hash code for a sub-array of longs.- Parameters:
x- The array. May not benull.nOfs- The offset. Must be ≥ 0.nLen- The length. Must be ≥ 0.- Returns:
- The computed hash code.
-
hashCode
public static int hashCode(short @NonNull [] x, @Nonnegative int nOfs, @Nonnegative int nLen) Compute a hash code for a sub-array of shorts.- Parameters:
x- The array. May not benull.nOfs- The offset. Must be ≥ 0.nLen- The length. Must be ≥ 0.- Returns:
- The computed hash code.
-
hashCode
Compute a hash code for a sub-array of objects.- Parameters:
x- The array. May not benull.nOfs- The offset. Must be ≥ 0.nLen- The length. Must be ≥ 0.- Returns:
- The computed hash code.
-
append
public static int append(int nPrevHashCode, boolean @Nullable [] x) Atomic type hash code generation.- Parameters:
nPrevHashCode- The previous hash code used as the basis for calculationx- Array to add- Returns:
- The updated hash code
-
append
public static int append(int nPrevHashCode, boolean @Nullable [] x, @Nonnegative int nOfs, @Nonnegative int nLen) Atomic type hash code generation.- Parameters:
nPrevHashCode- The previous hash code used as the basis for calculationx- Array to addnOfs- Offset to start from. Must be ≥ 0.nLen- Number of array items to use. Must be ≥ 0.- Returns:
- The updated hash code
-
append
public static int append(int nPrevHashCode, byte @Nullable [] x) Atomic type hash code generation.- Parameters:
nPrevHashCode- The previous hash code used as the basis for calculationx- Array to add- Returns:
- The updated hash code
-
append
public static int append(int nPrevHashCode, byte @Nullable [] x, @Nonnegative int nOfs, @Nonnegative int nLen) Atomic type hash code generation.- Parameters:
nPrevHashCode- The previous hash code used as the basis for calculationx- Array to addnOfs- Offset to start from. Must be ≥ 0.nLen- Number of array items to use. Must be ≥ 0.- Returns:
- The updated hash code
-
append
public static int append(int nPrevHashCode, char @Nullable [] x) Atomic type hash code generation.- Parameters:
nPrevHashCode- The previous hash code used as the basis for calculationx- Array to add- Returns:
- The updated hash code
-
append
public static int append(int nPrevHashCode, char @Nullable [] x, @Nonnegative int nOfs, @Nonnegative int nLen) Atomic type hash code generation.- Parameters:
nPrevHashCode- The previous hash code used as the basis for calculationx- Array to addnOfs- Offset to start from. Must be ≥ 0.nLen- Number of array items to use. Must be ≥ 0.- Returns:
- The updated hash code
-
append
public static int append(int nPrevHashCode, double @Nullable [] x) Atomic type hash code generation.- Parameters:
nPrevHashCode- The previous hash code used as the basis for calculationx- Array to add- Returns:
- The updated hash code
-
append
public static int append(int nPrevHashCode, double @Nullable [] x, @Nonnegative int nOfs, @Nonnegative int nLen) Atomic type hash code generation.- Parameters:
nPrevHashCode- The previous hash code used as the basis for calculationx- Array to addnOfs- Offset to start from. Must be ≥ 0.nLen- Number of array items to use. Must be ≥ 0.- Returns:
- The updated hash code
-
append
public static int append(int nPrevHashCode, float @Nullable [] x) Atomic type hash code generation.- Parameters:
nPrevHashCode- The previous hash code used as the basis for calculationx- Array to add- Returns:
- The updated hash code
-
append
public static int append(int nPrevHashCode, float @Nullable [] x, @Nonnegative int nOfs, @Nonnegative int nLen) Atomic type hash code generation.- Parameters:
nPrevHashCode- The previous hash code used as the basis for calculationx- Array to addnOfs- Offset to start from. Must be ≥ 0.nLen- Number of array items to use. Must be ≥ 0.- Returns:
- The updated hash code
-
append
public static int append(int nPrevHashCode, int @Nullable [] x) Atomic type hash code generation.- Parameters:
nPrevHashCode- The previous hash code used as the basis for calculationx- Array to add- Returns:
- The updated hash code
-
append
public static int append(int nPrevHashCode, int @Nullable [] x, @Nonnegative int nOfs, @Nonnegative int nLen) Atomic type hash code generation.- Parameters:
nPrevHashCode- The previous hash code used as the basis for calculationx- Array to addnOfs- Offset to start from. Must be ≥ 0.nLen- Number of array items to use. Must be ≥ 0.- Returns:
- The updated hash code
-
append
public static int append(int nPrevHashCode, long @Nullable [] x) Atomic type hash code generation.- Parameters:
nPrevHashCode- The previous hash code used as the basis for calculationx- Array to add- Returns:
- The updated hash code
-
append
public static int append(int nPrevHashCode, long @Nullable [] x, @Nonnegative int nOfs, @Nonnegative int nLen) Atomic type hash code generation.- Parameters:
nPrevHashCode- The previous hash code used as the basis for calculationx- Array to addnOfs- Offset to start from. Must be ≥ 0.nLen- Number of array items to use. Must be ≥ 0.- Returns:
- The updated hash code
-
append
public static int append(int nPrevHashCode, short @Nullable [] x) Atomic type hash code generation.- Parameters:
nPrevHashCode- The previous hash code used as the basis for calculationx- Array to add- Returns:
- The updated hash code
-
append
public static int append(int nPrevHashCode, short @Nullable [] x, @Nonnegative int nOfs, @Nonnegative int nLen) Atomic type hash code generation.- Parameters:
nPrevHashCode- The previous hash code used as the basis for calculationx- Array to addnOfs- Offset to start from. Must be ≥ 0.nLen- Number of array items to use. Must be ≥ 0.- Returns:
- The updated hash code
-
append
Array hash code generation.- Parameters:
nPrevHashCode- The previous hash code used as the basis for calculationx- Object array to add. May benull.- Returns:
- The updated hash code
-
append
public static int append(int nPrevHashCode, @Nullable Object[] x, @Nonnegative int nOfs, @Nonnegative int nLen) Atomic type hash code generation.- Parameters:
nPrevHashCode- The previous hash code used as the basis for calculationx- Array to addnOfs- Offset to start from. Must be ≥ 0.nLen- Number of array items to use. Must be ≥ 0.- Returns:
- The updated hash code
-