Java Hash Code Calculate hashCode(final Object... array)

Here you can find the source of hashCode(final Object... array)

Description

hash Code

License

Open Source License

Declaration

public static int hashCode(final Object... array) 

Method Source Code

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

public class Main {
    public static int hashCode(final Object... array) {
        if (array == null) {
            return 0;
        }/*from  ww  w  .j  a v  a  2 s  .  c  om*/

        int result = 1;
        Object element;

        for (final Object element2 : array) {
            element = element2;
            result = 31 * result + ((element == null) ? 0 : element.hashCode());
        }

        return result;
    }

    public static int hashCode(final boolean... array) {
        if (array == null) {
            return 0;
        }

        int result = 1;

        for (final boolean element : array) {
            result = 31 * result + (element ? 1231 : 1237);
        }

        return result;
    }

    public static int hashCode(final byte... array) {
        if (array == null) {
            return 0;
        }

        int result = 1;

        for (final byte element : array) {
            result = 31 * result + element;
        }

        return result;
    }

    public static int hashCode(final char... array) {
        if (array == null) {
            return 0;
        }

        int result = 1;

        for (final char element : array) {
            result = 31 * result + element;
        }

        return result;
    }

    public static int hashCode(final short... array) {
        if (array == null) {
            return 0;
        }

        int result = 1;

        for (final short element : array) {
            result = 31 * result + element;
        }

        return result;
    }

    public static int hashCode(final int... array) {
        if (array == null) {
            return 0;
        }

        int result = 1;

        for (final int element : array) {
            result = 31 * result + element;
        }

        return result;
    }

    public static int hashCode(final long... array) {
        if (array == null) {
            return 0;
        }

        int result = 1;
        long element;

        for (final long element2 : array) {
            element = element2;
            result = 31 * result + (int) (element ^ (element >>> 32));
        }

        return result;
    }

    public static int hashCode(final float... array) {
        if (array == null) {
            return 0;
        }

        int result = 1;

        for (final float element : array) {
            result = 31 * result + Float.floatToIntBits(element);
        }

        return result;
    }

    public static int hashCode(final double... array) {
        if (array == null) {
            return 0;
        }

        int result = 1;
        long bits;

        for (final double element : array) {
            bits = Double.doubleToLongBits(element);
            result = 31 * result + (int) (bits ^ (bits >>> 32));
        }

        return result;
    }

    public static int hashCode(final Object[] array, final int off, final int len) {
        if (array == null) {
            return 0;
        }

        int result = 1;
        final int end = off + len;
        Object element;

        for (int i = off; i < end; i++) {
            element = array[i];
            result = 31 * result + ((element == null) ? 0 : element.hashCode());
        }

        return result;
    }

    public static int hashCode(final boolean[] array, final int off, final int len) {
        if (array == null) {
            return 0;
        }

        int result = 1;
        final int end = off + len;

        for (int i = off; i < end; i++) {
            result = 31 * result + (array[i] ? 1231 : 1237);
        }

        return result;
    }

    public static int hashCode(final byte[] array, final int off, final int len) {
        if (array == null) {
            return 0;
        }

        int result = 1;
        final int end = off + len;

        for (int i = off; i < end; i++) {
            result = 31 * result + array[i];
        }

        return result;
    }

    public static int hashCode(final char[] array, final int off, final int len) {
        if (array == null) {
            return 0;
        }

        int result = 1;
        final int end = off + len;

        for (int i = off; i < end; i++) {
            result = 31 * result + array[i];
        }

        return result;
    }

    public static int hashCode(final short[] array, final int off, final int len) {
        if (array == null) {
            return 0;
        }

        int result = 1;
        final int end = off + len;

        for (int i = off; i < end; i++) {
            result = 31 * result + array[i];
        }

        return result;
    }

    public static int hashCode(final int[] array, final int off, final int len) {
        if (array == null) {
            return 0;
        }

        int result = 1;
        final int end = off + len;

        for (int i = off; i < end; i++) {
            result = 31 * result + array[i];
        }

        return result;
    }

    public static int hashCode(final long[] array, final int off, final int len) {
        if (array == null) {
            return 0;
        }

        int result = 1;
        final int end = off + len;
        long element;

        for (int i = off; i < end; i++) {
            element = array[i];
            result = 31 * result + (int) (element ^ (element >>> 32));
        }

        return result;
    }

    public static int hashCode(final float[] array, final int off, final int len) {
        if (array == null) {
            return 0;
        }

        int result = 1;
        final int end = off + len;

        for (int i = off; i < end; i++) {
            result = 31 * result + Float.floatToIntBits(array[i]);
        }

        return result;
    }

    public static int hashCode(final double[] array, final int off, final int len) {
        if (array == null) {
            return 0;
        }

        int result = 1;
        final int end = off + len;
        long bits;

        for (int i = off; i < end; i++) {
            bits = Double.doubleToLongBits(array[i]);
            result = 31 * result + (int) (bits ^ (bits >>> 32));
        }

        return result;
    }
}

Related

  1. hashCode(final long l)
  2. hashCode(final long v)
  3. hashCode(final Object obj)
  4. hashCode(final Object obj)
  5. hashCode(final Object object)
  6. hashCode(float value)
  7. hashCode(int base, int multiplier, boolean fastArrays, Object... relevantValues)
  8. hashCode(int currentHashCodeValue, boolean b)
  9. hashCode(int mul, Object obj)