1 3 package jodd.introspector; 4 5 import java.lang.reflect.Field ; 6 import java.util.HashMap ; 7 import java.util.Iterator ; 8 9 12 class Fields { 13 14 HashMap fMap = new HashMap (); 15 Field [] allFields; 16 boolean locked = false; 17 18 void addField(String name, Field field) { 19 if (locked == true) { 20 throw new IllegalStateException ("Fields introspection is already finished."); 21 } 22 fMap.put(name, field); 23 } 24 25 void lock() { 26 locked = true; 27 allFields = new Field [fMap.size()]; 28 Iterator i = fMap.values().iterator(); 29 int count = 0; 30 while (i.hasNext()) { 31 allFields[count] = (Field ) i.next(); 32 count++; 33 } 34 } 35 36 38 Field getField(String name) { 39 return (Field ) fMap.get(name); 40 } 41 42 int getCount() { 43 return allFields.length; 44 } 45 46 Field [] getAllFields() { 47 return allFields; 48 } 49 50 } | Popular Tags |