Chain the three comparators.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 8 Aug 2013 00:09:30 +0000 (02:09 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 8 Aug 2013 00:16:17 +0000 (02:16 +0200)
src/main/java/net/pterodactylus/xdcc/ui/stdin/CommandReader.java

index 7b6e64f..9cd2a12 100644 (file)
@@ -43,6 +43,7 @@ import net.pterodactylus.xdcc.data.Download;
 import net.pterodactylus.xdcc.data.Pack;
 
 import com.google.common.base.Predicate;
+import com.google.common.collect.ComparisonChain;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Sets;
 import com.google.common.eventbus.Subscribe;
@@ -439,14 +440,10 @@ public class CommandReader extends AbstractExecutionThreadService {
 
                @Override
                public int compareTo(Result result) {
-                       if (isArchive.apply(this) && !isArchive.apply(result)) {
-                               return 1;
-                       }
-                       if (!isArchive.apply(this) && isArchive.apply(result)) {
-                               return -1;
-                       }
-                       /* sort by bot name. */
-                       return botNameComparator.compare(bot().name(), result.bot().name());
+                       return ComparisonChain.start()
+                                       .compare(this, result, packArchiveComparator)
+                                       .compare(this, result, botNameComparator)
+                                       .compare(this, result, packNameComparator).result();
                }
 
        }