1
19
20 package com.liferay.portlet.bookmarks.util.comparator;
21
22 import com.liferay.portal.kernel.util.OrderByComparator;
23 import com.liferay.portlet.bookmarks.model.BookmarksEntry;
24
25
31 public class EntryPriorityComparator extends OrderByComparator {
32
33 public static String ORDER_BY_ASC = "priority ASC";
34
35 public static String ORDER_BY_DESC = "priority DESC";
36
37 public static String[] ORDER_BY_FIELDS = {"priority"};
38
39 public EntryPriorityComparator() {
40 this(false);
41 }
42
43 public EntryPriorityComparator(boolean asc) {
44 _asc = asc;
45 }
46
47 public int compare(Object obj1, Object obj2) {
48 BookmarksEntry entry1 = (BookmarksEntry)obj1;
49 BookmarksEntry entry2 = (BookmarksEntry)obj2;
50
51 int value = 0;
52
53 if (entry1.getPriority() < entry2.getPriority()) {
54 value = -1;
55 }
56 else if (entry1.getPriority() > entry2.getPriority()) {
57 value = 1;
58 }
59
60 if (_asc) {
61 return value;
62 }
63 else {
64 return -value;
65 }
66 }
67
68 public String getOrderBy() {
69 if (_asc) {
70 return ORDER_BY_ASC;
71 }
72 else {
73 return ORDER_BY_DESC;
74 }
75 }
76
77 public String[] getOrderByFields() {
78 return ORDER_BY_FIELDS;
79 }
80
81 public boolean isAscending() {
82 return _asc;
83 }
84
85 private boolean _asc;
86
87 }