Override hashCode() and equals().
[xudocci.git] / src / main / java / net / pterodactylus / xdcc / data / Download.java
index 2d95537..0592eaf 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;
 
@@ -37,6 +40,12 @@ public class Download {
        /** The name of the file being downloaded. */
        private String filename;
 
+       /** The size of the file being downloaded. */
+       private long filesize;
+
+       /** The remote address. */
+       private InetAddress remoteAddress;
+
        /** The output stream. */
        private OutputStream outputStream;
 
@@ -52,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");
        }
 
        //
@@ -88,6 +97,24 @@ public class Download {
        }
 
        /**
+        * Returns the size of the file.
+        *
+        * @return The size of the file
+        */
+       public long filesize() {
+               return filesize;
+       }
+
+       /**
+        * Returns the remote address to download from.
+        *
+        * @return The remote address to download from
+        */
+       public InetAddress remoteAddress() {
+               return remoteAddress;
+       }
+
+       /**
         * The output stream that writes to the file.
         *
         * @return The output stream
@@ -122,6 +149,30 @@ public class Download {
        }
 
        /**
+        * Sets the size of the download.
+        *
+        * @param filesize
+        *              The size of the download
+        * @return This download
+        */
+       public Download filesize(long filesize) {
+               this.filesize = filesize;
+               return this;
+       }
+
+       /**
+        * Sets the remote address of the download.
+        *
+        * @param remoteAddress
+        *              The remote address of the download
+        * @return This download
+        */
+       public Download remoteAddress(InetAddress remoteAddress) {
+               this.remoteAddress = remoteAddress;
+               return this;
+       }
+
+       /**
         * Sets the output stream the download is being written to
         *
         * @param outputStream
@@ -145,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();
+       }
+
 }