Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
EntityUtils |
|
| 9.0;9 |
1 | package org.kuali.rice.kim.api.entity; | |
2 | ||
3 | ||
4 | import org.apache.commons.collections.CollectionUtils; | |
5 | import org.kuali.rice.kns.bo.DefaultableInactivateable; | |
6 | ||
7 | import java.util.Collection; | |
8 | ||
9 | 0 | public class EntityUtils { |
10 | public static <T extends DefaultableInactivateable> T getDefaultItem( Collection<T> collection ) { | |
11 | // find the default entry | |
12 | 12 | if (CollectionUtils.isEmpty(collection)) { |
13 | 6 | return null; |
14 | } | |
15 | 6 | for ( DefaultableInactivateable 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 ( DefaultableInactivateable item : collection ) { |
22 | 0 | return (T)item; |
23 | } | |
24 | // if neither, return null | |
25 | 0 | return null; |
26 | } | |
27 | } |