1
22
23 package com.liferay.portlet.blogs.util.comparator;
24
25 import com.liferay.portal.kernel.util.DateUtil;
26 import com.liferay.portal.kernel.util.OrderByComparator;
27 import com.liferay.portlet.blogs.model.BlogsEntry;
28
29
34 public class EntryDisplayDateComparator extends OrderByComparator {
35
36 public static String ORDER_BY_ASC = "displayDate ASC, entryId ASC";
37
38 public static String ORDER_BY_DESC = "displayDate DESC, entryId DESC";
39
40 public static String[] ORDER_BY_FIELDS = {"displayDate", "entryId"};
41
42 public EntryDisplayDateComparator() {
43 this(false);
44 }
45
46 public EntryDisplayDateComparator(boolean asc) {
47 _asc = asc;
48 }
49
50 public int compare(Object obj1, Object obj2) {
51 BlogsEntry entry1 = (BlogsEntry)obj1;
52 BlogsEntry entry2 = (BlogsEntry)obj2;
53
54 int value = DateUtil.compareTo(
55 entry1.getDisplayDate(), entry2.getDisplayDate());
56
57 if (value == 0) {
58 if (entry1.getEntryId() < entry2.getEntryId()) {
59 value = -1;
60 }
61 else if (entry1.getEntryId() > entry2.getEntryId()) {
62 value = 1;
63 }
64 }
65
66 if (_asc) {
67 return value;
68 }
69 else {
70 return -value;
71 }
72 }
73
74 public String getOrderBy() {
75 if (_asc) {
76 return ORDER_BY_ASC;
77 }
78 else {
79 return ORDER_BY_DESC;
80 }
81 }
82
83 public String[] getOrderByFields() {
84 return ORDER_BY_FIELDS;
85 }
86
87 public boolean isAscending() {
88 return _asc;
89 }
90
91 private boolean _asc;
92
93 }