1 16 17 package org.springframework.metadata.support; 18 19 import java.lang.reflect.Field ; 20 import java.lang.reflect.Method ; 21 import java.util.Collection ; 22 import java.util.Iterator ; 23 import java.util.LinkedList ; 24 import java.util.List ; 25 26 import org.springframework.metadata.Attributes; 27 28 37 public abstract class AbstractAttributes implements Attributes { 38 39 42 public final Collection getAttributes(Class targetClass, Class filter) { 43 return filter(getAttributes(targetClass), filter); 44 } 45 46 49 private Collection filter(Collection coll, Class filter) { 50 if (filter == null) { 51 return coll; 52 } 53 54 List matches = new LinkedList (); 55 for (Iterator it = coll.iterator(); it.hasNext(); ) { 56 Object next = it.next(); 57 if (filter.isInstance(next)) { 58 matches.add(next); 59 } 60 } 61 return matches; 62 } 63 64 67 public final Collection getAttributes(Method targetMethod, Class filter) { 68 return filter(getAttributes(targetMethod), filter); 69 } 70 71 74 public final Collection getAttributes(Field targetField, Class filter) { 75 return filter(getAttributes(targetField), filter); 76 } 77 78 } 79 | Popular Tags |