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.portal.kernel.workflow.comparator;
16  
17  import com.liferay.portal.kernel.util.OrderByComparator;
18  import com.liferay.portal.kernel.workflow.WorkflowLog;
19  
20  /**
21   * <a href="WorkflowLogUserIdComparator.java.html"><b><i>View Source</i></b></a>
22   *
23   * @author Shuyang Zhou
24   */
25  public class WorkflowLogUserIdComparator extends OrderByComparator {
26  
27      public static String ORDER_BY_ASC = "userId ASC, workflowLogId ASC";
28  
29      public static String ORDER_BY_DESC = "userId DESC, workflowLogId DESC";
30  
31      public static String[] ORDER_BY_FIELDS = {"userId", "workflowLogId"};
32  
33      public WorkflowLogUserIdComparator() {
34          this(false);
35      }
36  
37      public WorkflowLogUserIdComparator(boolean asc) {
38          _asc = asc;
39      }
40  
41      public int compare(Object obj1, Object obj2) {
42          WorkflowLog workflowLog1 = (WorkflowLog)obj1;
43          WorkflowLog workflowLog2 = (WorkflowLog)obj2;
44  
45          Long userId1 = workflowLog1.getUserId();
46          Long userId2 = workflowLog2.getUserId();
47  
48          int value = userId1.compareTo(userId2);
49  
50          if (value == 0) {
51              Long workflowLogId1 = workflowLog1.getWorkflowLogId();
52              Long workflowLogId2 = workflowLog2.getWorkflowLogId();
53  
54              value = workflowLogId1.compareTo(workflowLogId2);
55          }
56  
57          if (_asc) {
58              return value;
59          }
60          else {
61              return -value;
62          }
63      }
64  
65      public String getOrderBy() {
66          if (_asc) {
67              return ORDER_BY_ASC;
68          }
69          else {
70              return ORDER_BY_DESC;
71          }
72      }
73  
74      public String[] getOrderByFields() {
75          return ORDER_BY_FIELDS;
76      }
77  
78      public boolean isAscending() {
79          return _asc;
80      }
81  
82      private boolean _asc;
83  
84  }