| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| ActionListPriorityComparator |
|
| 2.5;2.5 |
| 1 | /* | |
| 2 | * Copyright 2005-2007 The Kuali Foundation | |
| 3 | * | |
| 4 | * | |
| 5 | * Licensed under the Educational Community License, Version 2.0 (the "License"); | |
| 6 | * you may not use this file except in compliance with the License. | |
| 7 | * You may obtain a copy of the License at | |
| 8 | * | |
| 9 | * http://www.opensource.org/licenses/ecl2.php | |
| 10 | * | |
| 11 | * Unless required by applicable law or agreed to in writing, software | |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 | * See the License for the specific language governing permissions and | |
| 15 | * limitations under the License. | |
| 16 | */ | |
| 17 | package org.kuali.rice.kew.actionlist.dao.impl; | |
| 18 | ||
| 19 | import java.util.Comparator; | |
| 20 | ||
| 21 | import org.kuali.rice.kew.actionitem.ActionItem; | |
| 22 | import org.kuali.rice.kew.actionitem.ActionItemComparator; | |
| 23 | ||
| 24 | ||
| 25 | /** | |
| 26 | * Compares an action item to another action item and determines if one | |
| 27 | * item has a higher priority than the other. | |
| 28 | * Therefore, calling code needs to ensure that the document and user on the item | |
| 29 | * are the same. If action items for different documents are passed in, then the | |
| 30 | * compare method should always return 0. | |
| 31 | * | |
| 32 | * If the response returned from compare is less than 0, it means the first argument is | |
| 33 | * lower priority than the second. If a value greater than 0 is returned it means the | |
| 34 | * first argument has a higher priority then the second. If the result returned is 0, then | |
| 35 | * the two action items have the same priority. | |
| 36 | * | |
| 37 | * @author Kuali Rice Team (rice.collab@kuali.org) | |
| 38 | */ | |
| 39 | 0 | public class ActionListPriorityComparator implements Comparator { |
| 40 | ||
| 41 | 0 | private ActionItemComparator itemComparator = new ActionItemComparator(); |
| 42 | ||
| 43 | public int compare(Object object1, Object object2) throws ClassCastException { | |
| 44 | 0 | ActionItem actionItem1 = (ActionItem)object1; |
| 45 | 0 | ActionItem actionItem2 = (ActionItem)object2; |
| 46 | 0 | if (requiresComparison(actionItem1, actionItem2)) { |
| 47 | 0 | return itemComparator.compare(object1, object2); |
| 48 | } | |
| 49 | 0 | return 0; |
| 50 | } | |
| 51 | ||
| 52 | /** | |
| 53 | * Returns whether or not the two action items require comparison. The Action List only operates | |
| 54 | * on Action Items for a single user and we only care about comparing the action items if they are | |
| 55 | * on the same document and for the same user. | |
| 56 | */ | |
| 57 | protected boolean requiresComparison(ActionItem actionItem1, ActionItem actionItem2) { | |
| 58 | 0 | return actionItem1.getDocumentId().equals(actionItem2.getDocumentId()) && |
| 59 | actionItem1.getPrincipalId().equals(actionItem2.getPrincipalId()); | |
| 60 | } | |
| 61 | ||
| 62 | } |