Java Utililty Methods Hash Code Calculate

List of utility methods to do Hash Code Calculate

Description

The list of methods to do Hash Code Calculate are organized into topic(s).

Method

inthashcode(Object... as)
Compute the hash code for the given items
if (as == null)
    return 0;
int h = 1;
int i = 0;
while (i < as.length) {
    if (as[i] != null) {
        h = 31 * h + as[i].hashCode();
        i += 1;
...
inthashCode(Object... fields)
hash Code
if (fields == null)
    throw new IllegalArgumentException("Fields cannot be null");
int hashcode = 0;
for (int i = 0; i < fields.length; i++) {
    Object currentField = fields[i];
    hashcode += currentField != null ? currentField.hashCode() : 0;
return hashcode;
...
inthashCode(Object... objects)
Hash code from a bunch of objects
int result = 31 + hashCode(objects[0]);
for (int i = 1; i < objects.length; i++) {
    result *= 31 + hashCode(objects[i]);
return result;
inthashCode(Object... objects)
Computes the hash code of a set of objects.
int result = 17;
if (objects != null) {
    for (final Object obj : objects) {
        result = 31 * result + (obj == null ? 0 : obj.hashCode());
return result;
inthashCode(Object... objs)
hash Code
int code = 0;
for (Object o : objs) {
    code ^= System.identityHashCode(o);
return code;
inthashCode(Object... toHash)
shortcut for hashing some stuff.
int hash = 7;
for (Object o : toHash) {
    if (o != null) {
        hash = 31 * hash + o.hashCode();
return hash;
inthashCode(Object[] array)
hash Code
int prime = 31;
if (array == null) {
    return 0;
int result = 1;
for (int index = 0; index < array.length; index++) {
    result = prime * result + (array[index] == null ? 0 : array[index].hashCode());
return result;
inthashCode(Object[] thisFields)
Helper function to compute hasCode by fields.
final int prime = 31;
int result = 1;
for (int i = 0; i < thisFields.length; i++) {
    Object field = thisFields[i];
    if (field != null) {
        result = prime * result + field.hashCode();
return result;
inthashcode_old(final int[] array)
Computes a hashcode for an integer array.
int result = 23;
for (int i = 0; i < array.length; i++) {
    result = (37 * result) + array[i];
return result;
inthashCodeEps(double value)
hash Code Eps
return Long.valueOf(Math.round(value / EPSILON)).hashCode();