From: David ‘Bombe’ Roden Date: Thu, 8 Aug 2013 00:19:05 +0000 (+0200) Subject: Add comparators for sorting downloads. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=e23a2a9e59408fce266a6cac4b11cb5b311881e1;p=xudocci.git Add comparators for sorting downloads. --- diff --git a/src/main/java/net/pterodactylus/xdcc/data/Download.java b/src/main/java/net/pterodactylus/xdcc/data/Download.java index 12b0129..560e7f9 100644 --- a/src/main/java/net/pterodactylus/xdcc/data/Download.java +++ b/src/main/java/net/pterodactylus/xdcc/data/Download.java @@ -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 BY_NAME = new Comparator() { + + @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 BY_RUNNING = new Comparator() { + + @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;