private static String createAnnotationCollectionId()

in deltaspike/core/api/obsolete/src/main/java/org/apache/deltaspike/core/util/Annotateds.java [573:655]


    private static String createAnnotationCollectionId(Collection<Annotation> annotations)
    {
        if (annotations.isEmpty())
        {
            return "";
        }

        StringBuilder builder = new StringBuilder();
        builder.append('[');

        List<Annotation> annotationList = new ArrayList<Annotation>(annotations.size());
        annotationList.addAll(annotations);
        Collections.sort(annotationList, AnnotationComparator.INSTANCE);

        for (Annotation a : annotationList)
        {
            builder.append('@');
            builder.append(a.annotationType().getName());
            builder.append('(');
            Method[] declaredMethods = a.annotationType().getDeclaredMethods();
            List<Method> methods = new ArrayList<Method>(declaredMethods.length);
            methods.addAll(Arrays.asList(declaredMethods));
            Collections.sort(methods, MethodComparator.INSTANCE);

            for (int i = 0; i < methods.size(); ++i)
            {
                Method method = methods.get(i);
                try
                {
                    Object value = method.invoke(a);
                    builder.append(method.getName());
                    builder.append('=');
                    if (value.getClass().isArray())
                    {
                        Class<?> componentType = value.getClass().getComponentType();
                        if (componentType.isAnnotation())
                        {
                            builder.append(Arrays.asList((Object[]) value));
                        }
                        else if (componentType instanceof Class<?>)
                        {
                            builder.append(createArrayId(value));
                        }
                        else
                        {
                            builder.append(value.toString());
                        }
                    }
                    else
                    {
                        builder.append(value.toString());
                    }
                }
                catch (NullPointerException e)
                {
                    throw new RuntimeException("NullPointerException accessing annotation member, annotation:"
                            + a.annotationType().getName() + " member: " + method.getName(), e);
                }
                catch (IllegalArgumentException e)
                {
                    throw new RuntimeException("IllegalArgumentException accessing annotation member, annotation:"
                            + a.annotationType().getName() + " member: " + method.getName(), e);
                }
                catch (IllegalAccessException e)
                {
                    throw new RuntimeException("IllegalAccessException accessing annotation member, annotation:"
                            + a.annotationType().getName() + " member: " + method.getName(), e);
                }
                catch (InvocationTargetException e)
                {
                    throw new RuntimeException("InvocationTargetException accessing annotation member, annotation:"
                            + a.annotationType().getName() + " member: " + method.getName(), e);
                }
                if (i + 1 != methods.size())
                {
                    builder.append(',');
                }
            }
            builder.append(')');
        }
        builder.append(']');
        return builder.toString();
    }