01: package org.claros.chat.utility;
02:
03: import java.util.Comparator;
04: import java.util.HashMap;
05:
06: import org.claros.chat.models.Contact;
07:
08: /**
09: * @author Umut Gokbayrak
10: */
11: public class RosterComparator implements Comparator {
12: private static HashMap map = new HashMap();
13:
14: static {
15: map.put("chat", new Integer(1));
16: map.put("available", new Integer(2));
17: map.put("away", new Integer(3));
18: map.put("extended_away", new Integer(3));
19: map.put("disturb", new Integer(4));
20: map.put("invisible", new Integer(5));
21: map.put("offline", new Integer(6));
22: }
23:
24: /* (non-Javadoc)
25: * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
26: */
27: public int compare(Object arg0, Object arg1) {
28: Contact c1 = (Contact) arg0;
29: Contact c2 = (Contact) arg1;
30: Integer p1 = (Integer) map.get(c1.getPresence());
31: Integer p2 = (Integer) map.get(c2.getPresence());
32: if (p1 == null) {
33: p1 = new Integer(10);
34: }
35: if (p2 == null) {
36: p2 = new Integer(10);
37: }
38: if (p1.equals(p2)) {
39: return c1.getName().compareTo(c2.getName());
40: }
41: return p1.compareTo(p2);
42: }
43: }
|