Add predicate that identifies running downloads.
[xudocci.git] / src / main / java / net / pterodactylus / xdcc / data / Download.java
index 5190ed0..926adad 100644 (file)
 
 package net.pterodactylus.xdcc.data;
 
+import static com.google.common.base.Preconditions.checkNotNull;
+
 import java.io.OutputStream;
 import java.net.InetAddress;
 
 import net.pterodactylus.irc.DccReceiver;
 
+import com.google.common.base.Predicate;
+
 /**
  * Information about an ongoing download.
  *
@@ -29,6 +33,15 @@ import net.pterodactylus.irc.DccReceiver;
  */
 public class Download {
 
+       /** Predicate that identifies downloads that have started. */
+       public static final Predicate<Download> FILTER_RUNNING = new Predicate<Download>() {
+
+               @Override
+               public boolean apply(Download download) {
+                       return download.dccReceiver() != null;
+               }
+       };
+
        /** The bot that is being downloaded from. */
        private final Bot bot;
 
@@ -59,8 +72,8 @@ public class Download {
         *              The pack being downloaded
         */
        public Download(Bot bot, Pack pack) {
-               this.bot = bot;
-               this.pack = pack;
+               this.bot = checkNotNull(bot, "bot must not be null");
+               this.pack = checkNotNull(pack, "pack must not be null");
        }
 
        //
@@ -194,4 +207,22 @@ public class Download {
                return this;
        }
 
+       //
+       // OBJECT METHODS
+       //
+
+       @Override
+       public boolean equals(Object object) {
+               if (!(object instanceof Download)) {
+                       return false;
+               }
+               Download download = (Download) object;
+               return bot().equals(download.bot()) && pack().equals(download.pack());
+       }
+
+       @Override
+       public int hashCode() {
+               return bot().hashCode() ^ pack().hashCode();
+       }
+
 }