Override hashCode() and equals().
[xudocci.git] / src / main / java / net / pterodactylus / xdcc / data / Download.java
index 5190ed0..0592eaf 100644 (file)
@@ -17,6 +17,8 @@
 
 package net.pterodactylus.xdcc.data;
 
+import static com.google.common.base.Preconditions.checkNotNull;
+
 import java.io.OutputStream;
 import java.net.InetAddress;
 
@@ -59,8 +61,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 +196,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();
+       }
+
 }