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