1
2
3
4
5
6 package com.atlassian.core.util;
7
8 import java.util.Comparator;
9 import java.util.Locale;
10
11
12 public class LocaleComparator implements Comparator
13 {
14 public int compare(Object o1, Object o2)
15 {
16 Locale l1 = (Locale) o1;
17 Locale l2 = (Locale) o2;
18
19 if (l1 == null && l2 == null)
20 return 0;
21 else if (l2 == null)
22 return -1;
23 else if (l1 == null)
24 return 1;
25
26 String displayName1 = l1.getDisplayName();
27 String displayName2 = l2.getDisplayName();
28
29 if (displayName1 == null)
30 {
31 return -1;
32 }
33 else if (displayName2 == null)
34 {
35 return 1;
36 }
37 else
38 {
39 return displayName1.toLowerCase().compareTo(displayName2.toLowerCase());
40 }
41 }
42 }