001
014
015 package com.liferay.portlet.imagegallery.util.comparator;
016
017 import com.liferay.portal.kernel.util.OrderByComparator;
018 import com.liferay.portlet.imagegallery.model.IGImage;
019
020
023 public class ImageDescriptionComparator extends OrderByComparator {
024
025 public static String ORDER_BY_ASC = "description ASC";
026
027 public static String ORDER_BY_DESC = "description DESC";
028
029 public static String[] ORDER_BY_FIELDS = {"description"};
030
031 public ImageDescriptionComparator() {
032 this(false);
033 }
034
035 public ImageDescriptionComparator(boolean ascending) {
036 _ascending = ascending;
037 }
038
039 public int compare(Object obj1, Object obj2) {
040 IGImage image1 = (IGImage)obj1;
041 IGImage image2 = (IGImage)obj2;
042
043 int value =
044 image1.getDescription().toLowerCase().compareTo(
045 image2.getDescription().toLowerCase());
046
047 if (_ascending) {
048 return value;
049 }
050 else {
051 return -value;
052 }
053 }
054
055 public String getOrderBy() {
056 if (_ascending) {
057 return ORDER_BY_ASC;
058 }
059 else {
060 return ORDER_BY_DESC;
061 }
062 }
063
064 public String[] getOrderByFields() {
065 return ORDER_BY_FIELDS;
066 }
067
068 public boolean isAscending() {
069 return _ascending;
070 }
071
072 private boolean _ascending;
073
074 }