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