1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portlet.tasks.util.comparator;
16  
17  import com.liferay.portal.kernel.util.OrderByComparator;
18  import com.liferay.portlet.tasks.model.TasksReview;
19  
20  /**
21   * <a href="ReviewUserNameComparator.java.html"><b><i>View Source</i></b></a>
22   *
23   * @author Brian Wing Shun Chan
24   */
25  public class ReviewUserNameComparator extends OrderByComparator {
26  
27      public static String ORDER_BY_ASC = "stage, userName ASC";
28  
29      public static String ORDER_BY_DESC = "stage, userName DESC";
30  
31      public static String[] ORDER_BY_FIELDS = {"stage", "userName"};
32  
33      public ReviewUserNameComparator() {
34          this(false);
35      }
36  
37      public ReviewUserNameComparator(boolean asc) {
38          _asc = asc;
39      }
40  
41      public int compare(Object obj1, Object obj2) {
42          TasksReview review1 = (TasksReview)obj1;
43          TasksReview review2 = (TasksReview)obj2;
44  
45          int value = 0;
46  
47          if (review1.getStage() < review2.getStage()) {
48              value = -1;
49          }
50          else if (review1.getStage() > review2.getStage()) {
51              value = 1;
52          }
53  
54          if (value == 0) {
55              value = review1.getUserName().compareTo(review2.getUserName());
56          }
57  
58          if (_asc) {
59              return value;
60          }
61          else {
62              return -value;
63          }
64      }
65  
66      public String getOrderBy() {
67          if (_asc) {
68              return ORDER_BY_ASC;
69          }
70          else {
71              return ORDER_BY_DESC;
72          }
73      }
74  
75      public String[] getOrderByFields() {
76          return ORDER_BY_FIELDS;
77      }
78  
79      public boolean isAscending() {
80          return _asc;
81      }
82  
83      private boolean _asc;
84  
85  }