From e53822bee94492512b6ff19600d300887a02bff3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Thu, 24 Nov 2011 09:14:12 +0100 Subject: [PATCH] Override hashCode() and equals(). --- .../sone/notify/ListNotification.java | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/main/java/net/pterodactylus/sone/notify/ListNotification.java b/src/main/java/net/pterodactylus/sone/notify/ListNotification.java index 74e3100..7216c42 100644 --- a/src/main/java/net/pterodactylus/sone/notify/ListNotification.java +++ b/src/main/java/net/pterodactylus/sone/notify/ListNotification.java @@ -161,4 +161,43 @@ public class ListNotification 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; + } + } -- 2.7.4