aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTimur Masar <tmasar@459below.org>2015-11-10 20:43:31 +0100
committerTimur Masar <tmasar@459below.org>2015-11-15 02:25:34 +0100
commit5729665b1b8e13eaf419d58d80ccba2f226eaa86 (patch)
treeae1dba720ef1c785b216902e038022af186be741
parentda41388582b48aa830ee776db7b87bc400817f43 (diff)
downloadjitsi-5729665b1b8e13eaf419d58d80ccba2f226eaa86.zip
jitsi-5729665b1b8e13eaf419d58d80ccba2f226eaa86.tar.gz
jitsi-5729665b1b8e13eaf419d58d80ccba2f226eaa86.tar.bz2
Fixing TreeSet's Comparator
This fixes the Presence TreeSet's Comparator. If the comparator can't determine a greater or less than relationship, it will sort by the name of the resources lexicographically. A (mathematical) set is a collection of distinct objects. A TreeSet's compare function determines relation of two objects. It also determines equality and since this is a Set it would effectively replace the old one in the set, if the function returns 0. This method wasn't fully equals consistent, meaning different objects were deemed equal by the comparator. That lead to an inconsistency in the representation of presence objects and resources that contact has connected. The resources not represented in this TreeSet would no longer be able to let the contact appear as Online.
-rw-r--r--src/net/java/sip/communicator/impl/protocol/jabber/OperationSetPersistentPresenceJabberImpl.java13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetPersistentPresenceJabberImpl.java b/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetPersistentPresenceJabberImpl.java
index 69c168c..2d40ac1 100644
--- a/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetPersistentPresenceJabberImpl.java
+++ b/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetPersistentPresenceJabberImpl.java
@@ -1528,6 +1528,19 @@ public class OperationSetPersistentPresenceJabberImpl
o2, parentProvider).getStatus()
- jabberStatusToPresenceStatus(
o1, parentProvider).getStatus();
+ // We have run out of "logical" ways to order
+ // the presences inside the TreeSet. We have
+ // make sure we are consinstent with equals.
+ // We do this by comparing the unique resource
+ // names. If this evaluates to 0 again, then we
+ // can safely assume this presence object
+ // represents the same resource and by that the
+ // same client.
+ if(res == 0)
+ {
+ res = o1.getFrom().compareTo(
+ o2.getFrom());
+ }
}
return res;