Browse Source

Use an explicit comparator to sort plugins.

PluginInfo randomly implements Comparable and compares itself
by name, which I want to kill.
pull/298/head
Chris Smith 9 years ago
parent
commit
59b9e10f9b

+ 15
- 2
ui_swing/src/com/dmdirc/addons/ui_swing/components/addonpanel/PluginPanel.java View File

@@ -38,6 +38,7 @@ import java.awt.Window;
38 38
 import java.util.ArrayList;
39 39
 import java.util.Collection;
40 40
 import java.util.Collections;
41
+import java.util.Comparator;
41 42
 import java.util.List;
42 43
 
43 44
 import javax.inject.Inject;
@@ -53,6 +54,10 @@ public class PluginPanel extends AddonPanel {
53 54
 
54 55
     /** A version number for this class. */
55 56
     private static final long serialVersionUID = 1;
57
+
58
+    /** Comparator to use to sort plugins in the panel. */
59
+    private static final Comparator<? super PluginInfo> COMPARATOR = new PluginInfoComparator();
60
+
56 61
     /** Manager to retrieve plugin information from. */
57 62
     private final PluginManager pluginManager;
58 63
     /** Manager to use to retrieve addon-related icons. */
@@ -97,14 +102,14 @@ public class PluginPanel extends AddonPanel {
97 102
         final List<PluginInfo> list = new ArrayList<>();
98 103
         final Collection<PluginInfo> sortedList = new ArrayList<>();
99 104
         list.addAll(pluginManager.getPluginInfos());
100
-        Collections.sort(list);
105
+        Collections.sort(list, COMPARATOR);
101 106
         list.stream().filter(plugin -> plugin.getMetaData().getParent() == null).forEach(plugin -> {
102 107
             final List<PluginInfo> childList = new ArrayList<>();
103 108
             sortedList.add(plugin);
104 109
             plugin.getChildren().stream()
105 110
                     .filter(child -> !childList.contains(child))
106 111
                     .forEach(childList::add);
107
-            Collections.sort(childList);
112
+            Collections.sort(childList, COMPARATOR);
108 113
             sortedList.addAll(childList);
109 114
         });
110 115
 
@@ -136,4 +141,12 @@ public class PluginPanel extends AddonPanel {
136 141
         return "plugins";
137 142
     }
138 143
 
144
+    private static class PluginInfoComparator implements Comparator<PluginInfo> {
145
+
146
+        @Override
147
+        public int compare(final PluginInfo o1, final PluginInfo o2) {
148
+            return o1.getMetaData().getName().compareTo(o2.getMetaData().getName());
149
+        }
150
+    }
151
+
139 152
 }

Loading…
Cancel
Save