1
14
15 package com.liferay.portal.kernel.util;
16
17 import java.io.Serializable;
18
19 import java.util.Comparator;
20
21
26 public abstract class OrderByComparator implements Comparator, Serializable {
27
28 public abstract int compare(Object obj1, Object obj2);
29
30 public String getOrderBy() {
31 return null;
32 }
33
34 public String[] getOrderByFields() {
35 String orderBy = getOrderBy();
36
37 if (orderBy == null) {
38 return null;
39 }
40
41 String[] parts = StringUtil.split(orderBy);
42
43 String[] fields = new String[parts.length];
44
45 for (int i = 0; i < parts.length; i++) {
46 String part = parts[i];
47
48 int x = part.indexOf(StringPool.PERIOD);
49 int y = part.indexOf(StringPool.SPACE, x);
50
51 if (y == -1) {
52 y = part.length();
53 }
54
55 fields[i] = part.substring(x + 1, y);
56 }
57
58 return fields;
59 }
60
61 public boolean isAscending() {
62 String orderBy = getOrderBy();
63
64 if ((orderBy == null) || orderBy.toUpperCase().endsWith(" DESC")) {
65 return false;
66 }
67 else {
68 return true;
69 }
70 }
71
72 public String toString() {
73 return getOrderBy();
74 }
75
76 }