8038583: [javadoc] Refactor uses of arrays to Collections
authorksrini
Fri, 18 Apr 2014 08:44:53 -0700
changeset 24221 2376793dd33b
parent 24220 eb213562268d
child 24222 244127f8dd79
8038583: [javadoc] Refactor uses of arrays to Collections Reviewed-by: jjg
langtools/src/share/classes/com/sun/tools/doclets/formats/html/AbstractPackageIndexWriter.java
langtools/src/share/classes/com/sun/tools/doclets/formats/html/ClassUseWriter.java
langtools/src/share/classes/com/sun/tools/doclets/formats/html/ConfigurationImpl.java
langtools/src/share/classes/com/sun/tools/doclets/formats/html/FrameOutputWriter.java
langtools/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDoclet.java
langtools/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java
langtools/src/share/classes/com/sun/tools/doclets/formats/html/PackageIndexFrameWriter.java
langtools/src/share/classes/com/sun/tools/doclets/formats/html/PackageIndexWriter.java
langtools/src/share/classes/com/sun/tools/doclets/formats/html/PackageTreeWriter.java
langtools/src/share/classes/com/sun/tools/doclets/formats/html/PackageUseWriter.java
langtools/src/share/classes/com/sun/tools/doclets/formats/html/ProfilePackageIndexFrameWriter.java
langtools/src/share/classes/com/sun/tools/doclets/formats/html/TreeWriter.java
langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/Configuration.java
langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/builders/AbstractBuilder.java
langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/builders/AnnotationTypeBuilder.java
langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/builders/BuilderFactory.java
langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/builders/ClassBuilder.java
langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/builders/ProfileSummaryBuilder.java
langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/DeprecatedAPIListBuilder.java
langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/Group.java
--- a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/AbstractPackageIndexWriter.java	Fri Apr 18 08:35:59 2014 -0700
+++ b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/AbstractPackageIndexWriter.java	Fri Apr 18 08:44:53 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -49,9 +49,9 @@
 public abstract class AbstractPackageIndexWriter extends HtmlDocletWriter {
 
     /**
-     * Array of Packages to be documented.
+     * A Set of Packages to be documented.
      */
-    protected PackageDoc[] packages;
+    protected SortedSet<PackageDoc> packages;
 
     /**
      * Constructor. Also initializes the packages variable.
@@ -89,12 +89,12 @@
     /**
      * Adds the packages list to the documentation tree.
      *
-     * @param packages an array of packagedoc objects
+     * @param packages a collection of packagedoc objects
      * @param text caption for the table
      * @param tableSummary summary for the table
      * @param body the document tree to which the packages list will be added
      */
-    protected abstract void addPackagesList(PackageDoc[] packages, String text,
+    protected abstract void addPackagesList(Collection<PackageDoc> packages, String text,
             String tableSummary, Content body);
 
     /**
@@ -141,15 +141,14 @@
      * Adds package index contents. Call appropriate methods from
      * the sub-classes. Adds it to the body HtmlTree
      *
-     * @param packages array of packages to be documented
+     * @param packages a collection of packages to be documented
      * @param text string which will be used as the heading
      * @param tableSummary summary for the table
      * @param body the document tree to which the index contents will be added
      */
-    protected void addIndexContents(PackageDoc[] packages, String text,
+    protected void addIndexContents(Collection<PackageDoc> packages, String text,
             String tableSummary, Content body) {
-        if (packages.length > 0) {
-            Arrays.sort(packages);
+        if (!packages.isEmpty()) {
             HtmlTree div = new HtmlTree(HtmlTag.DIV);
             div.addStyle(HtmlStyle.indexHeader);
             addAllClassesLink(div);
--- a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/ClassUseWriter.java	Fri Apr 18 08:35:59 2014 -0700
+++ b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/ClassUseWriter.java	Fri Apr 18 08:44:53 2014 -0700
@@ -245,7 +245,7 @@
     protected void addClassUse(Content contentTree) throws IOException {
         HtmlTree ul = new HtmlTree(HtmlTag.UL);
         ul.addStyle(HtmlStyle.blockList);
-        if (configuration.packages.length > 1) {
+        if (configuration.packages.size() > 1) {
             addPackageList(ul);
             addPackageAnnotationList(ul);
         }
--- a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/ConfigurationImpl.java	Fri Apr 18 08:35:59 2014 -0700
+++ b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/ConfigurationImpl.java	Fri Apr 18 08:44:53 2014 -0700
@@ -495,15 +495,15 @@
         if (createoverview) {
             topFile = DocPaths.OVERVIEW_SUMMARY;
         } else {
-            if (packages.length == 1 && packages[0].name().equals("")) {
+            if (packages.size() == 1 && packages.first().name().equals("")) {
                 if (root.classes().length > 0) {
                     ClassDoc[] classarr = root.classes();
                     Arrays.sort(classarr);
                     ClassDoc cd = getValidClass(classarr);
                     topFile = DocPath.forClass(cd);
                 }
-            } else {
-                topFile = DocPath.forPackage(packages[0]).resolve(DocPaths.PACKAGE_SUMMARY);
+            } else if (!packages.isEmpty()) {
+                topFile = DocPath.forPackage(packages.first()).resolve(DocPaths.PACKAGE_SUMMARY);
             }
         }
     }
@@ -534,7 +534,7 @@
      * packages is more than one. Sets {@link #createoverview} field to true.
      */
     protected void setCreateOverview() {
-        if ((overview || packages.length > 1) && !nooverview) {
+        if ((overview || packages.size() > 1) && !nooverview) {
             createoverview = true;
         }
     }
--- a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/FrameOutputWriter.java	Fri Apr 18 08:35:59 2014 -0700
+++ b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/FrameOutputWriter.java	Fri Apr 18 08:44:53 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -65,7 +65,7 @@
     public FrameOutputWriter(ConfigurationImpl configuration,
                              DocPath filename) throws IOException {
         super(configuration, filename);
-        noOfPackages = configuration.packages.length;
+        noOfPackages = configuration.packages.size();
     }
 
     /**
--- a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDoclet.java	Fri Apr 18 08:35:59 2014 -0700
+++ b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDoclet.java	Fri Apr 18 08:44:53 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -215,22 +215,22 @@
                 if (!configuration.shouldDocumentProfile(profileName))
                     continue;
                 ProfilePackageIndexFrameWriter.generate(configuration, profileName);
-                PackageDoc[] packages = configuration.profilePackages.get(
+                List<PackageDoc> packages = configuration.profilePackages.get(
                         profileName);
                 PackageDoc prev = null, next;
-                for (int j = 0; j < packages.length; j++) {
+                for (int j = 0; j < packages.size(); j++) {
                     // if -nodeprecated option is set and the package is marked as
                     // deprecated, do not generate the profilename-package-summary.html
                     // and profilename-package-frame.html pages for that package.
-                    if (!(configuration.nodeprecated && Util.isDeprecated(packages[j]))) {
-                        ProfilePackageFrameWriter.generate(configuration, packages[j], i);
-                        next = (j + 1 < packages.length
-                                && packages[j + 1].name().length() > 0) ? packages[j + 1] : null;
+                    PackageDoc pkg = packages.get(j);
+                    if (!(configuration.nodeprecated && Util.isDeprecated(pkg))) {
+                        ProfilePackageFrameWriter.generate(configuration, pkg, i);
+                        next = getNamedPackage(packages, j + 1);
                         AbstractBuilder profilePackageSummaryBuilder =
                                 configuration.getBuilderFactory().getProfilePackageSummaryBuilder(
-                                packages[j], prev, next, Profile.lookup(i));
+                                pkg, prev, next, Profile.lookup(i));
                         profilePackageSummaryBuilder.build();
-                        prev = packages[j];
+                        prev = pkg;
                     }
                 }
                 nextProfile = (i + 1 < configuration.profiles.getProfileCount()) ?
@@ -244,35 +244,47 @@
         }
     }
 
+    PackageDoc getNamedPackage(List<PackageDoc> list, int idx) {
+        if (idx < list.size()) {
+            PackageDoc pkg = list.get(idx);
+            if (!pkg.name().isEmpty()) {
+                return pkg;
+            }
+        }
+        return null;
+    }
+
     /**
      * {@inheritDoc}
      */
     protected void generatePackageFiles(ClassTree classtree) throws Exception {
-        PackageDoc[] packages = configuration.packages;
-        if (packages.length > 1) {
+        Set<PackageDoc> packages = configuration.packages;
+        if (packages.size() > 1) {
             PackageIndexFrameWriter.generate(configuration);
         }
+        List<PackageDoc> pList = new ArrayList<>(configuration.packages);
         PackageDoc prev = null, next;
-        for (int i = 0; i < packages.length; i++) {
+        for (int i = 0; i < pList.size(); i++) {
             // if -nodeprecated option is set and the package is marked as
             // deprecated, do not generate the package-summary.html, package-frame.html
             // and package-tree.html pages for that package.
-            if (!(configuration.nodeprecated && Util.isDeprecated(packages[i]))) {
-                PackageFrameWriter.generate(configuration, packages[i]);
-                next = (i + 1 < packages.length &&
-                        packages[i + 1].name().length() > 0) ? packages[i + 1] : null;
+            PackageDoc pkg = pList.get(i);
+            if (!(configuration.nodeprecated && Util.isDeprecated(pkg))) {
+                PackageFrameWriter.generate(configuration, pkg);
+                next = getNamedPackage(pList, i + 1);
                 //If the next package is unnamed package, skip 2 ahead if possible
-                next = (i + 2 < packages.length && next == null) ? packages[i + 2] : next;
+                if (next == null)
+                    next = getNamedPackage(pList, i + 2);
                 AbstractBuilder packageSummaryBuilder =
                         configuration.getBuilderFactory().getPackageSummaryBuilder(
-                        packages[i], prev, next);
+                        pkg, prev, next);
                 packageSummaryBuilder.build();
                 if (configuration.createtree) {
                     PackageTreeWriter.generate(configuration,
-                            packages[i], prev, next,
+                            pkg, prev, next,
                             configuration.nodeprecated);
                 }
-                prev = packages[i];
+                prev = pkg;
             }
         }
     }
--- a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java	Fri Apr 18 08:35:59 2014 -0700
+++ b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java	Fri Apr 18 08:44:53 2014 -0700
@@ -524,9 +524,9 @@
             if (configuration.createoverview) {
                 navList.addContent(getNavLinkContents());
             }
-            if (configuration.packages.length == 1) {
-                navList.addContent(getNavLinkPackage(configuration.packages[0]));
-            } else if (configuration.packages.length > 1) {
+            if (configuration.packages.size() == 1) {
+                navList.addContent(getNavLinkPackage(configuration.packages.first()));
+            } else if (configuration.packages.size() > 1) {
                 navList.addContent(getNavLinkPackage());
             }
             navList.addContent(getNavLinkClass());
@@ -916,7 +916,7 @@
      * @return package name content
      */
     public Content getPackageName(PackageDoc packageDoc) {
-        return packageDoc == null || packageDoc.name().length() == 0 ?
+        return packageDoc == null || packageDoc.name().isEmpty() ?
             defaultPackageLabel :
             getPackageLabel(packageDoc.name());
     }
--- a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/PackageIndexFrameWriter.java	Fri Apr 18 08:35:59 2014 -0700
+++ b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/PackageIndexFrameWriter.java	Fri Apr 18 08:44:53 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,7 +25,8 @@
 
 package com.sun.tools.doclets.formats.html;
 
-import java.io.*;
+import java.io.IOException;
+import java.util.Collection;
 
 import com.sun.javadoc.*;
 import com.sun.tools.doclets.formats.html.markup.*;
@@ -78,7 +79,7 @@
     /**
      * {@inheritDoc}
      */
-    protected void addPackagesList(PackageDoc[] packages, String text,
+    protected void addPackagesList(Collection<PackageDoc> packages, String text,
             String tableSummary, Content body) {
         Content heading = HtmlTree.HEADING(HtmlConstants.PACKAGE_HEADING, true,
                 packagesLabel);
@@ -106,7 +107,7 @@
     protected Content getPackage(PackageDoc pd) {
         Content packageLinkContent;
         Content packageLabel;
-        if (pd.name().length() > 0) {
+        if (!pd.name().isEmpty()) {
             packageLabel = getPackageLabel(pd.name());
             packageLinkContent = getHyperLink(pathString(pd,
                      DocPaths.PACKAGE_FRAME), packageLabel, "",
--- a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/PackageIndexWriter.java	Fri Apr 18 08:35:59 2014 -0700
+++ b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/PackageIndexWriter.java	Fri Apr 18 08:44:53 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -111,8 +111,8 @@
     protected void addIndex(Content body) {
         for (String groupname : groupList) {
             List<PackageDoc> list = groupPackageMap.get(groupname);
-            if (list != null && list.size() > 0) {
-                addIndexContents(list.toArray(new PackageDoc[list.size()]),
+            if (list != null && !list.isEmpty()) {
+                addIndexContents(list,
                                  groupname, configuration.getText("doclet.Member_Table_Summary",
                                                                   groupname, configuration.getText("doclet.packages")), body);
             }
@@ -146,7 +146,7 @@
     /**
      * {@inheritDoc}
      */
-    protected void addPackagesList(PackageDoc[] packages, String text,
+    protected void addPackagesList(Collection<PackageDoc> packages, String text,
             String tableSummary, Content body) {
         Content table = HtmlTree.TABLE(HtmlStyle.overviewSummary, 0, 3, 0, tableSummary,
                 getTableCaption(new RawHtml(text)));
@@ -164,25 +164,23 @@
      * @param packages Packages to which link is to be generated
      * @param tbody the documentation tree to which the list will be added
      */
-    protected void addPackagesList(PackageDoc[] packages, Content tbody) {
-        for (int i = 0; i < packages.length; i++) {
-            if (packages[i] != null && packages[i].name().length() > 0) {
-                if (configuration.nodeprecated && Util.isDeprecated(packages[i]))
-                    continue;
-                Content packageLinkContent = getPackageLink(packages[i],
-                        getPackageName(packages[i]));
-                Content tdPackage = HtmlTree.TD(HtmlStyle.colFirst, packageLinkContent);
-                HtmlTree tdSummary = new HtmlTree(HtmlTag.TD);
-                tdSummary.addStyle(HtmlStyle.colLast);
-                addSummaryComment(packages[i], tdSummary);
-                HtmlTree tr = HtmlTree.TR(tdPackage);
-                tr.addContent(tdSummary);
-                if (i%2 == 0)
-                    tr.addStyle(HtmlStyle.altColor);
-                else
-                    tr.addStyle(HtmlStyle.rowColor);
-                tbody.addContent(tr);
+    protected void addPackagesList(Collection<PackageDoc> packages, Content tbody) {
+        boolean altColor = true;
+        for (PackageDoc pkg : packages) {
+            if (pkg != null && !pkg.name().isEmpty()) {
+                if (!(configuration.nodeprecated && Util.isDeprecated(pkg))) {
+                    Content packageLinkContent = getPackageLink(pkg, getPackageName(pkg));
+                    Content tdPackage = HtmlTree.TD(HtmlStyle.colFirst, packageLinkContent);
+                    HtmlTree tdSummary = new HtmlTree(HtmlTag.TD);
+                    tdSummary.addStyle(HtmlStyle.colLast);
+                    addSummaryComment(pkg, tdSummary);
+                    HtmlTree tr = HtmlTree.TR(tdPackage);
+                    tr.addContent(tdSummary);
+                    tr.addStyle(altColor ? HtmlStyle.altColor : HtmlStyle.rowColor);
+                    tbody.addContent(tr);
+                }
             }
+            altColor = !altColor;
         }
     }
 
--- a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/PackageTreeWriter.java	Fri Apr 18 08:35:59 2014 -0700
+++ b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/PackageTreeWriter.java	Fri Apr 18 08:44:53 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -119,7 +119,7 @@
         Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, false,
                 HtmlStyle.title, headContent);
         Content div = HtmlTree.DIV(HtmlStyle.header, heading);
-        if (configuration.packages.length > 1) {
+        if (configuration.packages.size() > 1) {
             addLinkToMainTree(div);
         }
         body.addContent(div);
--- a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/PackageUseWriter.java	Fri Apr 18 08:35:59 2014 -0700
+++ b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/PackageUseWriter.java	Fri Apr 18 08:44:53 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -135,7 +135,7 @@
     protected void addPackageUse(Content contentTree) throws IOException {
         HtmlTree ul = new HtmlTree(HtmlTag.UL);
         ul.addStyle(HtmlStyle.blockList);
-        if (configuration.packages.length > 1) {
+        if (configuration.packages.size() > 1) {
             addPackageList(ul);
         }
         addClassList(ul);
--- a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/ProfilePackageIndexFrameWriter.java	Fri Apr 18 08:35:59 2014 -0700
+++ b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/ProfilePackageIndexFrameWriter.java	Fri Apr 18 08:44:53 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,7 +25,8 @@
 
 package com.sun.tools.doclets.formats.html;
 
-import java.io.*;
+import java.io.IOException;
+import java.util.List;
 
 import com.sun.javadoc.*;
 import com.sun.tools.javac.sym.Profiles;
@@ -92,7 +93,7 @@
         Content div = HtmlTree.DIV(HtmlStyle.indexContainer, heading);
         HtmlTree ul = new HtmlTree(HtmlTag.UL);
         ul.setTitle(packagesLabel);
-        PackageDoc[] packages = configuration.profilePackages.get(profileName);
+        List<PackageDoc> packages = configuration.profilePackages.get(profileName);
         for (PackageDoc packageDoc : packages) {
             if ((!(configuration.nodeprecated && Util.isDeprecated(packageDoc)))) {
                 ul.addContent(getPackage(packageDoc, profileName));
--- a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/TreeWriter.java	Fri Apr 18 08:35:59 2014 -0700
+++ b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/TreeWriter.java	Fri Apr 18 08:44:53 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,7 +25,8 @@
 
 package com.sun.tools.doclets.formats.html;
 
-import java.io.*;
+import java.io.IOException;
+import java.util.SortedSet;
 
 import com.sun.javadoc.*;
 import com.sun.tools.doclets.formats.html.markup.*;
@@ -51,7 +52,7 @@
     /**
      * Packages in this run.
      */
-    private PackageDoc[] packages;
+    SortedSet<PackageDoc> packages;
 
     /**
      * True if there are no packages specified on the command line,
@@ -67,11 +68,10 @@
      * @param classtree the tree being built.
      */
     public TreeWriter(ConfigurationImpl configuration,
-            DocPath filename, ClassTree classtree)
-    throws IOException {
+            DocPath filename, ClassTree classtree) throws IOException {
         super(configuration, filename, classtree);
         packages = configuration.packages;
-    classesonly = packages.length == 0;
+        classesonly = packages.isEmpty();
     }
 
     /**
@@ -127,7 +127,7 @@
      */
     protected void addPackageTreeLinks(Content contentTree) {
         //Do nothing if only unnamed package is used
-        if (packages.length == 1 && packages[0].name().length() == 0) {
+        if (isUnnamedPackage()) {
             return;
         }
         if (!classesonly) {
@@ -136,21 +136,24 @@
             contentTree.addContent(span);
             HtmlTree ul = new HtmlTree(HtmlTag.UL);
             ul.addStyle(HtmlStyle.horizontal);
-            for (int i = 0; i < packages.length; i++) {
+            int i = 0;
+            for (PackageDoc pkg : packages) {
                 // If the package name length is 0 or if -nodeprecated option
                 // is set and the package is marked as deprecated, do not include
                 // the page in the list of package hierarchies.
-                if (packages[i].name().length() == 0 ||
-                        (configuration.nodeprecated && Util.isDeprecated(packages[i]))) {
+                if (pkg.name().isEmpty() ||
+                        (configuration.nodeprecated && Util.isDeprecated(pkg))) {
+                    i++;
                     continue;
                 }
-                DocPath link = pathString(packages[i], DocPaths.PACKAGE_TREE);
+                DocPath link = pathString(pkg, DocPaths.PACKAGE_TREE);
                 Content li = HtmlTree.LI(getHyperLink(
-                        link, new StringContent(packages[i].name())));
-                if (i < packages.length - 1) {
+                        link, new StringContent(pkg.name())));
+                if (i < packages.size() - 1) {
                     li.addContent(", ");
                 }
                 ul.addContent(li);
+                i++;
             }
             contentTree.addContent(ul);
         }
@@ -168,4 +171,8 @@
         addNavLinks(true, bodyTree);
         return bodyTree;
     }
+
+    private boolean isUnnamedPackage() {
+        return packages.size() == 1 && packages.first().name().isEmpty();
+    }
 }
--- a/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/Configuration.java	Fri Apr 18 08:35:59 2014 -0700
+++ b/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/Configuration.java	Fri Apr 18 08:44:53 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -289,16 +289,16 @@
     public Profiles profiles;
 
     /**
-     * An map of the profiles to packages.
+     * A map of the profiles to packages.
      */
-    public Map<String,PackageDoc[]> profilePackages;
+    public Map<String, List<PackageDoc>> profilePackages;
 
     /**
-     * An array of the packages specified on the command-line merged
-     * with the array of packages that contain the classes specified on the
-     * command-line.  The array is sorted.
+     * A sorted set of packages specified on the command-line merged with a
+     * collection of packages that contain the classes specified on the
+     * command-line.
      */
-    public PackageDoc[] packages;
+    public SortedSet<PackageDoc> packages;
 
     /**
      * Constructor. Constructs the message retriever with resource file.
@@ -423,7 +423,7 @@
             // For a profile, if there are no packages to be documented, do not add
             // it to profilePackages map.
             if (size > 0)
-                profilePackages.put(p.name, pkgs.toArray(new PackageDoc[pkgs.size()]));
+                profilePackages.put(p.name, pkgs);
             prev = pkgs;
         }
 
@@ -432,14 +432,11 @@
         showProfiles = !prev.isEmpty();
     }
 
-    private void initPackageArray() {
-        Set<PackageDoc> set = new HashSet<>(Arrays.asList(root.specifiedPackages()));
+    private void initPackages() {
+        packages = new TreeSet<>(Arrays.asList(root.specifiedPackages()));
         for (ClassDoc aClass : root.specifiedClasses()) {
-            set.add(aClass.containingPackage());
+            packages.add(aClass.containingPackage());
         }
-        ArrayList<PackageDoc> results = new ArrayList<>(set);
-        Collections.sort(results);
-        packages = results.toArray(new PackageDoc[] {});
     }
 
     /**
@@ -547,7 +544,7 @@
      * @throws DocletAbortException
      */
     public void setOptions() throws Fault {
-        initPackageArray();
+        initPackages();
         setOptions(root.options());
         try {
             initProfiles();
--- a/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/builders/AbstractBuilder.java	Fri Apr 18 08:35:59 2014 -0700
+++ b/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/builders/AbstractBuilder.java	Fri Apr 18 08:44:53 2014 -0700
@@ -29,6 +29,7 @@
 import java.lang.reflect.*;
 import java.util.*;
 
+import com.sun.javadoc.PackageDoc;
 import com.sun.tools.doclets.internal.toolkit.*;
 import com.sun.tools.doclets.internal.toolkit.util.*;
 
@@ -63,7 +64,7 @@
          * efficiency purposes.  We don't want to copy the
          * doc files multiple times for a single package.
          */
-        final Set<String> containingPackagesSeen;
+        final Set<PackageDoc> containingPackagesSeen;
 
         /**
          * Shared parser for the builder XML file
@@ -71,7 +72,7 @@
         final LayoutParser layoutParser;
 
         Context(Configuration configuration,
-                Set<String> containingPackagesSeen,
+                Set<PackageDoc> containingPackagesSeen,
                 LayoutParser layoutParser) {
             this.configuration = configuration;
             this.containingPackagesSeen = containingPackagesSeen;
@@ -89,7 +90,7 @@
      * efficiency purposes.  We don't want to copy the
      * doc files multiple times for a single package.
      */
-    protected final Set<String> containingPackagesSeen;
+    protected final Set<PackageDoc> containingPackagesSeen;
 
     protected final LayoutParser layoutParser;
 
--- a/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/builders/AnnotationTypeBuilder.java	Fri Apr 18 08:35:59 2014 -0700
+++ b/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/builders/AnnotationTypeBuilder.java	Fri Apr 18 08:44:53 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -133,14 +133,13 @@
      private void copyDocFiles() {
         PackageDoc containingPackage = annotationTypeDoc.containingPackage();
         if((configuration.packages == null ||
-                Arrays.binarySearch(configuration.packages,
-                                    containingPackage) < 0) &&
-           ! containingPackagesSeen.contains(containingPackage.name())){
+            !configuration.packages.contains(containingPackage) &&
+            !containingPackagesSeen.contains(containingPackage))){
             //Only copy doc files dir if the containing package is not
             //documented AND if we have not documented a class from the same
             //package already. Otherwise, we are making duplicate copies.
             Util.copyDocFiles(configuration, containingPackage);
-            containingPackagesSeen.add(containingPackage.name());
+            containingPackagesSeen.add(containingPackage);
         }
      }
 
--- a/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/builders/BuilderFactory.java	Fri Apr 18 08:35:59 2014 -0700
+++ b/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/builders/BuilderFactory.java	Fri Apr 18 08:44:53 2014 -0700
@@ -68,7 +68,7 @@
         this.configuration = configuration;
         this.writerFactory = configuration.getWriterFactory();
 
-        Set<String> containingPackagesSeen = new HashSet<>();
+        Set<PackageDoc> containingPackagesSeen = new HashSet<>();
         context = new AbstractBuilder.Context(configuration, containingPackagesSeen,
                 LayoutParser.getInstance(configuration));
     }
--- a/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/builders/ClassBuilder.java	Fri Apr 18 08:35:59 2014 -0700
+++ b/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/builders/ClassBuilder.java	Fri Apr 18 08:44:53 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -271,14 +271,13 @@
      private void copyDocFiles() {
         PackageDoc containingPackage = classDoc.containingPackage();
         if((configuration.packages == null ||
-                Arrays.binarySearch(configuration.packages,
-                containingPackage) < 0) &&
-                ! containingPackagesSeen.contains(containingPackage.name())){
+            !configuration.packages.contains(containingPackage)) &&
+            ! containingPackagesSeen.contains(containingPackage)){
             //Only copy doc files dir if the containing package is not
             //documented AND if we have not documented a class from the same
             //package already. Otherwise, we are making duplicate copies.
             Util.copyDocFiles(configuration, containingPackage);
-            containingPackagesSeen.add(containingPackage.name());
+            containingPackagesSeen.add(containingPackage);
         }
      }
 
--- a/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/builders/ProfileSummaryBuilder.java	Fri Apr 18 08:35:59 2014 -0700
+++ b/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/builders/ProfileSummaryBuilder.java	Fri Apr 18 08:44:53 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,7 +25,8 @@
 
 package com.sun.tools.doclets.internal.toolkit.builders;
 
-import java.io.*;
+import java.io.IOException;
+import java.util.List;
 
 import com.sun.javadoc.*;
 import com.sun.tools.javac.jvm.Profile;
@@ -165,7 +166,7 @@
      *                           be added
      */
     public void buildPackageSummary(XMLNode node, Content summaryContentTree) {
-        PackageDoc[] packages = configuration.profilePackages.get(profile.name);
+        List<PackageDoc> packages = configuration.profilePackages.get(profile.name);
         for (PackageDoc aPackage : packages) {
             this.pkg = aPackage;
             Content packageSummaryContentTree = profileWriter.getPackageSummaryHeader(this.pkg);
--- a/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/DeprecatedAPIListBuilder.java	Fri Apr 18 08:35:59 2014 -0700
+++ b/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/DeprecatedAPIListBuilder.java	Fri Apr 18 08:44:53 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -84,7 +84,7 @@
      * @param configuration the current configuration of the doclet.
      */
     private void buildDeprecatedAPIInfo(Configuration configuration) {
-        PackageDoc[] packages = configuration.packages;
+        Set<PackageDoc> packages = configuration.packages;
         for (PackageDoc pkg : packages) {
             if (Util.isDeprecated(pkg)) {
                 getList(PACKAGE).add(pkg);
--- a/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/Group.java	Fri Apr 18 08:35:59 2014 -0700
+++ b/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/Group.java	Fri Apr 18 08:44:53 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -175,7 +175,7 @@
      *
      * @param packages Packages specified on the command line.
      */
-    public Map<String,List<PackageDoc>> groupPackages(PackageDoc[] packages) {
+    public Map<String, List<PackageDoc>> groupPackages(Set<PackageDoc> packages) {
         Map<String,List<PackageDoc>> groupPackageMap = new HashMap<>();
         String defaultGroupName =
             (pkgNameGroupMap.isEmpty() && regExpGroupMap.isEmpty())?