1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-22 06:12:05 +01:00

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).
This commit is contained in:
Florian Schmaus 2014-10-27 13:31:33 +01:00
parent 416f42deb7
commit d60b63a89a
3 changed files with 0 additions and 104 deletions

View file

@ -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.
*/

View file

@ -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();

View file

@ -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);