| LayoutPriorityComparator.java |
1 /**
2 * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3 *
4 * The contents of this file are subject to the terms of the Liferay Enterprise
5 * Subscription License ("License"). You may not use this file except in
6 * compliance with the License. You can obtain a copy of the License by
7 * contacting Liferay, Inc. See the License for the specific language governing
8 * permissions and limitations under the License, including but not limited to
9 * distribution rights of the Software.
10 *
11 *
12 *
13 */
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 /**
21 * <a href="LayoutPriorityComparator.java.html"><b><i>View Source</i></b></a>
22 *
23 * @author Brian Wing Shun Chan
24 */
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 }