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