There are some small Bugs in JID class which can be solved really easily. I posted this a month ago here. According to the new bug report document, bugs should be reported here…so I do it.
Bug in JID#compareTo(Object)
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.
There is a minor typo in string "Object not instanceof JID: ", too.
The method compareTo() is currently 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;
}
another Bug in JID class
JID implements Comparable, not Comparable
Since Java supports type checking we should use it. You will get an unchecked warning from your compiler, e.g. when you do the following:
ArrayList<JID> list = new ArrayList<JID>(); // ... Collections.sort(list);