Example usage for java.lang.reflect Array getShort

List of usage examples for java.lang.reflect Array getShort

Introduction

In this page you can find the example usage for java.lang.reflect Array getShort.

Prototype

public static native short getShort(Object array, int index)
        throws IllegalArgumentException, ArrayIndexOutOfBoundsException;

Source Link

Document

Returns the value of the indexed component in the specified array object, as a short .

Usage

From source file:Main.java

public static void main(String args[]) {
    short[] array = new short[] { 1, 2, 3 };

    short value = Array.getShort(array, 1);

    System.out.println(value);/*from  w  w w . j a  v  a 2  s.  co m*/

}

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

/**
 * Hash code.//from   ww w .  jav  a 2  s.c o  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;
}