Package org.apache.juneau.internal
Class HashCode
java.lang.Object
org.apache.juneau.internal.HashCode
Utility class for generating integer hash codes.
General usage:
See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionadd
(int i) Hashes the hashcode into this object.Hashes the hashcode of the specified object into this object.static final HashCode
create()
Create a new HashCode object.int
get()
Return the calculated hashcode value.static final int
Calculates a hash code over the specified objects.protected Object
Converts the object to a normalized form before grabbing it's hashcode.
-
Constructor Details
-
HashCode
public HashCode()
-
-
Method Details
-
create
Create a new HashCode object.- Returns:
- A new HashCode object.
-
of
Calculates a hash code over the specified objects.- Parameters:
objects
- The objects to calculate a hashcode over.- Returns:
- A numerical hashcode value.
-
add
Hashes the hashcode of the specified object into this object.- Parameters:
o
- The object whose hashcode will be hashed with this object.- Returns:
- This object.
-
add
Hashes the hashcode into this object.The formula is simply
hashCode = 31*hashCode + i; - Parameters:
i
- The hashcode to hash into this object's hashcode.- Returns:
- This object.
-
get
Return the calculated hashcode value.- Returns:
- The calculated hashcode.
-
unswap
Converts the object to a normalized form before grabbing it's hashcode.Subclasses can override this method to provide specialized handling (e.g. converting numbers to strings so that
123 and"123" end up creating the same hashcode.)Default implementation does nothing.
- Parameters:
o
- The object to normalize before getting it's hashcode.- Returns:
- The normalized object.
-