1
22
23 package com.liferay.portal.util.comparator;
24
25 import com.liferay.portal.kernel.util.OrderByComparator;
26 import com.liferay.portal.model.Layout;
27
28
34 public class LayoutComparator extends OrderByComparator {
35
36 public static String ORDER_BY_ASC = "groupId ASC, layoutId ASC";
37
38 public static String ORDER_BY_DESC = "groupId DESC, layoutId DESC";
39
40 public static String[] ORDER_BY_FIELDS = {"groupId", "layoutId"};
41
42 public LayoutComparator() {
43 this(false);
44 }
45
46 public LayoutComparator(boolean asc) {
47 _asc = asc;
48 }
49
50 public int compare(Object obj1, Object obj2) {
51 Layout layout1 = (Layout)obj1;
52 Layout layout2 = (Layout)obj2;
53
54 Long groupId1 = new Long(layout1.getGroupId());
55 Long groupId2 = new Long(layout2.getGroupId());
56
57 int value = groupId1.compareTo(groupId2);
58
59 if (value != 0) {
60 if (_asc) {
61 return value;
62 }
63 else {
64 return -value;
65 }
66 }
67
68 Long layoutId1 = new Long(layout1.getLayoutId());
69 Long layoutId2 = new Long(layout2.getLayoutId());
70
71 value = layoutId1.compareTo(layoutId2);
72
73 if (_asc) {
74 return value;
75 }
76 else {
77 return -value;
78 }
79 }
80
81 public String getOrderBy() {
82 if (_asc) {
83 return ORDER_BY_ASC;
84 }
85 else {
86 return ORDER_BY_DESC;
87 }
88 }
89
90 public String[] getOrderByFields() {
91 return ORDER_BY_FIELDS;
92 }
93
94 public boolean isAscending() {
95 return _asc;
96 }
97
98 private boolean _asc;
99
100 }