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