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