KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jodd > introspector > Fields


1 // Copyright (c) 2003-2007, Jodd Team (jodd.sf.net). All Rights Reserved.
2

3 package jodd.introspector;
4
5 import java.lang.reflect.Field JavaDoc;
6 import java.util.HashMap JavaDoc;
7 import java.util.Iterator JavaDoc;
8
9 /**
10  * Fields map collection.
11  */

12 class Fields {
13
14     HashMap JavaDoc fMap = new HashMap JavaDoc();
15     Field JavaDoc[] allFields;
16     boolean locked = false;
17
18     void addField(String JavaDoc name, Field JavaDoc field) {
19         if (locked == true) {
20             throw new IllegalStateException JavaDoc("Fields introspection is already finished.");
21         }
22         fMap.put(name, field);
23     }
24
25     void lock() {
26         locked = true;
27         allFields = new Field JavaDoc[fMap.size()];
28         Iterator JavaDoc i = fMap.values().iterator();
29         int count = 0;
30         while (i.hasNext()) {
31             allFields[count] = (Field JavaDoc) i.next();
32             count++;
33         }
34     }
35
36     // ---------------------------------------------------------------- get
37

38     Field JavaDoc getField(String JavaDoc name) {
39         return (Field JavaDoc) fMap.get(name);
40     }
41
42     int getCount() {
43         return allFields.length;
44     }
45
46     Field JavaDoc[] getAllFields() {
47         return allFields;
48     }
49
50 }
Popular Tags