langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/IndexBuilder.java
changeset 868 d0f233085cbb
parent 10 06bc494ca11e
child 1264 076a3cde30d5
equal deleted inserted replaced
867:1dff24b5f407 868:d0f233085cbb
    47 
    47 
    48     /**
    48     /**
    49      * Mapping of each Unicode Character with the member list containing
    49      * Mapping of each Unicode Character with the member list containing
    50      * members with names starting with it.
    50      * members with names starting with it.
    51      */
    51      */
    52     private Map indexmap = new HashMap();
    52     private Map<Character,List<Doc>> indexmap = new HashMap<Character,List<Doc>>();
    53 
    53 
    54     /**
    54     /**
    55      * Don't generate deprecated information if true.
    55      * Don't generate deprecated information if true.
    56      */
    56      */
    57     private boolean noDeprecated;
    57     private boolean noDeprecated;
    66 
    66 
    67     /**
    67     /**
    68      * A comparator used to sort classes and members.
    68      * A comparator used to sort classes and members.
    69      * Note:  Maybe this compare code belongs in the tool?
    69      * Note:  Maybe this compare code belongs in the tool?
    70      */
    70      */
    71     private class DocComparator implements Comparator {
    71     private class DocComparator implements Comparator<Doc> {
    72         public int compare(Object d1, Object d2) {
    72         public int compare(Doc d1, Doc d2) {
    73             String doc1 = (((Doc) d1).name());
    73             String doc1 = d1.name();
    74             String doc2 = (((Doc) d2).name());
    74             String doc2 = d2.name();
    75             int compareResult;
    75             int compareResult;
    76             if ((compareResult = doc1.compareToIgnoreCase(doc2)) != 0) {
    76             if ((compareResult = doc1.compareToIgnoreCase(doc2)) != 0) {
    77                 return compareResult;
    77                 return compareResult;
    78             } else if (d1 instanceof ProgramElementDoc && d2 instanceof ProgramElementDoc) {
    78             } else if (d1 instanceof ProgramElementDoc && d2 instanceof ProgramElementDoc) {
    79                  doc1 = (((ProgramElementDoc) d1).qualifiedName());
    79                  doc1 = (((ProgramElementDoc) d1).qualifiedName());
   122     /**
   122     /**
   123      * Sort the index map. Traverse the index map for all it's elements and
   123      * Sort the index map. Traverse the index map for all it's elements and
   124      * sort each element which is a list.
   124      * sort each element which is a list.
   125      */
   125      */
   126     protected void sortIndexMap() {
   126     protected void sortIndexMap() {
   127         for (Iterator it = indexmap.values().iterator(); it.hasNext(); ) {
   127         for (Iterator<List<Doc>> it = indexmap.values().iterator(); it.hasNext(); ) {
   128             Collections.sort((List)it.next(), new DocComparator());
   128             Collections.sort(it.next(), new DocComparator());
   129         }
   129         }
   130     }
   130     }
   131 
   131 
   132     /**
   132     /**
   133      * Get all the members in all the Packages and all the Classes
   133      * Get all the members in all the Packages and all the Classes
   139     protected void buildIndexMap(RootDoc root)  {
   139     protected void buildIndexMap(RootDoc root)  {
   140         PackageDoc[] packages = root.specifiedPackages();
   140         PackageDoc[] packages = root.specifiedPackages();
   141         ClassDoc[] classes = root.classes();
   141         ClassDoc[] classes = root.classes();
   142         if (!classesOnly) {
   142         if (!classesOnly) {
   143             if (packages.length == 0) {
   143             if (packages.length == 0) {
   144                 Set set = new HashSet();
   144                 Set<PackageDoc> set = new HashSet<PackageDoc>();
   145                 PackageDoc pd;
   145                 PackageDoc pd;
   146                 for (int i = 0; i < classes.length; i++) {
   146                 for (int i = 0; i < classes.length; i++) {
   147                     pd = classes[i].containingPackage();
   147                     pd = classes[i].containingPackage();
   148                     if (pd != null && pd.name().length() > 0) {
   148                     if (pd != null && pd.name().length() > 0) {
   149                         set.add(pd);
   149                         set.add(pd);
   150                     }
   150                     }
   151                 }
   151                 }
   152                 adjustIndexMap((PackageDoc[]) set.toArray(packages));
   152                 adjustIndexMap(set.toArray(packages));
   153             } else {
   153             } else {
   154                 adjustIndexMap(packages);
   154                 adjustIndexMap(packages);
   155             }
   155             }
   156         }
   156         }
   157         adjustIndexMap(classes);
   157         adjustIndexMap(classes);
   191                 String name = elements[i].name();
   191                 String name = elements[i].name();
   192                 char ch = (name.length()==0)?
   192                 char ch = (name.length()==0)?
   193                     '*' :
   193                     '*' :
   194                     Character.toUpperCase(name.charAt(0));
   194                     Character.toUpperCase(name.charAt(0));
   195                 Character unicode = new Character(ch);
   195                 Character unicode = new Character(ch);
   196                 List list = (List)indexmap.get(unicode);
   196                 List<Doc> list = indexmap.get(unicode);
   197                 if (list == null) {
   197                 if (list == null) {
   198                     list = new ArrayList();
   198                     list = new ArrayList<Doc>();
   199                     indexmap.put(unicode, list);
   199                     indexmap.put(unicode, list);
   200                 }
   200                 }
   201                 list.add(elements[i]);
   201                 list.add(elements[i]);
   202             }
   202             }
   203         }
   203         }