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.Resource;
19  
20  /**
21   * <a href="ResourceComparator.java.html"><b><i>View Source</i></b></a>
22   *
23   * @author Alexander Chow
24   */
25  public class ResourceComparator extends OrderByComparator {
26  
27      public static String ORDER_BY_DESC = "resourceId DESC";
28  
29      public static String[] ORDER_BY_FIELDS = {"resourceId"};
30  
31      public int compare(Object obj1, Object obj2) {
32          Resource resource1 = (Resource)obj1;
33          Resource resource2 = (Resource)obj2;
34  
35          long resourceId1 = resource1.getResourceId();
36          long resourceId2 = resource2.getResourceId();
37  
38          if (resourceId1 > resourceId2) {
39              return -1;
40          }
41          else if (resourceId1 < resourceId2) {
42              return 1;
43          }
44          else {
45              return 0;
46          }
47      }
48  
49      public String getOrderBy() {
50          return ORDER_BY_DESC;
51      }
52  
53      public String[] getOrderByFields() {
54          return ORDER_BY_FIELDS;
55      }
56  
57      public boolean isAscending() {
58          return false;
59      }
60  
61  }