View Javadoc

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<Locale>
13  {
14      public int compare(Locale l1, Locale l2)
15      {
16          if (l1 == null && l2 == null)
17              return 0;
18          else if (l2 == null) // any value is less than null
19              return -1;
20          else if (l1 == null) // null is greater than any value
21              return 1;
22  
23          String displayName1 = l1.getDisplayName();
24          String displayName2 = l2.getDisplayName();
25  
26          if (displayName1 == null)
27          {
28              return -1;
29          }
30          else if (displayName2 == null)
31          {
32              return 1;
33          }
34          else
35          {
36              return displayName1.toLowerCase().compareTo(displayName2.toLowerCase()); //do case insensitive sorting
37          }
38      }
39  }