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  /**
21   * <a href="BaseWorkflowTaskNameComparator.java.html"><b><i>View Source</i></b>
22   * </a>
23   *
24   * @author Shuyang Zhou
25   */
26  public class BaseWorkflowTaskNameComparator extends OrderByComparator {
27  
28      public BaseWorkflowTaskNameComparator() {
29          this(false);
30      }
31  
32      public BaseWorkflowTaskNameComparator(boolean ascending) {
33          _ascending = ascending;
34      }
35  
36      public int compare(Object obj1, Object obj2) {
37          WorkflowTask workflowTask1 = (WorkflowTask)obj1;
38          WorkflowTask workflowTask2 = (WorkflowTask)obj2;
39  
40          String name1 = workflowTask1.getName();
41          String name2 = workflowTask2.getName();
42  
43          int value = name1.compareTo(name2);
44  
45          if (value == 0) {
46              Long workflowTaskId1 = workflowTask1.getWorkflowTaskId();
47              Long workflowTaskId2 = workflowTask2.getWorkflowTaskId();
48  
49              value = workflowTaskId1.compareTo(workflowTaskId2);
50          }
51  
52          if (_ascending) {
53              return value;
54          }
55          else {
56              return -value;
57          }
58      }
59  
60      public boolean isAscending() {
61          return _ascending;
62      }
63  
64      private boolean _ascending;
65  
66  }