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.WorkflowInstance;
19  
20  import java.util.Date;
21  
22  /**
23   * <a href="BaseWorkflowInstanceStartDateComparator.java.html"><b><i>View Source
24   * </i></b></a>
25   *
26   * @author Shuyang Zhou
27   */
28  public abstract class BaseWorkflowInstanceStartDateComparator
29      extends OrderByComparator {
30  
31      public BaseWorkflowInstanceStartDateComparator() {
32          this(false);
33      }
34  
35      public BaseWorkflowInstanceStartDateComparator(boolean ascending) {
36          _ascending = ascending;
37      }
38  
39      public int compare(Object obj1, Object obj2) {
40          WorkflowInstance workflowInstance1 = (WorkflowInstance)obj1;
41          WorkflowInstance workflowInstance2 = (WorkflowInstance)obj2;
42  
43          Date startDate1 = workflowInstance1.getStartDate();
44          Date startDate2 = workflowInstance2.getStartDate();
45  
46          int value = startDate1.compareTo(startDate2);
47  
48          if (value == 0) {
49              Long workflowInstanceId1 =
50                  workflowInstance1.getWorkflowInstanceId();
51              Long workflowInstanceId2 =
52                  workflowInstance2.getWorkflowInstanceId();
53  
54              value = workflowInstanceId1.compareTo(workflowInstanceId2);
55          }
56  
57          if (_ascending) {
58              return value;
59          }
60          else {
61              return -value;
62          }
63      }
64  
65      public boolean isAscending() {
66          return _ascending;
67      }
68  
69      private boolean _ascending;
70  
71  }