1
22
23 package com.liferay.portal.util.comparator;
24
25 import com.liferay.portal.kernel.util.OrderByComparator;
26 import com.liferay.portal.model.Organization;
27
28
34 public class OrganizationTypeComparator extends OrderByComparator {
35
36 public static String ORDER_BY_ASC = "orgLocation ASC, orgName ASC";
37
38 public static String ORDER_BY_DESC = "orgLocation DESC, orgName DESC";
39
40 public static String[] ORDER_BY_FIELDS = {"type", "name"};
41
42 public OrganizationTypeComparator() {
43 this(false);
44 }
45
46 public OrganizationTypeComparator(boolean asc) {
47 _asc = asc;
48 }
49
50 public int compare(Object obj1, Object obj2) {
51 Organization organization1 = (Organization)obj1;
52 Organization organization2 = (Organization)obj2;
53
54 int value = 0;
55
56 if (organization1.isLocation() && !organization2.isLocation()) {
57 value = 1;
58 }
59 else if (!organization1.isLocation() && organization2.isLocation()) {
60 value = -1;
61 }
62
63 if (value == 0) {
64 value = organization1.getName().compareTo(organization2.getName());
65 }
66
67 if (_asc) {
68 return value;
69 }
70 else {
71 return -value;
72 }
73 }
74
75 public String getOrderBy() {
76 if (_asc) {
77 return ORDER_BY_ASC;
78 }
79 else {
80 return ORDER_BY_DESC;
81 }
82 }
83
84 public String[] getOrderByFields() {
85 return ORDER_BY_FIELDS;
86 }
87
88 public boolean isAscending() {
89 return _asc;
90 }
91
92 private boolean _asc;
93
94 }