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