1
14
15 package com.liferay.portlet.imagegallery.util.comparator;
16
17 import com.liferay.portal.kernel.util.OrderByComparator;
18 import com.liferay.portlet.imagegallery.model.IGImage;
19
20
25 public class ImageDescriptionComparator extends OrderByComparator {
26
27 public static String ORDER_BY_ASC = "description ASC";
28
29 public static String ORDER_BY_DESC = "description DESC";
30
31 public static String[] ORDER_BY_FIELDS = {"description"};
32
33 public ImageDescriptionComparator() {
34 this(false);
35 }
36
37 public ImageDescriptionComparator(boolean asc) {
38 _asc = asc;
39 }
40
41 public int compare(Object obj1, Object obj2) {
42 IGImage image1 = (IGImage)obj1;
43 IGImage image2 = (IGImage)obj2;
44
45 int value =
46 image1.getDescription().toLowerCase().compareTo(
47 image2.getDescription().toLowerCase());
48
49 if (_asc) {
50 return value;
51 }
52 else {
53 return -value;
54 }
55 }
56
57 public String getOrderBy() {
58 if (_asc) {
59 return ORDER_BY_ASC;
60 }
61 else {
62 return ORDER_BY_DESC;
63 }
64 }
65
66 public String[] getOrderByFields() {
67 return ORDER_BY_FIELDS;
68 }
69
70 public boolean isAscending() {
71 return _asc;
72 }
73
74 private boolean _asc;
75
76 }