public static int calculateHashCodeOfAnnotation()

in deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/ReflectionUtils.java [406:489]


    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;
    }