1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-09-09 00:59:39 +02:00

Introduce EqualsUtil and HashCode.(Builder|Cache)

This commit is contained in:
Florian Schmaus 2019-06-12 14:51:17 +02:00
parent 92b02afbff
commit fa0c16d75c
8 changed files with 551 additions and 167 deletions

View file

@ -31,6 +31,7 @@ import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.packet.Presence.Type;
import org.jivesoftware.smack.roster.packet.RosterPacket;
import org.jivesoftware.smack.util.EqualsUtil;
import org.jxmpp.jid.BareJid;
@ -251,15 +252,9 @@ public final class RosterEntry extends Manager {
@Override
public boolean equals(Object object) {
if (this == object) {
return true;
}
if (object != null && object instanceof RosterEntry) {
return getJid().equals(((RosterEntry) object).getJid());
}
else {
return false;
}
return EqualsUtil.equals(this, object, (e, o) ->
e.append(getJid(), o.getJid())
);
}
/**
@ -272,14 +267,9 @@ public final class RosterEntry extends Manager {
* otherwise.
*/
public boolean equalsDeep(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
RosterEntry other = (RosterEntry) obj;
return other.item.equals(this.item);
return EqualsUtil.equals(this, obj, (e, o) ->
e.append(item, o.item)
);
}
/**

View file

@ -27,6 +27,8 @@ import java.util.concurrent.CopyOnWriteArraySet;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.NamedElement;
import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smack.util.EqualsUtil;
import org.jivesoftware.smack.util.HashCode;
import org.jivesoftware.smack.util.Objects;
import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smack.util.XmlStringBuilder;
@ -292,51 +294,26 @@ public final class RosterPacket extends IQ {
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((groupNames == null) ? 0 : groupNames.hashCode());
result = prime * result + (subscriptionPending ? 0 : 1);
result = prime * result + ((itemType == null) ? 0 : itemType.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((jid == null) ? 0 : jid.hashCode());
result = prime * result + ((approved == false) ? 0 : 1);
return result;
return HashCode.builder()
.append(groupNames)
.append(subscriptionPending)
.append(itemType)
.append(name)
.append(jid)
.append(approved)
.build();
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Item other = (Item) obj;
if (groupNames == null) {
if (other.groupNames != null)
return false;
}
else if (!groupNames.equals(other.groupNames))
return false;
if (subscriptionPending != other.subscriptionPending)
return false;
if (itemType != other.itemType)
return false;
if (name == null) {
if (other.name != null)
return false;
}
else if (!name.equals(other.name))
return false;
if (jid == null) {
if (other.jid != null)
return false;
}
else if (!jid.equals(other.jid))
return false;
if (approved != other.approved)
return false;
return true;
return EqualsUtil.equals(this, obj, (e, o) ->
e.append(groupNames, o.groupNames)
.append(subscriptionPending, o.subscriptionPending)
.append(itemType, o.itemType)
.append(name, o.name)
.append(jid, o.jid)
.append(approved, o.approved)
);
}
}