I tried to use a TreeMap<JID,Element> and spend hours for searching this bug:
node@domain compared with domain returns zero, which is defined as equal!
Same goes for node@domain/resource compared with node@domain.
(minor bug: typo "Object not instanceof JID: ")
The method compareTo is implemented as follows:
public int compareTo(Object o) {
if (!(o instanceof JID)) {
throw new ClassCastException("Ojbect not instanceof JID: " + o);
}
JID jid = (JID)o; // Comparison order is domain, node, resource.
int compare = domain.compareTo(jid.domain);
if (compare == 0 && node != null && jid.node != null) {
compare = node.compareTo(jid.node);
}
if (compare == 0 && resource != null && jid.resource != null) {
compare = resource.compareTo(jid.resource);
}
return compare;
}