Add comparators for sorting downloads.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 8 Aug 2013 00:19:05 +0000 (02:19 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 8 Aug 2013 00:19:05 +0000 (02:19 +0200)
src/main/java/net/pterodactylus/xdcc/data/Download.java

index 12b0129..560e7f9 100644 (file)
@@ -21,6 +21,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
 
 import java.io.OutputStream;
 import java.net.InetAddress;
+import java.util.Comparator;
 import java.util.concurrent.atomic.AtomicLong;
 import java.util.concurrent.atomic.AtomicReference;
 
@@ -44,6 +45,24 @@ public class Download {
                }
        };
 
+       /** {@link Comparator} that sorts downloads by their name. */
+       public static final Comparator<Download> BY_NAME = new Comparator<Download>() {
+
+               @Override
+               public int compare(Download leftDownload, Download rightDownload) {
+                       return leftDownload.pack().name().compareToIgnoreCase(rightDownload.pack().name());
+               }
+       };
+
+       /**  {@link Comparator} that sorts running downloads first. */
+       public static final Comparator<Download> BY_RUNNING = new Comparator<Download>() {
+
+               @Override
+               public int compare(Download leftDownload, Download rightDownload) {
+                       return (leftDownload.dccReceiver() != null) ? -1 : (rightDownload.dccReceiver() != null) ? 1 : 0;
+               }
+       };
+
        /** The bot that is being downloaded from. */
        private final Bot bot;