From d60b63a89a66d44601953c09029906456650ea0f Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Mon, 27 Oct 2014 13:31:33 +0100 Subject: [PATCH] Remove hashCode/equals from Message and Packet Those where never correctly implemented and are not really used. If you want to compare Packets, compare their toXML() result. N.B. that we keep hashCode/equals for Message.(Subject|Body) because those are correct and are in-use ('bodies' and 'subjects' are Sets in Message). --- .../jivesoftware/smack/packet/Message.java | 34 ----------------- .../org/jivesoftware/smack/packet/Packet.java | 32 ---------------- .../smack/packet/MessageTest.java | 38 ------------------- 3 files changed, 104 deletions(-) diff --git a/smack-core/src/main/java/org/jivesoftware/smack/packet/Message.java b/smack-core/src/main/java/org/jivesoftware/smack/packet/Message.java index 4cf3596c5..f5ac6030d 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/packet/Message.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/packet/Message.java @@ -441,40 +441,6 @@ public final class Message extends Packet { return buf; } - - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - Message message = (Message) o; - - if(!super.equals(message)) { return false; } - if (bodies.size() != message.bodies.size() || !bodies.containsAll(message.bodies)) { - return false; - } - if (language != null ? !language.equals(message.language) : message.language != null) { - return false; - } - if (subjects.size() != message.subjects.size() || !subjects.containsAll(message.subjects)) { - return false; - } - if (thread != null ? !thread.equals(message.thread) : message.thread != null) { - return false; - } - return type == message.type; - - } - - public int hashCode() { - int result; - result = (type != null ? type.hashCode() : 0); - result = 31 * result + subjects.hashCode(); - result = 31 * result + (thread != null ? thread.hashCode() : 0); - result = 31 * result + (language != null ? language.hashCode() : 0); - result = 31 * result + bodies.hashCode(); - return result; - } - /** * Represents a message subject, its language and the content of the subject. */ diff --git a/smack-core/src/main/java/org/jivesoftware/smack/packet/Packet.java b/smack-core/src/main/java/org/jivesoftware/smack/packet/Packet.java index 7091ac71d..697e8944d 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/packet/Packet.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/packet/Packet.java @@ -365,38 +365,6 @@ public abstract class Packet extends TopLevelStreamElement { return DEFAULT_LANGUAGE; } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - Packet packet = (Packet) o; - - if (error != null ? !error.equals(packet.error) : packet.error != null) { return false; } - if (from != null ? !from.equals(packet.from) : packet.from != null) { return false; } - synchronized (packetExtensions) { - if (!packetExtensions.equals(packet.packetExtensions)) { return false; } - } - if (packetID != null ? !packetID.equals(packet.packetID) : packet.packetID != null) { - return false; - } - if (to != null ? !to.equals(packet.to) : packet.to != null) { return false; } - return true; - } - - @Override - public int hashCode() { - int result = 1; - result = 31 * result + (packetID != null ? packetID.hashCode() : 0); - result = 31 * result + (to != null ? to.hashCode() : 0); - result = 31 * result + (from != null ? from.hashCode() : 0); - synchronized (packetExtensions) { - result = 31 * result + packetExtensions.hashCode(); - } - result = 31 * result + (error != null ? error.hashCode() : 0); - return result; - } - @Override public String toString() { return toXML().toString(); diff --git a/smack-core/src/test/java/org/jivesoftware/smack/packet/MessageTest.java b/smack-core/src/test/java/org/jivesoftware/smack/packet/MessageTest.java index 8867b65b3..d96438f95 100644 --- a/smack-core/src/test/java/org/jivesoftware/smack/packet/MessageTest.java +++ b/smack-core/src/test/java/org/jivesoftware/smack/packet/MessageTest.java @@ -217,44 +217,6 @@ public class MessageTest { assertXMLEqual(control, message.toXML().toString()); } - @Test - public void messageEqualityTest() { - Message message = getNewMessage(); - assertTrue(message.equals(message)); - //noinspection ObjectEqualsNull - assertFalse(message.equals(null)); - assertFalse(message.equals("test")); - Message message2 = getNewMessage(); - - assertTrue(message.equals(message2)); - - message.setTo("joe@shmoe.com"); - assertFalse(message.equals(message2)); - message2.setTo("joe@shmoe.com"); - - message.setSubject("subject"); - assertFalse(message.equals(message2)); - message2.setSubject("subject"); - - message.setThread("thread"); - assertFalse(message.equals(message2)); - message2.setThread("thread"); - - message.setBody("body1"); - assertFalse(message.equals(message2)); - message2.setBody("body1"); - - message.setLanguage("language"); - assertFalse(message.equals(message2)); - message2.setLanguage("language"); - - message.setType(Message.Type.chat); - assertFalse(message.equals(message2)); - message2.setType(Message.Type.chat); - - assertTrue(message.equals(message2)); - } - private static Message getNewMessage() { Message message = new Message(); message.setPacketID(null);