Java Hash Code Calculate hashCode(boolean bool)

Here you can find the source of hashCode(boolean bool)

Description

Return the same value as Boolean#hashCode() .

License

Open Source License

Parameter

Parameter Description
bool boolean

Return

hash code

Declaration

public static int hashCode(boolean bool) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2008, 2010 VMware Inc.//from   w w w. j  a  v  a2s.  c  o  m
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   VMware Inc. - initial contribution
 *******************************************************************************/

public class Main {
    /**
     * Return the same value as <code>{@link Boolean#hashCode()}</code>.
     * @param bool boolean
     * @return hash code
     * @see Boolean#hashCode()
     */
    public static int hashCode(boolean bool) {
        return bool ? 1231 : 1237;
    }

    /**
     * Return the same value as <code>{@link Double#hashCode()}</code>.
     * @param dbl double
     * @return hash code
     * @see Double#hashCode()
     */
    public static int hashCode(double dbl) {
        long bits = Double.doubleToLongBits(dbl);
        return hashCode(bits);
    }

    /**
     * Return the same value as <code>{@link Float#hashCode()}</code>.
     * @param flt float
     * @see Float#hashCode()
      * @return hash code
     */
    public static int hashCode(float flt) {
        return Float.floatToIntBits(flt);
    }

    /**
     * Return the same value as <code>{@link Long#hashCode()}</code>.
     * @param lng long
     * @see Long#hashCode()
      * @return hash code
     */
    public static int hashCode(long lng) {
        return (int) (lng ^ (lng >>> 32));
    }
}

Related

  1. generateHash(String tcString)
  2. generateHashSalt(int length)
  3. generateHashUUID(String digestData)
  4. hashCode(boolean b)
  5. hashCode(boolean b)
  6. hashCode(boolean bool)
  7. hashCode(boolean value)
  8. hashCode(byte a[])
  9. hashCode(byte a[], int offset, int length)