Class HashCalc
Object.hashCode().
This class knows how to deal with primitive types and objects, but also
arrays (of primitive types and objects), even nested ones. It also deals with
order, i.e. feeding it the same values in a different order will also produce
a different hash code. null values don't have to be treated specially
either.
The initial hash code is based on the class name provided in the constructor.
Arbitrary values (usually those that are also queried in
Object.equals(Object)) can then be fed to the HashCalc using
the various feed(..) methods. The resulting hash code can be
retrieved with hashCode().
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanfeed(boolean value) Feeds abooleanto the computed hash code.feed(boolean[] array) Feeds abooleanarray to the computed hash code.feed(byte value) Feeds abyteto the computed hash code.feed(byte[] array) Feeds abytearray to the computed hash code.feed(char value) Feeds acharto the computed hash code.feed(double value) Feeds adoubleto the computed hash code.feed(double[] array) Feeds adoublearray to the computed hash code.feed(float value) Feeds afloatto the computed hash code.feed(float[] array) Feeds afloatarray to the computed hash code.feed(int value) Feeds aintto the computed hash code.feed(int[] array) Feeds aintarray to the computed hash code.feed(long value) Feeds along valueto the computed hash code.feed(long[] array) Feeds alongarray to the computed hash code.feed(short value) Feeds ashortto the computed hash code.feed(short[] array) Feeds ashortarray to the computed hash code.Feeds anObjectto the computed hash code.Feeds anObjectarray to the computed hash code.feedShallow(Object[] array) Feeds anObjectarray to the computed hash code.inthashCode()Returns the computed hash code.
-
Constructor Details
-
HashCalc
Constructs a newHashCalcfor an object of the specified class.- Parameters:
forClass- the type of object for which to calculate a hash code
-
-
Method Details
-
feed
Feeds abooleanto the computed hash code.- Parameters:
value- value to be included in the hash code- Returns:
- this
HashCalc
-
feed
Feeds acharto the computed hash code.- Parameters:
value- value to be included in the hash code- Returns:
- this
HashCalc
-
feed
Feeds abyteto the computed hash code.- Parameters:
value- value to be included in the hash code- Returns:
- this
HashCalc
-
feed
Feeds ashortto the computed hash code.- Parameters:
value- value to be included in the hash code- Returns:
- this
HashCalc
-
feed
Feeds aintto the computed hash code.All other
feed()methods are redirected to this method. So in order to provide custom hash code computations only this method needs to be overridden.- Parameters:
value- value to be included in the hash code- Returns:
- this
HashCalc
-
feed
Feeds along valueto the computed hash code.- Parameters:
value- value to be included in the hash code- Returns:
- this
HashCalc
-
feed
Feeds afloatto the computed hash code.- Parameters:
value- value to be included in the hash code- Returns:
- this
HashCalc
-
feed
Feeds adoubleto the computed hash code.- Parameters:
value- value to be included in the hash code- Returns:
- this
HashCalc
-
feed
Feeds anObjectto the computed hash code. This is done by getting the object's own hash code.- Parameters:
object- object to be included in the hash code- Returns:
- this
HashCalc
-
feed
Feeds abooleanarray to the computed hash code. The arrays hash code is acquired usingArrays.hashCode(boolean[]).- Parameters:
array- array to be included in the hash code- Returns:
- this
HashCalc
-
feed
Feeds abytearray to the computed hash code. The arrays hash code is acquired usingArrays.hashCode(byte[]).- Parameters:
array- array to be included in the hash code- Returns:
- this
HashCalc
-
feed
Feeds ashortarray to the computed hash code. The arrays hash code is acquired usingArrays.hashCode(short[]).- Parameters:
array- array to be included in the hash code- Returns:
- this
HashCalc
-
feed
Feeds aintarray to the computed hash code. The arrays hash code is acquired usingArrays.hashCode(int[]).- Parameters:
array- array to be included in the hash code- Returns:
- this
HashCalc
-
feed
Feeds alongarray to the computed hash code. The arrays hash code is acquired usingArrays.hashCode(long[]).- Parameters:
array- array to be included in the hash code- Returns:
- this
HashCalc
-
feed
Feeds afloatarray to the computed hash code. The arrays hash code is acquired usingArrays.hashCode(float[]).- Parameters:
array- array to be included in the hash code- Returns:
- this
HashCalc
-
feed
Feeds adoublearray to the computed hash code. The arrays hash code is acquired usingArrays.hashCode(double[]).- Parameters:
array- array to be included in the hash code- Returns:
- this
HashCalc
-
feed
Feeds anObjectarray to the computed hash code. The array's deep (!) hash code is acquired usingArrays.deepHashCode(Object[]). So be careful if the array could potentially contain direct or indirect references to itself! If you are absolutely sure that the array does not contain any other arrays, usingfeedShallow(Object[])may save someinstanceofs.- Parameters:
array- array to be included in the hash code- Returns:
- this
HashCalc
-
feedShallow
Feeds anObjectarray to the computed hash code. The array's shallow (!) hash code is acquired usingArrays.hashCode(Object[]). So if the array contains other arrays, their hash code is based on their identity rather than their content. This may be useful if the array could potentially contain direct or indirect references to itself.- Parameters:
array- array to be included in the hash code- Returns:
- this
HashCalc
-
hashCode
public int hashCode()Returns the computed hash code. -
equals
-