1 16 package org.apache.commons.attributes; 17 18 import java.lang.reflect.Field ; 19 import java.lang.reflect.Constructor ; 20 import java.lang.reflect.Method ; 21 import java.util.Collection ; 22 import java.util.Collections ; 23 import java.util.ArrayList ; 24 import java.util.HashMap ; 25 import java.util.HashSet ; 26 import java.util.Iterator ; 27 import java.util.List ; 28 import java.util.Map ; 29 import java.util.WeakHashMap ; 30 31 34 public class AttributeUtil { 35 36 48 public static Collection getClassesWithAttributeType (Collection classes, Class attributeClass) { 49 if (classes == null) { 50 throw new NullPointerException ("classes"); 51 } 52 53 if (attributeClass == null) { 54 throw new NullPointerException ("attributeClass"); 55 } 56 57 ArrayList result = new ArrayList (); 58 Iterator iter = classes.iterator (); 59 while (iter.hasNext ()) { 60 Class clazz = (Class ) iter.next (); 61 if (clazz != null) { 62 if (Attributes.hasAttributeType (clazz, attributeClass)) { 63 result.add (clazz); 64 } 65 } 66 } 67 68 return result; 69 } 70 71 83 public static Collection getObjectsWithAttributeType (Collection objects, Class attributeClass) { 84 if (objects == null) { 85 throw new NullPointerException ("objects"); 86 } 87 88 if (attributeClass == null) { 89 throw new NullPointerException ("attributeClass"); 90 } 91 92 ArrayList result = new ArrayList (); 93 Iterator iter = objects.iterator (); 94 while (iter.hasNext ()) { 95 Object object = iter.next (); 96 if (object != null) { 97 Class clazz = object.getClass (); 98 if (Attributes.hasAttributeType (clazz, attributeClass)) { 99 result.add (object); 100 } 101 } 102 } 103 104 return result; 105 } 106 } | Popular Tags |