1
14
15 package com.liferay.portal.util.comparator;
16
17 import com.liferay.portal.kernel.util.OrderByComparator;
18 import com.liferay.portal.model.Role;
19
20
25 public class RoleDescriptionComparator extends OrderByComparator {
26
27 public static String ORDER_BY_ASC =
28 "Role_.description ASC, Role_.name ASC";
29
30 public static String ORDER_BY_DESC =
31 "Role_.description DESC, Role_.name DESC";
32
33 public static String[] ORDER_BY_FIELDS = {"description", "name"};
34
35 public RoleDescriptionComparator() {
36 this(false);
37 }
38
39 public RoleDescriptionComparator(boolean asc) {
40 _asc = asc;
41 }
42
43 public int compare(Object obj1, Object obj2) {
44 Role role1 = (Role)obj1;
45 Role role2 = (Role)obj2;
46
47 int value = role1.getDescription().compareTo(
48 role2.getDescription());
49
50 if (value == 0) {
51 value = role1.getName().compareTo(role2.getName());
52 }
53
54 if (_asc) {
55 return value;
56 }
57 else {
58 return -value;
59 }
60 }
61
62 public String getOrderBy() {
63 if (_asc) {
64 return ORDER_BY_ASC;
65 }
66 else {
67 return ORDER_BY_DESC;
68 }
69 }
70
71 public String[] getOrderByFields() {
72 return ORDER_BY_FIELDS;
73 }
74
75 public boolean isAscending() {
76 return _asc;
77 }
78
79 private boolean _asc;
80
81 }