Java Hash Code Calculate hashCode(int currentHashCodeValue, boolean b)

Here you can find the source of hashCode(int currentHashCodeValue, boolean b)

Description

hash Code

License

GNU General Public License

Declaration

public static int hashCode(int currentHashCodeValue, boolean b) 

Method Source Code

//package com.java2s;
/*//from  www . j a  v  a 2s .  c  o m
 *                    BioJava development code
 *
 * This code may be freely distributed and modified under the
 * terms of the GNU Lesser General Public Licence.  This should
 * be distributed with the code.  If you do not have a copy,
 * see:
 *
 *      http://www.gnu.org/copyleft/lesser.html
 *
 * Copyright for this code is held jointly by the individual
 * authors.  These should be listed in @author doc comments.
 *
 * For more information on the BioJava project and its aims,
 * or to join the biojava-l mailing list, visit the home page
 * at:
 *
 *      http://www.biojava.org/
 *
 */

public class Main {
    /**
     * the current hashCode is always first multiplied with this prime before the hashCode value for a particular field is
     * added.
     */
    public static final int PRIME = 1000003;

    public static int hashCode(int currentHashCodeValue, boolean b) {
        return PRIME * currentHashCodeValue + (b ? 1 : 0);
    }

    public static int hashCode(int currentHashCodeValue, int i) {
        return PRIME * currentHashCodeValue + i;
    }

    public static int hashCode(int currentHashCodeValue, long l) {
        return PRIME * (PRIME * currentHashCodeValue + ((int) (l >>> 32))) + ((int) (l & 0xFFFFFFFF));
    }

    public static int hashCode(int currentHashCodeValue, float f) {
        return hashCode(currentHashCodeValue, f == 0.0F ? 0 : Float.floatToIntBits(f));
    }

    public static int hashCode(int currentHashCodeValue, double d) {
        return hashCode(currentHashCodeValue, d == 0.0 ? 0L : Double.doubleToLongBits(d));
    }

    public static int hashCode(int currentHashCodeValue, boolean[] a) {
        if (a == null)
            return PRIME * currentHashCodeValue;

        final int l = a.length;
        for (int i = 0; i < l; i++) {
            currentHashCodeValue = hashCode(currentHashCodeValue, a[i]);
        }
        return currentHashCodeValue;
    }

    public static int hashCode(int currentHashCodeValue, int[] a) {
        if (a == null)
            return PRIME * currentHashCodeValue;

        final int l = a.length;
        for (int i = 0; i < l; i++) {
            currentHashCodeValue = hashCode(currentHashCodeValue, a[i]);
        }
        return currentHashCodeValue;
    }

    public static int hashCode(int currentHashCodeValue, long[] a) {
        if (a == null)
            return PRIME * currentHashCodeValue;

        final int l = a.length;
        for (int i = 0; i < l; i++) {
            currentHashCodeValue = hashCode(currentHashCodeValue, a[i]);
        }
        return currentHashCodeValue;
    }

    public static int hashCode(int currentHashCodeValue, float[] a) {
        if (a == null)
            return PRIME * currentHashCodeValue;

        final int l = a.length;
        for (int i = 0; i < l; i++) {
            currentHashCodeValue = hashCode(currentHashCodeValue, a[i]);
        }
        return currentHashCodeValue;
    }

    public static int hashCode(int currentHashCodeValue, double[] a) {
        if (a == null)
            return PRIME * currentHashCodeValue;

        final int l = a.length;
        for (int i = 0; i < l; i++) {
            currentHashCodeValue = hashCode(currentHashCodeValue, a[i]);
        }
        return currentHashCodeValue;
    }

    public static int hashCode(int currentHashCodeValue, Object[] a) {
        if (a == null)
            return PRIME * currentHashCodeValue;

        final int l = a.length;
        for (int i = 0; i < l; i++) {
            currentHashCodeValue = hashCode(currentHashCodeValue, a[i]);
        }
        return currentHashCodeValue;
    }

    public static int hashCode(int currentHashCodeValue, Object o) {
        return PRIME * currentHashCodeValue + (o == null ? 0 : o.hashCode());
    }
}

Related

  1. hashCode(final Object obj)
  2. hashCode(final Object object)
  3. hashCode(final Object... array)
  4. hashCode(float value)
  5. hashCode(int base, int multiplier, boolean fastArrays, Object... relevantValues)
  6. hashCode(int mul, Object obj)
  7. hashCode(int num)
  8. hashCode(int previous, boolean x)
  9. hashCode(int result, Object obj)