| ResourceComparator.java |
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.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 }