| LayoutPriorityComparator.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.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 }