876 * for creating specific comparators for an use-case. |
876 * for creating specific comparators for an use-case. |
877 * @param <T> a Doc entity |
877 * @param <T> a Doc entity |
878 */ |
878 */ |
879 static abstract class DocComparator<T extends Doc> implements Comparator<Doc> { |
879 static abstract class DocComparator<T extends Doc> implements Comparator<Doc> { |
880 /** |
880 /** |
881 * compares two parameter arrays by first comparing the length of the arrays, and |
881 * compares two parameter arrays by comparing each Type of the parameter in the array, |
882 * then each Type of the parameter in the array. |
882 * as possible, if the matched strings are identical, and have mismatched array lengths |
|
883 * then compare the lengths. |
883 * @param params1 the first parameter array. |
884 * @param params1 the first parameter array. |
884 * @param params2 the first parameter array. |
885 * @param params2 the first parameter array. |
885 * @return a negative integer, zero, or a positive integer as the first |
886 * @return a negative integer, zero, or a positive integer as the first |
886 * argument is less than, equal to, or greater than the second. |
887 * argument is less than, equal to, or greater than the second. |
887 */ |
888 */ |
888 protected int compareParameters(Parameter[] params1, Parameter[] params2) { |
889 protected int compareParameters(Parameter[] params1, Parameter[] params2) { |
889 if (params1.length == 0 && params2.length == 0) { |
890 if (params1.length == 0 && params2.length == 0) { |
890 return 0; |
891 return 0; |
891 } |
892 } |
892 int result = Integer.compare(params1.length, params2.length); |
893 // try to compare as many as possible |
893 if (result != 0) { |
894 for (int i = 0; i < params1.length && i < params2.length; i++) { |
894 return result; |
895 int result = compareStrings(params1[i].typeName(), params2[i].typeName()); |
895 } |
|
896 for (int i = 0; i < params1.length; i++) { |
|
897 result = compareStrings(params1[i].typeName(), params2[i].typeName()); |
|
898 if (result != 0) { |
896 if (result != 0) { |
899 return result; |
897 return result; |
900 } |
898 } |
901 } |
899 } |
902 return 0; |
900 return Integer.compare(params1.length, params2.length); |
903 } |
901 } |
904 |
902 |
905 /** |
903 /** |
906 * Compares two MemberDocs, typically the name of a method, |
904 * Compares two MemberDocs, typically the name of a method, |
907 * field or constructor. |
905 * field or constructor. |