Search in sources :

Example 1 with Nonbinding

use of javax.enterprise.util.Nonbinding in project deltaspike by apache.

the class ReflectionUtils method calculateHashCodeOfAnnotation.

public static int calculateHashCodeOfAnnotation(Annotation annotation, boolean skipNonbindingMembers) {
    Class annotationClass = annotation.annotationType();
    // the hashCode of an Annotation is calculated solely via the hashCodes
    // of it's members. If there are no members, it is 0.
    // thus we first need to get the annotation-class hashCode
    int hashCode = calculateHashCodeOfType(annotationClass);
    // and now add the hashCode of all it's Nonbinding members
    // the following algorithm is defined by the Annotation class definition
    // see the JavaDoc for Annotation!
    // we only change it so far that we skip evaluating @Nonbinding members
    final Method[] members = annotationClass.getDeclaredMethods();
    for (Method member : members) {
        if (skipNonbindingMembers && member.isAnnotationPresent(Nonbinding.class)) {
            // ignore the non binding
            continue;
        }
        // Member value
        final Object object = invokeMethod(annotation, member, Object.class, true, EMPTY_OBJECT_ARRAY);
        final int value;
        if (object.getClass().isArray()) {
            Class<?> type = object.getClass().getComponentType();
            if (type.isPrimitive()) {
                if (Long.TYPE == type) {
                    value = Arrays.hashCode((long[]) object);
                } else if (Integer.TYPE == type) {
                    value = Arrays.hashCode((int[]) object);
                } else if (Short.TYPE == type) {
                    value = Arrays.hashCode((short[]) object);
                } else if (Double.TYPE == type) {
                    value = Arrays.hashCode((double[]) object);
                } else if (Float.TYPE == type) {
                    value = Arrays.hashCode((float[]) object);
                } else if (Boolean.TYPE == type) {
                    value = Arrays.hashCode((boolean[]) object);
                } else if (Byte.TYPE == type) {
                    value = Arrays.hashCode((byte[]) object);
                } else if (Character.TYPE == type) {
                    value = Arrays.hashCode((char[]) object);
                } else {
                    value = 0;
                }
            } else {
                value = Arrays.hashCode((Object[]) object);
            }
        } else {
            value = object.hashCode();
        }
        hashCode = 29 * hashCode + value;
        hashCode = 29 * hashCode + member.getName().hashCode();
    }
    return hashCode;
}
Also used : Nonbinding(javax.enterprise.util.Nonbinding) Method(java.lang.reflect.Method)

Aggregations

Method (java.lang.reflect.Method)1 Nonbinding (javax.enterprise.util.Nonbinding)1