KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dbforms > config > FieldValues


1 /*
2  * $Header: /cvsroot/jdbforms/dbforms/src/org/dbforms/config/FieldValues.java,v 1.8 2004/08/18 12:25:55 hkollmann Exp $
3  * $Revision: 1.8 $
4  * $Date: 2004/08/18 12:25:55 $
5  *
6  * DbForms - a Rapid Application Development Framework
7  * Copyright (C) 2001 Joachim Peer <joepeer@excite.com>
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22  */

23
24 package org.dbforms.config;
25
26 import org.dbforms.util.Util;
27
28 import java.util.Hashtable JavaDoc;
29 import java.util.Iterator JavaDoc;
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 JavaDoc ht;
42
43    /**
44     * Creates a new FieldValues object.
45     */

46    public FieldValues() {
47       ht = new Hashtable JavaDoc();
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 JavaDoc();
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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc toString() {
173       StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
174       sb.append("FieldValues size: ")
175         .append(size())
176         .append("; elements are:\n");
177
178       Iterator JavaDoc keys = keys();
179
180       while (keys.hasNext()) {
181          String JavaDoc key = (String JavaDoc) 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 }
192
Popular Tags