in webbeans-impl/src/main/java/org/apache/webbeans/container/BeanCacheKey.java [279:388]
public int compare(Annotation annotation1, Annotation annotation2)
{
Class<? extends Annotation> type1 = annotation1.annotationType();
Class<? extends Annotation> type2 = annotation2.annotationType();
int temp = type1.getName().compareTo(type2.getName());
if (temp != 0)
{
return temp;
}
if (annotation1 instanceof EmptyAnnotationLiteral || annotation2 instanceof EmptyAnnotationLiteral)
{
// if any of those 2 annotations are known to have no members
// then we can immediately return as we know the 2 annotations mean the same
return 0;
}
Method[] member1 = type1.getDeclaredMethods();
Method[] member2 = type2.getDeclaredMethods();
// TBD: the order of the list of members seems to be deterministic
int i = 0;
int j = 0;
int length1 = member1.length;
int length2 = member2.length;
// find next nonbinding
for (;; i++, j++)
{
while (i < length1 && member1[i].isAnnotationPresent(Nonbinding.class))
{
i++;
}
while (j < length2 && member2[j].isAnnotationPresent(Nonbinding.class))
{
j++;
}
if (i >= length1 && j >= length2)
{ // both ended
return 0;
}
else if (i >= length1)
{ // #1 ended
return 1;
}
else if (j >= length2)
{ // #2 ended
return -1;
}
else
{ // not ended
int c = member1[i].getName().compareTo(member2[j].getName());
if (c != 0)
{
return c;
}
Object value1 = callMethod(annotation1, member1[i]);
Object value2 = callMethod(annotation2, member2[j]);
assert value1.getClass().equals(value2.getClass());
if (value1 instanceof Comparable)
{
c = ((Comparable)value1).compareTo(value2);
if (c != 0)
{
return c;
}
}
else if (value1.getClass().isArray())
{
c = value1.getClass().getComponentType().getName()
.compareTo(value2.getClass().getComponentType().getName());
if (c != 0)
{
return c;
}
int length = Array.getLength(value1);
c = length - Array.getLength(value2);
if (c != 0)
{
return c;
}
for (int k = 0; k < length; k++)
{
c = ((Comparable)Array.get(value1, k)).compareTo(Array.get(value2, k));
if (c != 0)
{
return c;
}
}
}
else if (value1 instanceof Class)
{
c = ((Class)value1).getName().compareTo(((Class) value2).getName());
if (c != 0)
{
return c;
}
}
else
{
// valid types for members are only Comparable, Arrays, or Class
assert false;
}
}
}
}