001
014
015 package com.liferay.portal.util.comparator;
016
017 import com.liferay.portal.kernel.util.OrderByComparator;
018 import com.liferay.portal.model.Layout;
019
020
023 public class LayoutPriorityComparator extends OrderByComparator {
024
025 public static String ORDER_BY_ASC = "priority ASC";
026
027 public static String[] ORDER_BY_FIELDS = {"priority"};
028
029 public LayoutPriorityComparator(Layout layout, boolean lessThan) {
030 _layout = layout;
031 _lessThan = lessThan;
032 }
033
034 public int compare(Object obj1, Object obj2) {
035 Layout layout1 = (Layout)obj1;
036 Layout layout2 = (Layout)obj2;
037
038 int priority1 = layout1.getPriority();
039 int priority2 = layout2.getPriority();
040
041 if (priority1 > priority2) {
042 return 1;
043 }
044 else if (priority1 < priority2) {
045 return -1;
046 }
047 else {
048 if (_layout.equals(layout1)) {
049 if (_lessThan) {
050 return 1;
051 }
052 else {
053 return -1;
054 }
055 }
056 else if (_layout.equals(layout2)) {
057 if (_lessThan) {
058 return -1;
059 }
060 else {
061 return 1;
062 }
063 }
064
065 return 0;
066 }
067 }
068
069 public String getOrderBy() {
070 return ORDER_BY_ASC;
071 }
072
073 public String[] getOrderByFields() {
074 return ORDER_BY_FIELDS;
075 }
076
077 public boolean isAscending() {
078 return true;
079 }
080
081 private Layout _layout;
082 private boolean _lessThan;
083
084 }