Message10244
The following code also considers overloaded setter methods:
// === START PATCH FOR BUG 2391 ===
Comparator<Class<?>> classComparator = new Comparator<Class<?>>() {
@Override public int compare(Class<?> c1, Class<?> c2) {
if (c1 != c2) {
if (c1.isAssignableFrom(c2)) { return -1; }
if (c2.isAssignableFrom(c1)) { return 1; }
}
return 0;
}
};
Comparator<Method> methodComparator = new Comparator<Method>() {
@Override public int compare(Method m1, Method m2) {
int result = m1.getName().compareTo(m2.getName());
if (result != 0) {
return result;
}
Parameter[] p1 = m1.getParameters();
Parameter[] p2 = m2.getParameters();
int n1 = p1.length;
int n2 = p2.length;
result = n1 - n2;
if (result != 0) {
return result;
}
result = classComparator.compare(m1.getDeclaringClass(), m2.getDeclaringClass());
if (result != 0) {
return result;
}
if (n1 == 0) {
result = classComparator.compare(m1.getReturnType(), m2.getReturnType());
} else if (n1 == 1) {
result = classComparator.compare(p1[0].getType(), p2[0].getType());
}
return result;
}
};
Arrays.sort(methods, methodComparator);
// ==== END PATCH FOR BUG 2391 ==== |
|
Date |
User |
Action |
Args |
2015-09-10 12:52:10 | jsaiz | set | messageid: <1441889530.07.0.747861208443.issue2391@psf.upfronthosting.co.za> |
2015-09-10 12:52:10 | jsaiz | set | recipients:
+ jsaiz, zyasoft |
2015-09-10 12:52:10 | jsaiz | link | issue2391 messages |
2015-09-10 12:52:09 | jsaiz | create | |
|