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