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.Group;
19  
20  /**
21   * <a href="GroupFriendlyURLComparator.java.html"><b><i>View Source</i></b></a>
22   *
23   * @author Brian Wing Shun Chan
24   */
25  public class GroupFriendlyURLComparator extends OrderByComparator {
26  
27      public static String ORDER_BY_ASC = "groupFriendlyURL ASC";
28  
29      public static String ORDER_BY_DESC = "groupFriendlyURL DESC";
30  
31      public static String[] ORDER_BY_FIELDS = {"groupFriendlyURL"};
32  
33      public GroupFriendlyURLComparator() {
34          this(false);
35      }
36  
37      public GroupFriendlyURLComparator(boolean ascending) {
38          _ascending = ascending;
39      }
40  
41      public int compare(Object obj1, Object obj2) {
42          Group group1 = (Group)obj1;
43          Group group2 = (Group)obj2;
44  
45          int value = group1.getFriendlyURL().compareTo(group2.getFriendlyURL());
46  
47          if (_ascending) {
48              return value;
49          }
50          else {
51              return -value;
52          }
53      }
54  
55      public String getOrderBy() {
56          if (_ascending) {
57              return ORDER_BY_ASC;
58          }
59          else {
60              return ORDER_BY_DESC;
61          }
62      }
63  
64      public String[] getOrderByFields() {
65          return ORDER_BY_FIELDS;
66      }
67  
68      public boolean isAscending() {
69          return _ascending;
70      }
71  
72      private boolean _ascending;
73  
74  }