| java.lang.Object org.apache.harmony.misc.HashCode
HashCode | final public class HashCode (Code) | | This class is a convenience method to sequentially calculate hash code of the
object based on the field values. The result depends on the order of elements
appended. The exact formula is the same as for
java.util.List.hashCode .
If you need order independent hash code just summate, multiply or XOR all
elements.
Suppose we have class:
class Thing {
long id;
String name;
float weight;
}
The hash code calculation can be expressed in 2 forms.
For maximum performance:
public int hashCode() {
int hashCode = HashCode.EMPTY_HASH_CODE;
hashCode = HashCode.combine(hashCode, id);
hashCode = HashCode.combine(hashCode, name);
hashCode = HashCode.combine(hashCode, weight);
return hashCode;
}
For convenience:
public int hashCode() {
return new HashCode().append(id).append(name).append(weight).hashCode();
}
See Also: java.util.List.hashCode |
Field Summary | |
final public static int | EMPTY_HASH_CODE The hashCode value before any data is appended, equals to 1. |
Method Summary | |
final public HashCode | append(int value) Appends value's hashCode to the current hashCode. | final public HashCode | append(long value) Appends value's hashCode to the current hashCode. | final public HashCode | append(float value) Appends value's hashCode to the current hashCode. | final public HashCode | append(double value) Appends value's hashCode to the current hashCode. | final public HashCode | append(boolean value) Appends value's hashCode to the current hashCode. | final public HashCode | append(Object value) Appends value's hashCode to the current hashCode. | public static int | combine(int hashCode, boolean value) Combines hashCode of previous elements sequence and value's hashCode. | public static int | combine(int hashCode, long value) Combines hashCode of previous elements sequence and value's hashCode. | public static int | combine(int hashCode, float value) Combines hashCode of previous elements sequence and value's hashCode. | public static int | combine(int hashCode, double value) Combines hashCode of previous elements sequence and value's hashCode. | public static int | combine(int hashCode, Object value) Combines hashCode of previous elements sequence and value's hashCode. | public static int | combine(int hashCode, int value) Combines hashCode of previous elements sequence and value's hashCode. | final public int | hashCode() |
EMPTY_HASH_CODE | final public static int EMPTY_HASH_CODE(Code) | | The hashCode value before any data is appended, equals to 1.
See Also: java.util.List.hashCode |
append | final public HashCode append(int value)(Code) | | Appends value's hashCode to the current hashCode.
Parameters: value - new element this |
append | final public HashCode append(long value)(Code) | | Appends value's hashCode to the current hashCode.
Parameters: value - new element this |
append | final public HashCode append(float value)(Code) | | Appends value's hashCode to the current hashCode.
Parameters: value - new element this |
append | final public HashCode append(double value)(Code) | | Appends value's hashCode to the current hashCode.
Parameters: value - new element this |
append | final public HashCode append(boolean value)(Code) | | Appends value's hashCode to the current hashCode.
Parameters: value - new element this |
append | final public HashCode append(Object value)(Code) | | Appends value's hashCode to the current hashCode.
Parameters: value - new element this |
combine | public static int combine(int hashCode, boolean value)(Code) | | Combines hashCode of previous elements sequence and value's hashCode.
Parameters: hashCode - previous hashCode value Parameters: value - new element combined hashCode |
combine | public static int combine(int hashCode, long value)(Code) | | Combines hashCode of previous elements sequence and value's hashCode.
Parameters: hashCode - previous hashCode value Parameters: value - new element combined hashCode |
combine | public static int combine(int hashCode, float value)(Code) | | Combines hashCode of previous elements sequence and value's hashCode.
Parameters: hashCode - previous hashCode value Parameters: value - new element combined hashCode |
combine | public static int combine(int hashCode, double value)(Code) | | Combines hashCode of previous elements sequence and value's hashCode.
Parameters: hashCode - previous hashCode value Parameters: value - new element combined hashCode |
combine | public static int combine(int hashCode, Object value)(Code) | | Combines hashCode of previous elements sequence and value's hashCode.
Parameters: hashCode - previous hashCode value Parameters: value - new element combined hashCode |
combine | public static int combine(int hashCode, int value)(Code) | | Combines hashCode of previous elements sequence and value's hashCode.
Parameters: hashCode - previous hashCode value Parameters: value - new element combined hashCode |
hashCode | final public int hashCode()(Code) | | Returns accumulated hashCode
|
|
|