| FullNameComparator | Line # 15 | 15 | 7 | 0% |
0.0
|
| No Tests | |||
| 1 | /* | |
| 2 | * Created by IntelliJ IDEA. | |
| 3 | * User: Administrator | |
| 4 | * Date: 14/03/2002 | |
| 5 | * Time: 11:55:04 | |
| 6 | * To change template for new class use | |
| 7 | * Code Style | Class Templates options (Tools | IDE Options). | |
| 8 | */ | |
| 9 | package com.atlassian.core.user; | |
| 10 | ||
| 11 | import com.opensymphony.user.User; | |
| 12 | ||
| 13 | import java.util.Comparator; | |
| 14 | ||
| 15 | public class FullNameComparator implements Comparator | |
| 16 | { | |
| 17 | 0 |
public int compare(Object o1, Object o2) |
| 18 | { | |
| 19 | 0 | User u1 = (User) o1; |
| 20 | 0 | User u2 = (User) o2; |
| 21 | ||
| 22 | 0 | if (u1 == null && u2 == null) |
| 23 | 0 | return 0; |
| 24 | 0 | else if (u2 == null) // any value is less than null |
| 25 | 0 | return -1; |
| 26 | 0 | else if (u1 == null) // null is greater than any value |
| 27 | 0 | return 1; |
| 28 | ||
| 29 | 0 | String fullname1 = u1.getFullName(); |
| 30 | 0 | String fullname2 = u2.getFullName(); |
| 31 | ||
| 32 | 0 | if (fullname1 == null) |
| 33 | { | |
| 34 | 0 | return -1; |
| 35 | } | |
| 36 | 0 | else if (fullname2 == null) |
| 37 | { | |
| 38 | 0 | return 1; |
| 39 | } | |
| 40 | else | |
| 41 | { | |
| 42 | 0 | return fullname1.toLowerCase().compareTo(fullname2.toLowerCase()); //do case insensitive sorting |
| 43 | } | |
| 44 | } | |
| 45 | } | |
|
||||||||||