1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.dbforms.config;
25
26 import org.dbforms.util.Util;
27
28 import java.util.Hashtable;
29 import java.util.Iterator;
30
31
32
33 /***
34 * New class to deal with a list of FieldValues. <br>
35 * This class uses a delegate pattern: it delegates everything to an Hashtable
36 * to do the necessary type transformations.
37 *
38 * @author hkk
39 */
40 public class FieldValues {
41 private Hashtable ht;
42
43 /***
44 * Creates a new FieldValues object.
45 */
46 public FieldValues() {
47 ht = new Hashtable();
48 }
49
50
51 /***
52 * Creates a new FieldValues object from an input array of FieldValue
53 * objects.
54 *
55 * @param valueArr an array of FieldValue objects
56 */
57 public FieldValues(FieldValue[] valueArr) {
58 ht = new Hashtable();
59
60 for (int i = 0; i < valueArr.length; i++) {
61 if (!Util.isNull(valueArr[i].getFieldValue())) {
62 put(valueArr[i]);
63 }
64 }
65 }
66
67 /***
68 * Clear the internal hash table.
69 */
70 public void clear() {
71 ht.clear();
72 }
73
74
75 /***
76 * Get the Enumeration of the hash table keys.
77 *
78 * @return the Enumeration of the hash table keys
79 */
80 public Iterator elements() {
81 return ht.values()
82 .iterator();
83 }
84
85
86 /***
87 * Get the FieldValue object having the input name.
88 *
89 * @param name Dthe name of the FieldValue object to retrieve
90 *
91 * @return the FieldValue object having the input name
92 */
93 public FieldValue get(String name) {
94 return (FieldValue) ht.get(name);
95 }
96
97
98 /***
99 * Get the Enumeration of the hash table keys.
100 *
101 * @return the Enumeration of the hash table keys
102 */
103 public Iterator keys() {
104 return ht.keySet()
105 .iterator();
106 }
107
108
109 /***
110 * Put the input FieldName object into the internal hash table.
111 *
112 * @param value the FieldValue object to store
113 */
114 public void put(FieldValue value) {
115 ht.put(value.getField().getName(), value);
116 }
117
118
119 /***
120 * removes the from the internal hash table.
121 *
122 * @param name the FieldValue object to remove
123 *
124 * @return DOCUMENT ME!
125 */
126 public FieldValue remove(String name) {
127 return (FieldValue) ht.remove(name);
128 }
129
130
131 /***
132 * removes the from the internal hash table.
133 *
134 * @param value the FieldValue object to remove
135 *
136 * @return DOCUMENT ME!
137 */
138 public FieldValue remove(FieldValue value) {
139 return remove(value.getField().getName());
140 }
141
142
143 /***
144 * Get the size of the internal hash table.
145 *
146 * @return the size of the internal hash table
147 */
148 public int size() {
149 return ht.size();
150 }
151
152
153 /***
154 * Transform this object into a FieldValue array.
155 *
156 * @return the FieldValue array representation of this object
157 */
158 public FieldValue[] toArray() {
159 FieldValue[] result = new FieldValue[0];
160 result = (FieldValue[]) ht.values()
161 .toArray(result);
162
163 return result;
164 }
165
166
167 /***
168 * Dump the input FieldValues object
169 *
170 * @return the string representation of the FieldValues object
171 */
172 public String toString() {
173 StringBuffer sb = new StringBuffer();
174 sb.append("FieldValues size: ")
175 .append(size())
176 .append("; elements are:\n");
177
178 Iterator keys = keys();
179
180 while (keys.hasNext()) {
181 String key = (String) keys.next();
182 FieldValue fValue = get(key);
183 sb.append(key);
184 sb.append(" - ");
185 sb.append(fValue.toString());
186 sb.append("\n");
187 }
188
189 return sb.toString();
190 }
191 }