Example usage for java.util Arrays hashCode

List of usage examples for java.util Arrays hashCode

Introduction

In this page you can find the example usage for java.util Arrays hashCode.

Prototype

public static int hashCode(Object a[]) 

Source Link

Document

Returns a hash code based on the contents of the specified array.

Usage

From source file:org.jgentleframework.core.interceptor.AnnotationAroundAdviceMethodInterceptor.java

/**
 * Hash code./*from  www. j  a v  a2  s  .co  m*/
 * 
 * @param proxy
 *            the proxy
 * @return the int
 * @throws IllegalArgumentException
 *             the illegal argument exception
 * @throws IllegalAccessException
 *             the illegal access exception
 * @throws InvocationTargetException
 *             the invocation target exception
 */
protected int hashCode(Object proxy)
        throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {

    Method[] methods = targetClass.getDeclaredMethods();
    int hashCode = 0;
    for (Method method : methods) {
        Class<?> type = method.getReturnType();
        Object value = (Object) this.attributesMapping.get(method);
        if (value == null)
            value = method.getDefaultValue();
        // if type is primitive type
        if (type.isPrimitive()) {
            // //////////////////////////////////
            // //////////////////////////////////
            hashCode += 127 * method.getName().hashCode() ^ value.hashCode();
        } else if (type.isArray()) {
            Object array = method.invoke(proxy);
            Class<?> comtype = type.getComponentType();
            if (comtype == byte.class || comtype == Byte.class) {
                byte[] valueArr = new byte[Array.getLength(array)];
                for (int i = 0; i < valueArr.length; i++) {
                    valueArr[i] = Array.getByte(array, i);
                }
                hashCode += 127 * method.getName().hashCode() ^ Arrays.hashCode(valueArr);
            } else if (comtype == char.class || comtype == Character.class) {
                char[] valueArr = new char[Array.getLength(array)];
                for (int i = 0; i < valueArr.length; i++) {
                    valueArr[i] = Array.getChar(array, i);
                }
                hashCode += 127 * method.getName().hashCode() ^ Arrays.hashCode(valueArr);
            } else if (comtype == double.class || comtype == Double.class) {
                double[] valueArr = new double[Array.getLength(array)];
                for (int i = 0; i < valueArr.length; i++) {
                    valueArr[i] = Array.getDouble(array, i);
                }
                hashCode += 127 * method.getName().hashCode() ^ Arrays.hashCode(valueArr);
            } else if (comtype == float.class || comtype == Float.class) {
                float[] valueArr = new float[Array.getLength(array)];
                for (int i = 0; i < valueArr.length; i++) {
                    valueArr[i] = Array.getFloat(array, i);
                }
                hashCode += 127 * method.getName().hashCode() ^ Arrays.hashCode(valueArr);
            } else if (comtype == int.class || comtype == Integer.class) {
                int[] valueArr = new int[Array.getLength(array)];
                for (int i = 0; i < valueArr.length; i++) {
                    valueArr[i] = Array.getInt(array, i);
                }
                hashCode += 127 * method.getName().hashCode() ^ Arrays.hashCode(valueArr);
            } else if (comtype == long.class || comtype == Long.class) {
                long[] valueArr = new long[Array.getLength(array)];
                for (int i = 0; i < valueArr.length; i++) {
                    valueArr[i] = Array.getLong(array, i);
                }
                hashCode += 127 * method.getName().hashCode() ^ Arrays.hashCode(valueArr);
            } else if (comtype == short.class || comtype == Short.class) {
                short[] valueArr = new short[Array.getLength(array)];
                for (int i = 0; i < valueArr.length; i++) {
                    valueArr[i] = Array.getShort(array, i);
                }
                hashCode += 127 * method.getName().hashCode() ^ Arrays.hashCode(valueArr);
            } else if (comtype == boolean.class || comtype == Boolean.class) {
                boolean[] valueArr = new boolean[Array.getLength(array)];
                for (int i = 0; i < valueArr.length; i++) {
                    valueArr[i] = Array.getBoolean(array, i);
                }
                hashCode += 127 * method.getName().hashCode() ^ Arrays.hashCode(valueArr);
            } else {
                Object[] valueArr = new Object[Array.getLength(array)];
                for (int i = 0; i < valueArr.length; i++) {
                    valueArr[i] = Array.get(array, i);
                }
                hashCode += 127 * method.getName().hashCode() ^ Arrays.hashCode(valueArr);
            }
        } else {
            // Object value = method.invoke(proxy);
            hashCode += 127 * method.getName().hashCode() ^ value.hashCode();
        }
    }
    return hashCode;
}

From source file:com.opengamma.analytics.math.function.RealPolynomialFunction1D.java

