Class EfficientHashCode

  • All Implemented Interfaces:
    org.apache.commons.lang3.builder.Builder<Integer>

    public class EfficientHashCode
    extends Object
    implements org.apache.commons.lang3.builder.Builder<Integer>
    A more efficient version of HashCodeBuilder.reflectionHashCode(Object, boolean). Extracts the fields of the classes to hash via the FieldsComparable class when possible.
    Since:
    1.3
    • Constructor Detail

      • EfficientHashCode

        public EfficientHashCode()
    • Method Detail

      • efficientHashcode

        public static int efficientHashcode​(FieldsComparable object)
      • append

        public EfficientHashCode append​(boolean value)

        Append a hashCode for a boolean.

        This adds 1 when true, and 0 when false to the hashCode.

        This is in contrast to the standard java.lang.Boolean.hashCode handling, which computes a hashCode value of 1231 for java.lang.Boolean instances that represent true or 1237 for java.lang.Boolean instances that represent false.

        This is in accordance with the Effective Java design.

        Parameters:
        value - the boolean to add to the hashCode
        Returns:
        this
      • append

        public EfficientHashCode append​(byte value)

        Append a hashCode for a byte.

        Parameters:
        value - the byte to add to the hashCode
        Returns:
        this
      • append

        public EfficientHashCode append​(char value)

        Append a hashCode for a char.

        Parameters:
        value - the char to add to the hashCode
        Returns:
        this
      • append

        public EfficientHashCode append​(double value)

        Append a hashCode for a double.

        Parameters:
        value - the double to add to the hashCode
        Returns:
        this
      • append

        public EfficientHashCode append​(float value)

        Append a hashCode for a float.

        Parameters:
        value - the float to add to the hashCode
        Returns:
        this
      • append

        public EfficientHashCode append​(int value)

        Append a hashCode for an int.

        Parameters:
        value - the int to add to the hashCode
        Returns:
        this
      • append

        public EfficientHashCode append​(long value)

        Append a hashCode for a long.

        Parameters:
        value - the long to add to the hashCode
        Returns:
        this
      • append

        public EfficientHashCode append​(Object object)

        Append a hashCode for an Object.

        Parameters:
        object - the Object to add to the hashCode
        Returns:
        this
      • append

        public EfficientHashCode append​(short value)

        Append a hashCode for a short.

        Parameters:
        value - the short to add to the hashCode
        Returns:
        this
      • build

        public Integer build()

        Returns the computed hashCode.

        Specified by:
        build in interface org.apache.commons.lang3.builder.Builder<Integer>
        Returns:
        hashCode based on the fields appended