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 class WorkflowInstanceEndDateComparator extends OrderByComparator {
026
027 public WorkflowInstanceEndDateComparator(
028 boolean ascending, String orderByAsc, String orderByDesc,
029 String[] orderByFields) {
030
031 _ascending = ascending;
032 _orderByAsc = orderByAsc;
033 _orderByDesc = orderByDesc;
034 _orderByFields = orderByFields;
035 }
036
037 @Override
038 public int compare(Object obj1, Object obj2) {
039 WorkflowInstance workflowInstance1 = (WorkflowInstance)obj1;
040 WorkflowInstance workflowInstance2 = (WorkflowInstance)obj2;
041
042 Date endDate1 = workflowInstance1.getEndDate();
043 Date endDate2 = workflowInstance2.getEndDate();
044
045 int value = endDate1.compareTo(endDate2);
046
047 if (value == 0) {
048 Long workflowInstanceId1 =
049 workflowInstance1.getWorkflowInstanceId();
050 Long workflowInstanceId2 =
051 workflowInstance2.getWorkflowInstanceId();
052
053 value = workflowInstanceId1.compareTo(workflowInstanceId2);
054 }
055
056 if (_ascending) {
057 return value;
058 }
059 else {
060 return -value;
061 }
062 }
063
064 @Override
065 public String getOrderBy() {
066 if (isAscending()) {
067 return _orderByAsc;
068 }
069 else {
070 return _orderByDesc;
071 }
072 }
073
074 @Override
075 public String[] getOrderByFields() {
076 return _orderByFields;
077 }
078
079 @Override
080 public boolean isAscending() {
081 return _ascending;
082 }
083
084 private boolean _ascending;
085 private String _orderByAsc;
086 private String _orderByDesc;
087 private String[] _orderByFields;
088
089 }