001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.kernel.workflow.comparator;
016    
017    import com.liferay.portal.kernel.util.OrderByComparator;
018    import com.liferay.portal.kernel.workflow.WorkflowTask;
019    
020    /**
021     * @author Shuyang Zhou
022     */
023    public class BaseWorkflowTaskNameComparator extends OrderByComparator {
024    
025            public BaseWorkflowTaskNameComparator() {
026                    this(false);
027            }
028    
029            public BaseWorkflowTaskNameComparator(boolean ascending) {
030                    _ascending = ascending;
031            }
032    
033            public int compare(Object obj1, Object obj2) {
034                    WorkflowTask workflowTask1 = (WorkflowTask)obj1;
035                    WorkflowTask workflowTask2 = (WorkflowTask)obj2;
036    
037                    String name1 = workflowTask1.getName();
038                    String name2 = workflowTask2.getName();
039    
040                    int value = name1.compareTo(name2);
041    
042                    if (value == 0) {
043                            Long workflowTaskId1 = workflowTask1.getWorkflowTaskId();
044                            Long workflowTaskId2 = workflowTask2.getWorkflowTaskId();
045    
046                            value = workflowTaskId1.compareTo(workflowTaskId2);
047                    }
048    
049                    if (_ascending) {
050                            return value;
051                    }
052                    else {
053                            return -value;
054                    }
055            }
056    
057            public boolean isAscending() {
058                    return _ascending;
059            }
060    
061            private boolean _ascending;
062    
063    }