| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| EntityUtils | 
  | 
  | 9.0;9 | 
| 1 |  package org.kuali.rice.kim.api.identity; | |
| 2 | ||
| 3 |  import org.apache.commons.collections.CollectionUtils; | |
| 4 |  import org.kuali.rice.core.api.mo.common.Defaultable; | |
| 5 |  import org.kuali.rice.core.api.mo.common.active.Inactivatable; | |
| 6 | ||
| 7 |  import java.util.Collection; | |
| 8 | ||
| 9 | 0 |  public class EntityUtils { | 
| 10 | public static <T extends Defaultable & Inactivatable> T getDefaultItem( Collection<T> collection ) {  | |
| 11 |                  // find the default entry | |
| 12 | 12 | if (CollectionUtils.isEmpty(collection)) {  | 
| 13 | 6 | return null;  | 
| 14 | }  | |
| 15 | 6 |                  for ( T item : collection ) { | 
| 16 | 6 |                          if ( item.isDefaultValue() && item.isActive() ) { | 
| 17 | 6 |                                  return (T)item; | 
| 18 | }  | |
| 19 | }  | |
| 20 |                  // if no default, return the first | |
| 21 | 0 |                  for ( T item : collection ) { | 
| 22 | 0 |                      return (T)item; | 
| 23 | }  | |
| 24 |                  // if neither, return null | |
| 25 | 0 |                  return null; | 
| 26 | }  | |
| 27 | }  |