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.WorkflowDefinition;
019
020
023 public class WorkflowDefinitionNameComparator
024 extends OrderByComparator<WorkflowDefinition> {
025
026 public WorkflowDefinitionNameComparator(
027 boolean ascending, String orderByAsc, String orderByDesc,
028 String[] orderByFields) {
029
030 _ascending = ascending;
031 _orderByAsc = orderByAsc;
032 _orderByDesc = orderByDesc;
033 _orderByFields = orderByFields;
034 }
035
036 @Override
037 public int compare(
038 WorkflowDefinition workflowDefinition1,
039 WorkflowDefinition workflowDefinition2) {
040
041 String name1 = workflowDefinition1.getName();
042 String name2 = workflowDefinition2.getName();
043
044 int value = name1.compareTo(name2);
045
046 if (value == 0) {
047 Integer version1 = workflowDefinition1.getVersion();
048 Integer version2 = workflowDefinition2.getVersion();
049
050 value = version1.compareTo(version2);
051 }
052
053 if (_ascending) {
054 return value;
055 }
056 else {
057 return -value;
058 }
059 }
060
061 @Override
062 public String getOrderBy() {
063 if (isAscending()) {
064 return _orderByAsc;
065 }
066 else {
067 return _orderByDesc;
068 }
069 }
070
071 @Override
072 public String[] getOrderByFields() {
073 return _orderByFields;
074 }
075
076 @Override
077 public boolean isAscending() {
078 return _ascending;
079 }
080
081 private final boolean _ascending;
082 private final String _orderByAsc;
083 private final String _orderByDesc;
084 private final String[] _orderByFields;
085
086 }