Override hashCode() and equals().
[xudocci.git] / src / main / java / net / pterodactylus / xdcc / data / Bot.java
index 724f0e0..96d91b6 100644 (file)
@@ -17,6 +17,8 @@
 
 package net.pterodactylus.xdcc.data;
 
+import static com.google.common.base.Preconditions.checkNotNull;
+
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.Map;
@@ -45,9 +47,12 @@ public class Bot implements Iterable<Pack> {
         *
         * @param network
         *              The network the bot is on
+        * @param name
+        *              The name of the bot
         */
-       public Bot(Network network) {
-               this.network = network;
+       public Bot(Network network, String name) {
+               this.network = checkNotNull(network, "network must not be null");
+               this.name = checkNotNull(name, "name must not be null");
        }
 
        //
@@ -93,7 +98,7 @@ public class Bot implements Iterable<Pack> {
         * @return This bot
         */
        public Bot name(String name) {
-               this.name = name;
+               this.name = checkNotNull(name, "name must not be null");
                return this;
        }
 
@@ -125,6 +130,20 @@ public class Bot implements Iterable<Pack> {
        //
 
        @Override
+       public boolean equals(Object object) {
+               if (!(object instanceof Bot)) {
+                       return false;
+               }
+               Bot bot = (Bot) object;
+               return network().equals(bot.network()) && name().equals(bot.name());
+       }
+
+       @Override
+       public int hashCode() {
+               return network().hashCode() ^ name().hashCode();
+       }
+
+       @Override
        public String toString() {
                return String.format("%s/%s", name(), network().name());
        }