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 final String ORDER_BY_ASC = "Layout.priority ASC";
026
027 public static final String[] ORDER_BY_FIELDS = {"priority"};
028
029 public LayoutPriorityComparator(Layout layout, boolean lessThan) {
030 _layout = layout;
031 _lessThan = lessThan;
032 }
033
034 @Override
035 public int compare(Object obj1, Object obj2) {
036 Layout layout1 = (Layout)obj1;
037 Layout layout2 = (Layout)obj2;
038
039 int priority1 = layout1.getPriority();
040 int priority2 = layout2.getPriority();
041
042 if (priority1 > priority2) {
043 return 1;
044 }
045 else if (priority1 < priority2) {
046 return -1;
047 }
048 else {
049 if (_layout.equals(layout1)) {
050 if (_lessThan) {
051 return 1;
052 }
053 else {
054 return -1;
055 }
056 }
057 else if (_layout.equals(layout2)) {
058 if (_lessThan) {
059 return -1;
060 }
061 else {
062 return 1;
063 }
064 }
065
066 return 0;
067 }
068 }
069
070 @Override
071 public String getOrderBy() {
072 return ORDER_BY_ASC;
073 }
074
075 @Override
076 public String[] getOrderByFields() {
077 return ORDER_BY_FIELDS;
078 }
079
080 @Override
081 public boolean isAscending() {
082 return true;
083 }
084
085 private Layout _layout;
086 private boolean _lessThan;
087
088 }