Sort repacks to the front.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 21 Jan 2014 07:05:19 +0000 (08:05 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 21 Jan 2014 07:05:19 +0000 (08:05 +0100)
src/main/java/net/pterodactylus/xdcc/ui/stdin/Result.java

index 0107c6c..f7f0523 100644 (file)
@@ -85,16 +85,20 @@ public class Result implements Comparable<Result> {
                return preferredComparator(matches("[-|]P[-|]").negate(), (result) -> result.bot().name());
        }
 
-       /**
-        * {@link Comparator} for {@link Result}s that sorts them by the name of the
-        * {@link Pack}.
-        */
-       private static final Comparator<Result> packNameComparator = new Comparator<Result>() {
-               @Override
-               public int compare(Result leftResult, Result rightResult) {
-                       return leftResult.pack().name().compareToIgnoreCase(rightResult.pack().name());
-               }
-       };
+       private static final Comparator<Result> packNameComparator = sortRepacksFirst().thenComparing(sortPacksAlphabetically());
+
+       private static Comparator<Result> sortRepacksFirst() {
+               return preferredComparator(matches("\\.(PROPER|REPACK)\\."), (result) -> result.pack().name());
+       }
+
+       private static Comparator<Result> sortPacksAlphabetically() {
+               return new Comparator<Result>() {
+                       @Override
+                       public int compare(Result leftResult, Result rightResult) {
+                               return leftResult.pack().name().compareToIgnoreCase(rightResult.pack().name());
+                       }
+               };
+       }
 
        /** Comparator that sorts bots with running downloads to the back of the list. */
        private final Comparator<Result> botsWithRunningTransfersComparator = new Comparator<Result>() {