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.WorkflowLog;
019    
020    /**
021     * @author Michael C. Han
022     */
023    public abstract class BaseWorkflowLogUserIdComparator
024            extends OrderByComparator {
025    
026            public BaseWorkflowLogUserIdComparator() {
027                    this(false);
028            }
029    
030            public BaseWorkflowLogUserIdComparator(boolean ascending) {
031                    _ascending = ascending;
032            }
033    
034            public int compare(Object obj1, Object obj2) {
035                    WorkflowLog workflowLog1 = (WorkflowLog)obj1;
036                    WorkflowLog workflowLog2 = (WorkflowLog)obj2;
037    
038                    Long userId1 = workflowLog1.getUserId();
039                    Long userId2 = workflowLog2.getUserId();
040    
041                    int value = userId1.compareTo(userId2);
042    
043                    if (value == 0) {
044                            Long workflowLogId1 = workflowLog1.getWorkflowLogId();
045                            Long workflowLogId2 = workflowLog2.getWorkflowLogId();
046    
047                            value = workflowLogId1.compareTo(workflowLogId2);
048                    }
049    
050                    if (_ascending) {
051                            return value;
052                    }
053                    else {
054                            return -value;
055                    }
056            }
057    
058            public boolean isAscending() {
059                    return _ascending;
060            }
061    
062            private boolean _ascending;
063    
064    }