Class HashCodeBuilder
public class HashCodeBuilder extends Object
Object.hashCode() methods. The code is based on
 HashCodeBuilder from commons-lang 2.1.- Since:
- 3.0
- 
Constructor SummaryConstructors Constructor Description HashCodeBuilder()Uses 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 Type Method Description HashCodeBuilderappend(boolean value)Append ahashCodefor aboolean.HashCodeBuilderappend(boolean[] array)Append ahashCodefor abooleanarray.HashCodeBuilderappend(byte value)Append ahashCodefor abyte.HashCodeBuilderappend(byte[] array)Append ahashCodefor abytearray.HashCodeBuilderappend(char value)Append ahashCodefor achar.HashCodeBuilderappend(char[] array)Append ahashCodefor achararray.HashCodeBuilderappend(double value)Append ahashCodefor adouble.HashCodeBuilderappend(double[] array)Append ahashCodefor adoublearray.HashCodeBuilderappend(float value)Append ahashCodefor afloat.HashCodeBuilderappend(float[] array)Append ahashCodefor afloatarray.HashCodeBuilderappend(int value)Append ahashCodefor anint.HashCodeBuilderappend(int[] array)Append ahashCodefor anintarray.HashCodeBuilderappend(long value)Append ahashCodefor along.HashCodeBuilderappend(long[] array)Append ahashCodefor alongarray.HashCodeBuilderappend(short value)Append ahashCodefor ashort.HashCodeBuilderappend(short[] array)Append ahashCodefor ashortarray.HashCodeBuilderappend(Object object)Append ahashCodefor anObject.HashCodeBuilderappend(Object[] array)Append ahashCodefor anObjectarray.HashCodeBuilderappendSuper(int superHashCode)Adds the result of super.hashCode() to this builder.inttoHashCode()Return 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
 
 
-