001
014
015 package com.liferay.portlet.dynamicdatamapping.util.comparator;
016
017 import com.liferay.portal.kernel.util.OrderByComparator;
018 import com.liferay.portal.kernel.util.StringUtil;
019 import com.liferay.portlet.dynamicdatamapping.model.DDMStructure;
020
021
024 public class StructureStructureKeyComparator
025 extends OrderByComparator<DDMStructure> {
026
027 public static final String ORDER_BY_ASC = "DDMStructure.structureKey ASC";
028
029 public static final String ORDER_BY_DESC = "DDMStructure.structureKey DESC";
030
031 public static final String[] ORDER_BY_FIELDS = {"structureKey"};
032
033 public StructureStructureKeyComparator() {
034 this(false);
035 }
036
037 public StructureStructureKeyComparator(boolean ascending) {
038 _ascending = ascending;
039 }
040
041 @Override
042 public int compare(DDMStructure structure1, DDMStructure structure2) {
043 String structureKey1 = structure1.getStructureKey();
044
045 structureKey1 = StringUtil.toLowerCase(structureKey1);
046
047 String structureKey2 = structure2.getStructureKey();
048
049 structureKey2 = StringUtil.toLowerCase(structureKey2);
050
051 int value = structureKey1.compareTo(structureKey2);
052
053 if (_ascending) {
054 return value;
055 }
056 else {
057 return -value;
058 }
059 }
060
061 @Override
062 public String getOrderBy() {
063 if (_ascending) {
064 return ORDER_BY_ASC;
065 }
066 else {
067 return ORDER_BY_DESC;
068 }
069 }
070
071 @Override
072 public String[] getOrderByFields() {
073 return ORDER_BY_FIELDS;
074 }
075
076 @Override
077 public boolean isAscending() {
078 return _ascending;
079 }
080
081 private final boolean _ascending;
082
083 }