001
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
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 @Override
037 public int compare(Object obj1, Object obj2) {
038 WorkflowInstance workflowInstance1 = (WorkflowInstance)obj1;
039 WorkflowInstance workflowInstance2 = (WorkflowInstance)obj2;
040
041 Date endDate1 = workflowInstance1.getEndDate();
042 Date endDate2 = workflowInstance2.getEndDate();
043
044 int value = endDate1.compareTo(endDate2);
045
046 if (value == 0) {
047 Long workflowInstanceId1 =
048 workflowInstance1.getWorkflowInstanceId();
049 Long workflowInstanceId2 =
050 workflowInstance2.getWorkflowInstanceId();
051
052 value = workflowInstanceId1.compareTo(workflowInstanceId2);
053 }
054
055 if (_ascending) {
056 return value;
057 }
058 else {
059 return -value;
060 }
061 }
062
063 @Override
064 public boolean isAscending() {
065 return _ascending;
066 }
067
068 private boolean _ascending;
069
070 }