001    /**
002     * Copyright (c) 2000-2010 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.WorkflowInstance;
019    
020    import java.util.Date;
021    
022    /**
023     * @author Shuyang Zhou
024     */
025    public abstract class BaseWorkflowInstanceEndDateComparator
026            extends OrderByComparator {
027    
028            public BaseWorkflowInstanceEndDateComparator() {
029                    this(false);
030            }
031    
032            public BaseWorkflowInstanceEndDateComparator(boolean ascending) {
033                    _ascending = ascending;
034            }
035    
036            public int compare(Object obj1, Object obj2) {
037                    WorkflowInstance workflowInstance1 = (WorkflowInstance)obj1;
038                    WorkflowInstance workflowInstance2 = (WorkflowInstance)obj2;
039    
040                    Date endDate1 = workflowInstance1.getEndDate();
041                    Date endDate2 = workflowInstance2.getEndDate();
042    
043                    int value = endDate1.compareTo(endDate2);
044    
045                    if (value == 0) {
046                            Long workflowInstanceId1 =
047                                    workflowInstance1.getWorkflowInstanceId();
048                            Long workflowInstanceId2 =
049                                    workflowInstance2.getWorkflowInstanceId();
050    
051                            value = workflowInstanceId1.compareTo(workflowInstanceId2);
052                    }
053    
054                    if (_ascending) {
055                            return value;
056                    }
057                    else {
058                            return -value;
059                    }
060            }
061    
062            public boolean isAscending() {
063                    return _ascending;
064            }
065    
066            private boolean _ascending;
067    
068    }