Package com.helger.commons.hashcode
Class HashCodeCalculator
java.lang.Object
com.helger.commons.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 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, byte x) Atomic type hash code generation.static intappend(int nPrevHashCode, char x) Atomic type hash code generation.static intappend(int nPrevHashCode, double x) Atomic type hash code generation.static intappend(int nPrevHashCode, float x) Atomic type hash code generation.static intappend(int nPrevHashCode, int x) Atomic type hash code generation.static intappend(int nPrevHashCode, long x) Atomic type hash code generation.static intappend(int nPrevHashCode, short x) Atomic type hash code generation.static intObject hash code generation.
-
Field Details
-
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
-
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
-