001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
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            @Override
034            public int compare(Object obj1, Object obj2) {
035                    WorkflowTask workflowTask1 = (WorkflowTask)obj1;
036                    WorkflowTask workflowTask2 = (WorkflowTask)obj2;
037    
038                    String name1 = workflowTask1.getName();
039                    String name2 = workflowTask2.getName();
040    
041                    int value = name1.compareTo(name2);
042    
043                    if (value == 0) {
044                            Long workflowTaskId1 = workflowTask1.getWorkflowTaskId();
045                            Long workflowTaskId2 = workflowTask2.getWorkflowTaskId();
046    
047                            value = workflowTaskId1.compareTo(workflowTaskId2);
048                    }
049    
050                    if (_ascending) {
051                            return value;
052                    }
053                    else {
054                            return -value;
055                    }
056            }
057    
058            @Override
059            public boolean isAscending() {
060                    return _ascending;
061            }
062    
063            private boolean _ascending;
064    
065    }