Clover Coverage Report - Atlassian Core
Coverage timestamp: Sun Nov 30 2008 18:33:35 CST
20   57   10   20
14   34   0.5   1
1     10  
1    
 
 
  BestNameComparator2       Line # 21 20 10 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.atlassian.user.User;
12   
13    import java.util.Comparator;
14   
15    /**
16    * This comparator tries to compare two users based on their 'best name'
17    * ie their full name if possible, otherwise their username.
18    *
19    * This comparator completely ignores case.
20    */
 
21    public class BestNameComparator2 implements Comparator
22    {
 
23  0 toggle public int compare(Object o1, Object o2)
24    {
25  0 User u1 = (User) o1;
26  0 User u2 = (User) o2;
27   
28  0 if (u1 == null && u2 == null)
29  0 return 0;
30  0 else if (u2 == null) // any value is less than null
31  0 return -1;
32  0 else if (u1 == null) // null is greater than any value
33  0 return 1;
34   
35  0 String name1 = u1.getFullName();
36  0 String name2 = u2.getFullName();
37   
38  0 if (name1 == null)
39  0 name1 = u1.getName();
40   
41  0 if (name2 == null)
42  0 name2 = u2.getName();
43   
44  0 if (name1 == null || name2 == null)
45  0 throw new RuntimeException("Null user name");
46   
47  0 final int fullNameComparison = name1.toLowerCase().compareTo(name2.toLowerCase());
48  0 if (fullNameComparison == 0) //if full names are the same, we should check the username (JRA-5847)
49    {
50  0 return u1.getName().compareTo(u2.getName());
51    }
52    else
53    {
54  0 return fullNameComparison;
55    }
56    }
57    }