| PermissionComparator.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.Permission;
19
20 /**
21 * <a href="PermissionComparator.java.html"><b><i>View Source</i></b></a>
22 *
23 * @author Alexander Chow
24 */
25 public class PermissionComparator extends OrderByComparator {
26
27 public static String ORDER_BY_DESC = "permissionId DESC";
28
29 public static String[] ORDER_BY_FIELDS = {"permissionId"};
30
31 public int compare(Object obj1, Object obj2) {
32 Permission perm1 = (Permission)obj1;
33 Permission perm2 = (Permission)obj2;
34
35 long permissionId1 = perm1.getPermissionId();
36 long permissionId2 = perm2.getPermissionId();
37
38 if (permissionId1 > permissionId2) {
39 return -1;
40 }
41 else if (permissionId1 < permissionId2) {
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 }