@Override
public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = prime * result + Arrays.hashCode(_coefficients);
    return result;
}

From source file:org.apache.accumulo.core.rpc.SslConnectionParams.java

@Override
public int hashCode() {
    int hash = 0;
    hash = 31 * hash + (clientAuth ? 0 : 1);
    hash = 31 * hash + (useJsse ? 0 : 1);
    if (useJsse)//from  w ww .j  a v a2s.  c  o  m
        return hash;
    hash = 31 * hash + (keyStoreSet ? 0 : 1);
    hash = 31 * hash + (trustStoreSet ? 0 : 1);
    if (keyStoreSet) {
        hash = 31 * hash + keyStorePath.hashCode();
    }
    if (trustStoreSet) {
        hash = 31 * hash + trustStorePath.hashCode();
    }
    hash = 31 * hash + clientProtocol.hashCode();
    hash = 31 * hash + Arrays.hashCode(serverProtocols);
    return super.hashCode();
}

From source file:ffx.potential.parameters.ImproperTorsionType.java

/**
 * {@inheritDoc}/*from ww  w.  ja  va  2 s .  c o m*/
 *
 * Implementation of the <code>hashCode</code> method.
 *
 * @since 1.0
 */
@Override
public int hashCode() {
    int hash = 7;
    hash = 89 * hash + Arrays.hashCode(atomClasses);
    return hash;
}

From source file:com.htmlhifive.pitalium.core.model.TargetResult.java

@Override
public int hashCode() {
    int result1 = result != null ? result.hashCode() : 0;
    final int hashPrime = 31;
    result1 = hashPrime * result1 + (target != null ? target.hashCode() : 0);
    result1 = hashPrime * result1 + (excludes != null ? excludes.hashCode() : 0);
    result1 = hashPrime * result1 + (moveTarget != null ? moveTarget.hashCode() : 0);
    result1 = hashPrime * result1 + (hiddenElementSelectors != null ? hiddenElementSelectors.hashCode() : 0);
    result1 = hashPrime * result1 + (image != null ? image.hashCode() : 0);
    result1 = hashPrime * result1 + (options != null ? Arrays.hashCode(options) : 0);
    return result1;
}

From source file:org.apache.tajo.OverridableConf.java

@Override
public int hashCode() {
    final int prime = 31;
    int result = super.hashCode();
    result = prime * result + ((conf == null) ? 0 : conf.hashCode());
    result = prime * result + Arrays.hashCode(configTypes);
    return result;
}

From source file:org.opentides.bean.Widget.java

@Override
public int hashCode() {
    final int prime = 31;
    int result = super.hashCode();
    result = prime * result + ((accessCode == null) ? 0 : accessCode.hashCode());
    result = prime * result + Arrays.hashCode(cache);
    result = prime * result + (int) (cacheDuration ^ (cacheDuration >>> 32));
    result = prime * result + ((cacheType == null) ? 0 : cacheType.hashCode());
    result = prime * result + ((description == null) ? 0 : description.hashCode());
    result = prime * result + ((isShown == null) ? 0 : isShown.hashCode());
    result = prime * result + ((isUserDefined == null) ? 0 : isUserDefined.hashCode());
    result = prime * result + ((lastCacheUpdate == null) ? 0 : lastCacheUpdate.hashCode());
    result = prime * result + ((name == null) ? 0 : name.hashCode());
    result = prime * result + ((screenshot == null) ? 0 : screenshot.hashCode());
    result = prime * result + ((title == null) ? 0 : title.hashCode());
    result = prime * result + ((url == null) ? 0 : url.hashCode());
    return result;
}

From source file:eu.planets_project.services.datatypes.ImmutableContent.java

/**
 * {@inheritDoc}//from  www  . ja  v  a  2  s. c  o m
 * @see java.lang.Object#hashCode()
 */
@Override
public int hashCode() {
    return dataHandler != null ? dataHandler.hashCode()
            : bytes != null ? Arrays.hashCode(bytes) : reference.toString().hashCode();
}

From source file:org.apache.hadoop.hbase.HRegionInfo.java

private void setHashCode() {
    int result = Arrays.hashCode(this.regionName);
    result ^= this.regionId;
    result ^= Arrays.hashCode(this.startKey);
    result ^= Arrays.hashCode(this.endKey);
    result ^= Boolean.valueOf(this.offLine).hashCode();
    result ^= Arrays.hashCode(this.tableName.getName());
    this.hashCode = result;
}

From source file:ffx.potential.parameters.AngleType.java

/**
 * {@inheritDoc}//from   w w  w .  ja  va 2s  .co  m
 */
@Override
public int hashCode() {
    int hash = 5;
    hash = 37 * hash + Arrays.hashCode(atomClasses);
    return hash;
}