Java Hash Code Calculate hashCode(int base, int multiplier, boolean fastArrays, Object... relevantValues)

Here you can find the source of hashCode(int base, int multiplier, boolean fastArrays, Object... relevantValues)

Description

hash Code

License

Open Source License

Declaration

public static int hashCode(int base, int multiplier, boolean fastArrays, Object... relevantValues) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static final int DEFAULT_BASE = 17, DEFAULT_MULTIPLIER = 59;
    public static final boolean DEFAULT_FASTARRAYS = false;

    public static int hashCode(int base, int multiplier, boolean fastArrays, Object... relevantValues) {
        int hashCode = base * multiplier + relevantValues.length;

        for (Object value : relevantValues) {
            if (value == null || value.getClass() == Object.class)
                continue;
            if (fastArrays && value instanceof Object[]) {
                Object[] array = (Object[]) value;
                hashCode = hashCode * multiplier + array.length;
                for (int i = 0; i < array.length; i <<= 1) {
                    if (array[i] == null)
                        continue;
                    hashCode = hashCode * multiplier + array[i].hashCode();
                }//from  w ww .j  a v a  2 s  . com
            } else {
                hashCode = hashCode * multiplier + value.hashCode();
            }
        }
        return hashCode;
    }

    public static int hashCode(Object... relevantValues) {
        return hashCode(DEFAULT_BASE, DEFAULT_MULTIPLIER, DEFAULT_FASTARRAYS, relevantValues);
    }
}

Related

  1. hashCode(final Object obj)
  2. hashCode(final Object obj)
  3. hashCode(final Object object)
  4. hashCode(final Object... array)
  5. hashCode(float value)
  6. hashCode(int currentHashCodeValue, boolean b)
  7. hashCode(int mul, Object obj)
  8. hashCode(int num)
  9. hashCode(int previous, boolean x)