KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > openedit > users > UserComparator


1 /*
2  * Created on Jun 7, 2005
3  */

4 package com.openedit.users;
5
6 import java.util.Comparator JavaDoc;
7
8 /**
9  * @author cburkey
10  *
11  */

12 public class UserComparator implements Comparator JavaDoc
13 {
14
15     /* (non-javadoc)
16      * @see java.util.Comparator#compare(T, T)
17      */

18     public int compare(Object JavaDoc inO1, Object JavaDoc inO2)
19     {
20         User low = (User)inO1;
21         User high = (User)inO2;
22         
23         String JavaDoc lowlast = low.getLastName();
24         String JavaDoc highlast = high.getLastName();
25         
26         if ( lowlast == null)
27         {
28             lowlast = "";
29         }
30         if ( highlast == null)
31         {
32             highlast = "";
33         }
34         int i = lowlast.compareTo(highlast);
35         if ( i == 0)
36         {
37             return checkFirst(low.getFirstName(),high.getFirstName());
38         }
39         else
40         {
41             return i;
42         }
43     }
44
45     /**
46      * @param inFirstName
47      * @param inFirstName2
48      * @return
49      */

50     private int checkFirst(String JavaDoc inFirstName, String JavaDoc inFirstName2)
51     {
52         if ( inFirstName ==null)
53         {
54             inFirstName = "";
55         }
56         if ( inFirstName2 == null)
57         {
58             inFirstName2 = "";
59         }
60         return inFirstName.compareTo(inFirstName2);
61     }
62
63 }
64
Popular Tags