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