Package org.cactoos.scalar
Class HashCode
- java.lang.Object
-
- org.cactoos.scalar.HashCode
-
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
andmultiplier
values are arbitrarily set to 17 and 31 respectively.- Parameters:
attributes
- The object's attributes
-
HashCode
public HashCode(Iterable<?> attributes)
Ctor.The
initial
andmultiplier
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
-
-