1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portal.util.comparator;
16  
17  import com.liferay.portal.kernel.util.OrderByComparator;
18  import com.liferay.portal.model.User;
19  
20  /**
21   * <a href="UserFirstNameComparator.java.html"><b><i>View Source</i></b></a>
22   *
23   * @author Brian Wing Shun Chan
24   */
25  public class UserFirstNameComparator extends OrderByComparator {
26  
27      public static String ORDER_BY_ASC =
28          "User_.firstName ASC, User_.middleName ASC, User_.lastName ASC";
29  
30      public static String ORDER_BY_DESC =
31          "User_.firstName DESC, User_.middleName DESC, User_.lastName DESC";
32  
33      public static String[] ORDER_BY_FIELDS = {
34          "firstName", "middleName", "lastName"
35      };
36  
37      public UserFirstNameComparator() {
38          this(false);
39      }
40  
41      public UserFirstNameComparator(boolean asc) {
42          _asc = asc;
43      }
44  
45      public int compare(Object obj1, Object obj2) {
46          User user1 = (User)obj1;
47          User user2 = (User)obj2;
48  
49          int value = user1.getFirstName().compareTo(user2.getFirstName());
50  
51          if (value == 0) {
52              value = user1.getMiddleName().compareTo(user2.getMiddleName());
53          }
54  
55          if (value == 0) {
56              value = user1.getLastName().compareTo(user2.getLastName());
57          }
58  
59          if (_asc) {
60              return value;
61          }
62          else {
63              return -value;
64          }
65      }
66  
67      public String getOrderBy() {
68          if (_asc) {
69              return ORDER_BY_ASC;
70          }
71          else {
72              return ORDER_BY_DESC;
73          }
74      }
75  
76      public String[] getOrderByFields() {
77          return ORDER_BY_FIELDS;
78      }
79  
80      public boolean isAscending() {
81          return _asc;
82      }
83  
84      private boolean _asc;
85  
86  }