Class HashCode

  • All Implemented Interfaces:
    Scalar<Integer>

    public final class HashCode
    extends Object
    implements Scalar<Integer>
    Object HashCode. Replace this code: public int hashCode() { int hash = 5; hash = 67 * hash + Objects.hashCode(this.attr1); hash = 67 * hash + Objects.hashCode(this.attr2); hash = 67 * hash + Objects.hashCode(this.attr3); // ... more attributes return hash; } With this: public int hashCode() { return new HashCode( 5, 67, this.attr1, this.attr2, this.attr3, ... ).value(); }

    There is no thread-safety guarantee.

    Since:
    1.0
    • Constructor Detail

      • HashCode

        public HashCode​(Object... attributes)
        Ctor.

        The initial and multiplier values are arbitrarily set to 17 and 31 respectively.

        Parameters:
        attributes - The object's attributes
      • HashCode

        public HashCode​(Iterable<?> attributes)
        Ctor.

        The initial and multiplier values are arbitrarily set to 17 and 31 respectively.

        Parameters:
        attributes - The object's attributes
      • HashCode

        public HashCode​(int initial,
                        int multiplier,
                        Object... attributes)
        Ctor.
        Parameters:
        initial - Initial value (non-zero recommended)
        multiplier - Step multiplier (odd prime recommended)
        attributes - The object's attributes
      • HashCode

        public HashCode​(int initial,
                        int multiplier,
                        Iterable<?> attributes)
        Ctor.
        Parameters:
        initial - Initial value (non-zero recommended)
        multiplier - Step multiplier (odd prime recommended)
        attributes - The object's attributes
    • Method Detail

      • value

        public Integer value()
        Description copied from interface: Scalar
        Convert it to the value.
        Specified by:
        value in interface Scalar<Integer>
        Returns:
        The value