001    package org.kuali.rice.kim.api.identity;
002    
003    import org.apache.commons.collections.CollectionUtils;
004    import org.kuali.rice.core.api.mo.common.Defaultable;
005    import org.kuali.rice.core.api.mo.common.active.Inactivatable;
006    
007    import java.util.Collection;
008    
009    public class EntityUtils {
010    
011        private EntityUtils() {
012            throw new UnsupportedOperationException("do not call.");
013        }
014    
015        public static <T extends Defaultable & Inactivatable> T getDefaultItem( Collection<T> collection ) {
016                    // find the default entry
017            if (CollectionUtils.isEmpty(collection)) {
018                return null;
019            }
020                    for ( T item : collection ) {
021                            if ( item.isDefaultValue() && item.isActive() ) {
022                                    return (T)item;
023                            }
024                    }
025                    // if no default, return the first
026                    for ( T item : collection ) {
027                        return item;
028                    }
029                    // if neither, return null
030                    return null;
031            }
032    }