1 package org.springframework.samples.petclinic.util; 2 3 import java.util.Collection ; 4 import java.util.Iterator ; 5 6 import org.springframework.orm.ObjectRetrievalFailureException; 7 import org.springframework.samples.petclinic.Entity; 8 9 18 public abstract class EntityUtils { 19 20 29 public static Entity getById(Collection entities, Class entityClass, int entityId) 30 throws ObjectRetrievalFailureException { 31 32 for (Iterator it = entities.iterator(); it.hasNext();) { 33 Entity entity = (Entity) it.next(); 34 if (entity.getId().intValue() == entityId && entityClass.isInstance(entity)) { 35 return entity; 36 } 37 } 38 throw new ObjectRetrievalFailureException(entityClass, new Integer (entityId)); 39 } 40 41 } 42 | Popular Tags |