001 /** 002 * Copyright 2005-2012 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.kuali.rice.kim.api.identity; 017 018 import org.apache.commons.collections.CollectionUtils; 019 import org.kuali.rice.core.api.mo.common.Defaultable; 020 import org.kuali.rice.core.api.mo.common.active.Inactivatable; 021 022 import java.util.Collection; 023 024 public class EntityUtils { 025 026 private EntityUtils() { 027 throw new UnsupportedOperationException("do not call."); 028 } 029 030 public static <T extends Defaultable & Inactivatable> T getDefaultItem( Collection<T> collection ) { 031 // find the default entry 032 if (CollectionUtils.isEmpty(collection)) { 033 return null; 034 } 035 for ( T item : collection ) { 036 if ( item.isDefaultValue() && item.isActive() ) { 037 return (T)item; 038 } 039 } 040 // if no default, return the first 041 for ( T item : collection ) { 042 return item; 043 } 044 // if neither, return null 045 return null; 046 } 047 }