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