From e3962d15ae3298a7a13d93df85cadbecd3f6699a Mon Sep 17 00:00:00 2001 From: Henning Staib Date: Sun, 15 Aug 2010 16:37:51 +0000 Subject: [PATCH] only fire roster listener if entry changed (SMACK-312) git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@11827 b35dd754-fafc-0310-a699-88a17e54d16e --- source/org/jivesoftware/smack/Roster.java | 10 +++-- .../org/jivesoftware/smack/RosterEntry.java | 45 +++++++++++++++++++ 2 files changed, 51 insertions(+), 4 deletions(-) diff --git a/source/org/jivesoftware/smack/Roster.java b/source/org/jivesoftware/smack/Roster.java index 7539c32c8..df5d53d9b 100644 --- a/source/org/jivesoftware/smack/Roster.java +++ b/source/org/jivesoftware/smack/Roster.java @@ -852,10 +852,12 @@ public class Roster { } else { // If the entry was in then list then update its state with the new values - entries.put(item.getUser(), entry); - - // Keep note that an entry has been updated - updatedEntries.add(item.getUser()); + RosterEntry oldEntry = entries.put(item.getUser(), entry); + + // Keep note that an entry has been updated but only if it's different + if (oldEntry == null || !oldEntry.equalsDeep(entry)) { + updatedEntries.add(item.getUser()); + } } // If the roster entry belongs to any groups, remove it from the // list of unfiled entries. diff --git a/source/org/jivesoftware/smack/RosterEntry.java b/source/org/jivesoftware/smack/RosterEntry.java index b352969dc..31f7a1e15 100644 --- a/source/org/jivesoftware/smack/RosterEntry.java +++ b/source/org/jivesoftware/smack/RosterEntry.java @@ -181,6 +181,50 @@ public class RosterEntry { } } + /** + * Indicates whether some other object is "equal to" this by comparing all members. + *

+ * The {@link #equals(Object)} method returns true if the user JIDs are equal. + * + * @param obj the reference object with which to compare. + * @return true if this object is the same as the obj argument; false + * 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; + if (name == null) { + if (other.name != null) + return false; + } + else if (!name.equals(other.name)) + return false; + if (status == null) { + if (other.status != null) + return false; + } + else if (!status.equals(other.status)) + return false; + if (type == null) { + if (other.type != null) + return false; + } + else if (!type.equals(other.type)) + return false; + if (user == null) { + if (other.user != null) + return false; + } + else if (!user.equals(other.user)) + return false; + return true; + } + static RosterPacket.Item toRosterItem(RosterEntry entry) { RosterPacket.Item item = new RosterPacket.Item(entry.getUser(), entry.getName()); item.setItemType(entry.getType()); @@ -191,4 +235,5 @@ public class RosterEntry { } return item; } + } \ No newline at end of file