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 LayoutComparator extends OrderByComparator {
024
025 public static String ORDER_BY_ASC = "groupId ASC, layoutId ASC";
026
027 public static String ORDER_BY_DESC = "groupId DESC, layoutId DESC";
028
029 public static String[] ORDER_BY_FIELDS = {"groupId", "layoutId"};
030
031 public LayoutComparator() {
032 this(false);
033 }
034
035 public LayoutComparator(boolean ascending) {
036 _ascending = ascending;
037 }
038
039 @Override
040 public int compare(Object obj1, Object obj2) {
041 Layout layout1 = (Layout)obj1;
042 Layout layout2 = (Layout)obj2;
043
044 Long groupId1 = new Long(layout1.getGroupId());
045 Long groupId2 = new Long(layout2.getGroupId());
046
047 int value = groupId1.compareTo(groupId2);
048
049 if (value != 0) {
050 if (_ascending) {
051 return value;
052 }
053 else {
054 return -value;
055 }
056 }
057
058 Long layoutId1 = new Long(layout1.getLayoutId());
059 Long layoutId2 = new Long(layout2.getLayoutId());
060
061 value = layoutId1.compareTo(layoutId2);
062
063 if (_ascending) {
064 return value;
065 }
066 else {
067 return -value;
068 }
069 }
070
071 @Override
072 public String getOrderBy() {
073 if (_ascending) {
074 return ORDER_BY_ASC;
075 }
076 else {
077 return ORDER_BY_DESC;
078 }
079 }
080
081 @Override
082 public String[] getOrderByFields() {
083 return ORDER_BY_FIELDS;
084 }
085
086 @Override
087 public boolean isAscending() {
088 return _ascending;
089 }
090
091 private boolean _ascending;
092
093 }