1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.util.comparator;
16  
17  import com.liferay.portal.kernel.util.OrderByComparator;
18  import com.liferay.portal.model.UserGroup;
19  
20  /**
21   * <a href="UserGroupDescriptionComparator.java.html"><b><i>View Source</i></b>
22   * </a>
23   *
24   * @author Brian Wing Shun Chan
25   */
26  public class UserGroupDescriptionComparator extends OrderByComparator {
27  
28      public static String ORDER_BY_ASC =
29          "UserGroup.description ASC, UserGroup.name ASC";
30  
31      public static String ORDER_BY_DESC =
32          "UserGroup.description DESC, UserGroup.name DESC";
33  
34      public static String[] ORDER_BY_FIELDS = {"description", "name"};
35  
36      public UserGroupDescriptionComparator() {
37          this(false);
38      }
39  
40      public UserGroupDescriptionComparator(boolean asc) {
41          _asc = asc;
42      }
43  
44      public int compare(Object obj1, Object obj2) {
45          UserGroup userGroup1 = (UserGroup)obj1;
46          UserGroup userGroup2 = (UserGroup)obj2;
47  
48          int value = userGroup1.getDescription().compareTo(
49              userGroup2.getDescription());
50  
51          if (value == 0) {
52              value = userGroup1.getName().compareTo(userGroup2.getName());
53          }
54  
55          if (_asc) {
56              return value;
57          }
58          else {
59              return -value;
60          }
61      }
62  
63      public String getOrderBy() {
64          if (_asc) {
65              return ORDER_BY_ASC;
66          }
67          else {
68              return ORDER_BY_DESC;
69          }
70      }
71  
72      public String[] getOrderByFields() {
73          return ORDER_BY_FIELDS;
74      }
75  
76      public boolean isAscending() {
77          return _asc;
78      }
79  
80      private boolean _asc;
81  
82  }