⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hashcodeutils.java

📁 主要是对串口驱动的的一些控制源码!!! 在下载javacomm20-win32.zip后就可以使用。
💻 JAVA
字号:
// Copyright <applicate>, 2002. All Rights Reserved.

// This software is the proprietary information of www.applicate.de.

// Use is subject to license terms.



package de.applicate.util.lang;







/**

 * See JavaSpektrum 5/6/2002 page 64 and Joshua Bloch "Effective Java" page 38

 *

 * @author     hs

 * @created    11. Juni 2002

 * @version    $Author: mwulff $ checked in $Revision: 1.1 $ at $Date: 2003/01/16 13:04:46 $

 */

public abstract class HashCodeUtils {

    private final static  int[]  INTNULLNULL  = new int[]{0, 0};





    private HashCodeUtils() {

    }





    public static int getFieldHashCode(boolean _bValue) {

        return _bValue ? 0 : 1;

    }





    public static int getFieldHashCode(byte _byteValue) {

        return (int)_byteValue;

    }





    public static int getFieldHashCode(char _charValue) {

        return (int)_charValue;

    }





    public static int getFieldHashCode(short _shortValue) {

        return (int)_shortValue;

    }





    public static int getFieldHashCode(int _nValue) {

        return _nValue;

    }





    public static int getFieldHashCode(long _lValue) {

        return (int)(_lValue ^ (_lValue >>> 32));

    }





    public static int[] getFieldHashCodes(long _lValue) {

        return new int[]{(int)(_lValue >>> 32), (int)(_lValue & 0xFFFFFFFF)};

    }





    public static int getFieldHashCode(float _fValue) {

        return (_fValue == 0.0F) ? 0 : Float.floatToIntBits(_fValue);

    }





    public static int getFieldHashCode(double _dValue) {

        return (_dValue == 0.0) ? 0 : getFieldHashCode(Double.doubleToLongBits(_dValue));

    }





    public static int[] getFieldHashCodes(double _dValue) {

        return (_dValue == 0.0) ? INTNULLNULL : getFieldHashCodes(Double.doubleToLongBits(_dValue));

    }





    public static int getFieldHashCode(Object _oValue) {

        return (_oValue == null) ? 0 : _oValue.hashCode();

    }





    /**

     * Determins hash code if super class is a class without calculated hash code (Object).

     *

     * @param  _nHashCodesOfFields

     * @return

     */

    public static int getHashCode(final int[] _nHashCodesOfFields) {

        return getHashCode(_nHashCodesOfFields, 0);

    }





    /**

     * <code>HashCodeUtils.getHashCode(nHashCodeFields, super.hashCode()</code>

     *

     * @param  _nHashCodesOfFields

     * @param  _nHashCodeSuperClass  0 if super class is Object

     * @return

     */

    public static int getHashCode(final int[] _nHashCodesOfFields, int _nHashCodeSuperClass) {

        int  nResult  = (0 == _nHashCodeSuperClass) ? 17 : _nHashCodeSuperClass;

        for (int i = 0; i < _nHashCodesOfFields.length; i++) {

            nResult = 37 * nResult + _nHashCodesOfFields[i];

        }

        return nResult;

    }





    /**

     * Determins hash code if super class is a class without calculated hash code (Object).

     *

     * @param  _nHashCodesOfField

     * @return

     */

    public static int getHashCode(final int _nHashCodesOfField) {

        return getHashCode(_nHashCodesOfField, 0);

    }





    /**

     * <code>HashCodeUtils.getHashCode(nHashCodeField, super.hashCode()</code>

     *

     * @param  _nHashCodesOfField

     * @param  _nHashCodeSuperClass  0 if super class is Object

     * @return

     */

    public static int getHashCode(final int _nHashCodesOfField, int _nHashCodeSuperClass) {

        int  nResult  = (0 == _nHashCodeSuperClass) ? 17 : _nHashCodeSuperClass;

        return 37 * nResult + _nHashCodesOfField;

    }



}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -