Add comparator that uses the “isArchive” predicate.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 8 Aug 2013 00:07:41 +0000 (02:07 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 8 Aug 2013 00:15:59 +0000 (02:15 +0200)
src/main/java/net/pterodactylus/xdcc/ui/stdin/CommandReader.java

index 95425d0..abef80e 100644 (file)
@@ -330,6 +330,23 @@ public class CommandReader extends AbstractExecutionThreadService {
                };
 
                /**
+                * {@link Comparator} for {@link Result}s that sorts archives (as per {@link
+                * #isArchive} to the back of the list.
+                */
+               private static final Comparator<Result> packArchiveComparator = new Comparator<Result>() {
+                       @Override
+                       public int compare(Result leftResult, Result rightResult) {
+                               if (isArchive.apply(leftResult) && !isArchive.apply(rightResult)) {
+                                       return 1;
+                               }
+                               if (!isArchive.apply(leftResult) && isArchive.apply(rightResult)) {
+                                       return -1;
+                               }
+                               return 0;
+                       }
+               };
+
+               /**
                 * {@link Comparator} for bot nicknames. It comprises different strategies:
                 * one name pattern is preferred (and thus listed first), one pattern is
                 * disliked (and thus listed last), the rest is sorted alphabetically.