8210683: Search result display order reversed for overloaded entries
authorhannesw
Tue, 16 Oct 2018 15:05:03 +0200
changeset 52144 f53671e05660
parent 52143 ad6384355aa3
child 52146 032c1c1379ab
8210683: Search result display order reversed for overloaded entries Reviewed-by: jjg
src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/Utils.java
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/Utils.java	Tue Oct 16 14:17:19 2018 +0200
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/Utils.java	Tue Oct 16 15:05:03 2018 +0200
@@ -30,6 +30,8 @@
 import java.net.URI;
 import java.text.CollationKey;
 import java.text.Collator;
+import java.text.ParseException;
+import java.text.RuleBasedCollator;
 import java.util.*;
 import java.util.AbstractMap.SimpleEntry;
 import java.util.Map.Entry;
@@ -1588,7 +1590,7 @@
         private final Collator instance;
         private final int MAX_SIZE = 1000;
         private DocCollator(Locale locale, int strength) {
-            instance = Collator.getInstance(locale);
+            instance = createCollator(locale);
             instance.setStrength(strength);
 
             keys = new LinkedHashMap<String, CollationKey>(MAX_SIZE + 1, 0.75f, true) {
@@ -1607,6 +1609,21 @@
         public int compare(String s1, String s2) {
             return getKey(s1).compareTo(getKey(s2));
         }
+
+        private Collator createCollator(Locale locale) {
+            Collator baseCollator = Collator.getInstance(locale);
+            if (baseCollator instanceof RuleBasedCollator) {
+                // Extend collator to sort signatures with additional args and var-args in a well-defined order:
+                // () < (int) < (int, int) < (int...)
+                try {
+                    return new RuleBasedCollator(((RuleBasedCollator) baseCollator).getRules()
+                            + "& ')' < ',' < '.','['");
+                } catch (ParseException e) {
+                    throw new RuntimeException(e);
+                }
+            }
+            return baseCollator;
+        }
     }
 
     private Comparator<Element> moduleComparator = null;