1
19
20 package com.liferay.portlet.documentlibrary.util.comparator;
21
22 import com.liferay.portal.kernel.util.OrderByComparator;
23 import com.liferay.portlet.documentlibrary.model.DLFileEntry;
24
25
31 public class FileEntryTitleComparator extends OrderByComparator {
32
33 public static String ORDER_BY_ASC = "title ASC";
34
35 public static String ORDER_BY_DESC = "title DESC";
36
37 public static String[] ORDER_BY_FIELDS = {"title"};
38
39 public FileEntryTitleComparator() {
40 this(false);
41 }
42
43 public FileEntryTitleComparator(boolean asc) {
44 _asc = asc;
45 }
46
47 public int compare(Object obj1, Object obj2) {
48 DLFileEntry fileEntry1 = (DLFileEntry)obj1;
49 DLFileEntry fileEntry2 = (DLFileEntry)obj2;
50
51 int value = fileEntry1.getTitle().toLowerCase().compareTo(
52 fileEntry2.getTitle().toLowerCase());
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 }