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