1
14
15 package com.liferay.portal.util.comparator;
16
17 import com.liferay.portal.kernel.util.OrderByComparator;
18 import com.liferay.portal.model.Layout;
19
20
25 public class LayoutPriorityComparator extends OrderByComparator {
26
27 public static String ORDER_BY_ASC = "priority ASC";
28
29 public static String[] ORDER_BY_FIELDS = {"priority"};
30
31 public LayoutPriorityComparator(Layout layout, boolean lessThan) {
32 _layout = layout;
33 _lessThan = lessThan;
34 }
35
36 public int compare(Object obj1, Object obj2) {
37 Layout layout1 = (Layout)obj1;
38 Layout layout2 = (Layout)obj2;
39
40 int priority1 = layout1.getPriority();
41 int priority2 = layout2.getPriority();
42
43 if (priority1 > priority2) {
44 return 1;
45 }
46 else if (priority1 < priority2) {
47 return -1;
48 }
49 else {
50 if (_layout.equals(layout1)) {
51 if (_lessThan) {
52 return 1;
53 }
54 else {
55 return -1;
56 }
57 }
58 else if (_layout.equals(layout2)) {
59 if (_lessThan) {
60 return -1;
61 }
62 else {
63 return 1;
64 }
65 }
66
67 return 0;
68 }
69 }
70
71 public String getOrderBy() {
72 return ORDER_BY_ASC;
73 }
74
75 public String[] getOrderByFields() {
76 return ORDER_BY_FIELDS;
77 }
78
79 public boolean isAscending() {
80 return true;
81 }
82
83 private Layout _layout;
84 private boolean _lessThan;
85
86 }