Override hashCode() and equals().
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 24 Nov 2011 08:14:12 +0000 (09:14 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 24 Nov 2011 08:14:12 +0000 (09:14 +0100)
src/main/java/net/pterodactylus/sone/notify/ListNotification.java

index 74e3100..7216c42 100644 (file)
@@ -161,4 +161,43 @@ public class ListNotification<T> extends TemplateNotification {
                elements.clear();
        }
 
+       //
+       // OBJECT METHODS
+       //
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       public int hashCode() {
+               int hashCode = key.hashCode();
+               for (T element : elements) {
+                       hashCode ^= element.hashCode();
+               }
+               return hashCode;
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       public boolean equals(Object object) {
+               if (!(object instanceof ListNotification)) {
+                       return false;
+               }
+               ListNotification<?> listNotification = (ListNotification<?>) object;
+               if (!key.equals(listNotification.key)) {
+                       return false;
+               }
+               if (elements.size() != listNotification.elements.size()) {
+                       return false;
+               }
+               for (int index = 0; index < elements.size(); ++index) {
+                       if (!elements.get(index).equals(listNotification.elements.get(index))) {
+                               return false;
+                       }
+               }
+               return true;
+       }
+
 }