Class 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 int HASHCODE_NULL
      The hash code value to be used for null values.
      static int MULTIPLIER
      Each value is multiplied with this value. 31 because it can easily be optimized to (1 << 5) - 1.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      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.
    • Field Detail

      • 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:
        Constant Field Values
      • 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:
        Constant Field Values
    • Method Detail

      • 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