< prev index next >

src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/Comparators.java

Print this page

        

*** 78,88 **** private Comparator<Element> allClassesComparator = null; /** * Returns a Comparator for all classes, compares the simple names of ! * TypeElement, if equal then the fully qualified names. * * @return Comparator */ public Comparator<Element> makeAllClassesComparator() { if (allClassesComparator == null) { --- 78,89 ---- private Comparator<Element> allClassesComparator = null; /** * Returns a Comparator for all classes, compares the simple names of ! * TypeElement, if equal then the fully qualified names, and if equal again ! * the names of the enclosing modules. * * @return Comparator */ public Comparator<Element> makeAllClassesComparator() { if (allClassesComparator == null) {
*** 90,140 **** @Override public int compare(Element e1, Element e2) { int result = compareNames(e1, e2); if (result == 0) result = compareFullyQualifiedNames(e1, e2); ! return result; } }; } return allClassesComparator; } private Comparator<Element> packageComparator = null; /** ! * Returns a Comparator for packages, by comparing the fully qualified names. * * @return a Comparator */ public Comparator<Element> makePackageComparator() { if (packageComparator == null) { packageComparator = new ElementComparator() { @Override public int compare(Element pkg1, Element pkg2) { ! return compareFullyQualifiedNames(pkg1, pkg2); } }; } return packageComparator; } private Comparator<Element> deprecatedComparator = null; /** * Returns a Comparator for deprecated items listed on deprecated list page, by comparing the ! * fully qualified names. * * @return a Comparator */ public Comparator<Element> makeDeprecatedComparator() { if (deprecatedComparator == null) { deprecatedComparator = new ElementComparator() { @Override public int compare(Element e1, Element e2) { ! return compareFullyQualifiedNames(e1, e2); } }; } return deprecatedComparator; } --- 91,149 ---- @Override public int compare(Element e1, Element e2) { int result = compareNames(e1, e2); if (result == 0) result = compareFullyQualifiedNames(e1, e2); ! if (result == 0) ! result = compareModuleNames(e1, e2); return result; } }; } return allClassesComparator; } private Comparator<Element> packageComparator = null; /** ! * Returns a Comparator for packages, by comparing the fully qualified names, ! * and if those are equal the names of the enclosing modules. * * @return a Comparator */ public Comparator<Element> makePackageComparator() { if (packageComparator == null) { packageComparator = new ElementComparator() { @Override public int compare(Element pkg1, Element pkg2) { ! int result = compareFullyQualifiedNames(pkg1, pkg2); ! if (result == 0) ! result = compareModuleNames(pkg1, pkg2); ! return result; } }; } return packageComparator; } private Comparator<Element> deprecatedComparator = null; /** * Returns a Comparator for deprecated items listed on deprecated list page, by comparing the ! * fully qualified names, and if those are equal the names of the enclosing modules. * * @return a Comparator */ public Comparator<Element> makeDeprecatedComparator() { if (deprecatedComparator == null) { deprecatedComparator = new ElementComparator() { @Override public int compare(Element e1, Element e2) { ! int result = compareFullyQualifiedNames(e1, e2); ! if (result == 0) ! result = compareModuleNames(e1, e2); ! return result; } }; } return deprecatedComparator; }
*** 209,219 **** * otherwise: * 1. compare the ElementKind ex: Module, Package, Interface etc. * 2a. if equal and if the type is of ExecutableElement(Constructor, Methods), * a case insensitive comparison of parameter the type signatures * 2b. if equal, case sensitive comparison of the type signatures ! * 3. finally, if equal, compare the FQNs of the entities * @return an element comparator for index file use */ public Comparator<Element> makeIndexElementComparator() { if (indexUseComparator == null) { indexUseComparator = new ElementComparator() { --- 218,229 ---- * otherwise: * 1. compare the ElementKind ex: Module, Package, Interface etc. * 2a. if equal and if the type is of ExecutableElement(Constructor, Methods), * a case insensitive comparison of parameter the type signatures * 2b. if equal, case sensitive comparison of the type signatures ! * 3. if equal, compare the FQNs of the entities ! * 4. finally, if equal, compare the names of the enclosing modules * @return an element comparator for index file use */ public Comparator<Element> makeIndexElementComparator() { if (indexUseComparator == null) { indexUseComparator = new ElementComparator() {
*** 259,269 **** if (result != 0) { return result; } } // else fall back on fully qualified names ! return compareFullyQualifiedNames(e1, e2); } }; } return indexUseComparator; } --- 269,282 ---- if (result != 0) { return result; } } // else fall back on fully qualified names ! result = compareFullyQualifiedNames(e1, e2); ! if (result != 0) ! return result; ! return compareModuleNames(e1, e2); } }; } return indexUseComparator; }
*** 343,353 **** /** * Comparator for ClassUse presentations, and sorts as follows: * 1. member names * 2. then fully qualified member names * 3. then parameter types if applicable ! * 4. finally the element kinds ie. package, class, interface etc. * @return a comparator to sort classes and members for class use */ public Comparator<Element> makeClassUseComparator() { if (classUseComparator == null) { classUseComparator = new ElementComparator() { --- 356,367 ---- /** * Comparator for ClassUse presentations, and sorts as follows: * 1. member names * 2. then fully qualified member names * 3. then parameter types if applicable ! * 4. the element kinds ie. package, class, interface etc. ! * 5. finally the name of the enclosing modules * @return a comparator to sort classes and members for class use */ public Comparator<Element> makeClassUseComparator() { if (classUseComparator == null) { classUseComparator = new ElementComparator() {
*** 379,389 **** result = compareParameters(true, parameters1, parameters2); } if (result != 0) { return result; } ! return compareElementKinds(e1, e2); } }; } return classUseComparator; } --- 393,407 ---- result = compareParameters(true, parameters1, parameters2); } if (result != 0) { return result; } ! result = compareElementKinds(e1, e2); ! if (result != 0) { ! return result; ! } ! return compareModuleNames(e1, e2); } }; } return classUseComparator; }
*** 464,473 **** --- 482,511 ---- String thisElement = getFullyQualifiedName(e1); String thatElement = getFullyQualifiedName(e2); return utils.compareStrings(thisElement, thatElement); } + /** + * Compares the name of the modules of two elements. + * @param e1 the first element + * @param e2 the second element + * @return a negative integer, zero, or a positive integer as the first + * argument is less than, equal to, or greater than the second + */ + protected int compareModuleNames(Element e1, Element e2) { + ModuleElement m1 = utils.elementUtils.getModuleOf(e1); + ModuleElement m2 = utils.elementUtils.getModuleOf(e2); + if (m1 != null && m2 != null) { + return compareFullyQualifiedNames(m1, m2); + } else if (m1 != null) { + return 1; + } else if (m2 != null) { + return -1; + } + return 0; + } + protected int compareElementKinds(Element e1, Element e2) { return Integer.compare(getKindIndex(e1), getKindIndex(e2)); } private int getKindIndex(Element e) {
< prev index next >