Class HashCodeBuilder
Object.hashCode() methods. The code is based on
 HashCodeBuilder from commons-lang 2.1.- Since:
- 3.0
- 
Constructor SummaryConstructorsConstructorDescriptionUses two hard coded choices for the constants needed to build ahashCode.HashCodeBuilder(int initialNonZeroOddNumber, int multiplierNonZeroOddNumber) Two randomly chosen, non-zero, odd numbers must be passed in.
- 
Method SummaryModifier and TypeMethodDescriptionappend(boolean value) Append ahashCodefor aboolean.append(boolean[] array) Append ahashCodefor abooleanarray.append(byte value) Append ahashCodefor abyte.append(byte[] array) Append ahashCodefor abytearray.append(char value) Append ahashCodefor achar.append(char[] array) Append ahashCodefor achararray.append(double value) Append ahashCodefor adouble.append(double[] array) Append ahashCodefor adoublearray.append(float value) Append ahashCodefor afloat.append(float[] array) Append ahashCodefor afloatarray.append(int value) Append ahashCodefor anint.append(int[] array) Append ahashCodefor anintarray.append(long value) Append ahashCodefor along.append(long[] array) Append ahashCodefor alongarray.append(short value) Append ahashCodefor ashort.append(short[] array) Append ahashCodefor ashortarray.Append ahashCodefor anObject.Append ahashCodefor anObjectarray.appendSuper(int superHashCode) Adds the result of super.hashCode() to this builder.intReturn the computedhashCode.
- 
Constructor Details- 
HashCodeBuilderpublic HashCodeBuilder()Uses two hard coded choices for the constants needed to build a hashCode.
- 
HashCodeBuilderpublic HashCodeBuilder(int initialNonZeroOddNumber, int multiplierNonZeroOddNumber) Two randomly chosen, non-zero, odd numbers must be passed in. Ideally these should be different for each class, however this is not vital. Prime numbers are preferred, especially for the multiplier. - Parameters:
- initialNonZeroOddNumber- a non-zero, odd number used as the initial value
- multiplierNonZeroOddNumber- a non-zero, odd number used as the multiplier
- Throws:
- IllegalArgumentException- if the number is zero or even
 
 
- 
- 
Method Details- 
appendSuperAdds the result of super.hashCode() to this builder. - Parameters:
- superHashCode- the result of calling- super.hashCode()
- Returns:
- this HashCodeBuilder, used to chain calls.
- Since:
- 2.0
 
- 
appendAppend a hashCodefor anObject.- Parameters:
- object- the Object to add to the- hashCode
- Returns:
- this
 
- 
appendAppend a hashCodefor along.- Parameters:
- value- the long to add to the- hashCode
- Returns:
- this
 
- 
appendAppend a hashCodefor anint.- Parameters:
- value- the int to add to the- hashCode
- Returns:
- this
 
- 
appendAppend a hashCodefor ashort.- Parameters:
- value- the short to add to the- hashCode
- Returns:
- this
 
- 
appendAppend a hashCodefor achar.- Parameters:
- value- the char to add to the- hashCode
- Returns:
- this
 
- 
appendAppend a hashCodefor abyte.- Parameters:
- value- the byte to add to the- hashCode
- Returns:
- this
 
- 
appendAppend a hashCodefor adouble.- Parameters:
- value- the double to add to the- hashCode
- Returns:
- this
 
- 
appendAppend a hashCodefor afloat.- Parameters:
- value- the float to add to the- hashCode
- Returns:
- this
 
- 
appendAppend a hashCodefor aboolean.This adds iConstant * 1to thehashCodeand not a1231or1237as done in java.lang.Boolean. This is in accordance with the Effective Java design.- Parameters:
- value- the boolean to add to the- hashCode
- Returns:
- this
 
- 
appendAppend a hashCodefor anObjectarray.- Parameters:
- array- the array to add to the- hashCode
- Returns:
- this
 
- 
appendAppend a hashCodefor alongarray.- Parameters:
- array- the array to add to the- hashCode
- Returns:
- this
 
- 
appendAppend a hashCodefor anintarray.- Parameters:
- array- the array to add to the- hashCode
- Returns:
- this
 
- 
appendAppend a hashCodefor ashortarray.- Parameters:
- array- the array to add to the- hashCode
- Returns:
- this
 
- 
appendAppend a hashCodefor achararray.- Parameters:
- array- the array to add to the- hashCode
- Returns:
- this
 
- 
appendAppend a hashCodefor abytearray.- Parameters:
- array- the array to add to the- hashCode
- Returns:
- this
 
- 
appendAppend a hashCodefor adoublearray.- Parameters:
- array- the array to add to the- hashCode
- Returns:
- this
 
- 
appendAppend a hashCodefor afloatarray.- Parameters:
- array- the array to add to the- hashCode
- Returns:
- this
 
- 
appendAppend a hashCodefor abooleanarray.- Parameters:
- array- the array to add to the- hashCode
- Returns:
- this
 
- 
toHashCodepublic int toHashCode()Return the computed hashCode.- Returns:
- hashCodebased on the fields appended
 
 
-