KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > roller > util > LocaleComparator


1 package org.roller.util;
2
3 import java.util.Locale JavaDoc;
4 import java.util.Comparator JavaDoc;
5 import java.io.Serializable JavaDoc;
6
7 public class LocaleComparator implements Comparator JavaDoc, Serializable JavaDoc
8 {
9     public int compare(Object JavaDoc obj1, Object JavaDoc obj2)
10     {
11         if (obj1 instanceof Locale JavaDoc && obj2 instanceof Locale JavaDoc)
12         {
13             Locale JavaDoc locale1 = (Locale JavaDoc)obj1;
14             Locale JavaDoc locale2 = (Locale JavaDoc)obj2;
15             int compName = locale1.getDisplayName().compareTo(locale2.getDisplayName());
16             if (compName == 0)
17             {
18                 return locale1.toString().compareTo(locale2.toString());
19             }
20             return compName;
21         }
22         return 0;
23     }
24 /* Do Comparators need to implement equals()? -Lance
25     public boolean equals(Object obj)
26     {
27         if (obj instanceof LocaleComparator)
28         {
29             if (obj.equals(this)) return true;
30         }
31         return false;
32     }
33 */

34 }
Popular Tags