Class HashCodeCalculator

java.lang.Object
com.helger.commons.hashcode.HashCodeCalculator

@Immutable public final class HashCodeCalculator extends Object
This class provides the hash code generation for different data types.
Author:
Philip Helger
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    The hash code value to be used for null values.
    static final int
    Each value is multiplied with this value. 31 because it can easily be optimized to (1 << 5) - 1.
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    append(int nPrevHashCode, boolean x)
    Atomic type hash code generation.
    static int
    append(int nPrevHashCode, byte x)
    Atomic type hash code generation.
    static int
    append(int nPrevHashCode, char x)
    Atomic type hash code generation.
    static int
    append(int nPrevHashCode, double x)
    Atomic type hash code generation.
    static int
    append(int nPrevHashCode, float x)
    Atomic type hash code generation.
    static int
    append(int nPrevHashCode, int x)
    Atomic type hash code generation.
    static int
    append(int nPrevHashCode, long x)
    Atomic type hash code generation.
    static int
    append(int nPrevHashCode, short x)
    Atomic type hash code generation.
    static int
    append(int nPrevHashCode, Object x)
    Object hash code generation.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • MULTIPLIER

      public static final int MULTIPLIER
      Each 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_NULL
      The hash code value to be used for null values. 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 calculation
      x - 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 calculation
      x - 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 calculation
      x - 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 calculation
      x - 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 calculation
      x - 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 calculation
      x - 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 calculation
      x - 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 calculation
      x - Array to add
      Returns:
      The updated hash code
    • append

      public static int append(int nPrevHashCode, @Nullable Object x)
      Object hash code generation.
      Parameters:
      nPrevHashCode - The previous hash code used as the basis for calculation
      x - Object to add. May be null.
      Returns:
      The updated hash code