1   /*
2    * Copyright (c) 2002-2004
3    * All rights reserved.
4    */
5   
6   package com.atlassian.core.util;
7   
8   import java.util.Comparator;
9   import java.util.Locale;
10  
11  // Locale comparator - compares on locale display name
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) // any value is less than null
22              return -1;
23          else if (l1 == null) // null is greater than any value
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()); //do case insensitive sorting
40          }
41      }
42  }