1 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 40 public class FieldValues { 41 private Hashtable ht; 42 43 46 public FieldValues() { 47 ht = new Hashtable (); 48 } 49 50 51 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 70 public void clear() { 71 ht.clear(); 72 } 73 74 75 80 public Iterator elements() { 81 return ht.values() 82 .iterator(); 83 } 84 85 86 93 public FieldValue get(String name) { 94 return (FieldValue) ht.get(name); 95 } 96 97 98 103 public Iterator keys() { 104 return ht.keySet() 105 .iterator(); 106 } 107 108 109 114 public void put(FieldValue value) { 115 ht.put(value.getField().getName(), value); 116 } 117 118 119 126 public FieldValue remove(String name) { 127 return (FieldValue) ht.remove(name); 128 } 129 130 131 138 public FieldValue remove(FieldValue value) { 139 return remove(value.getField().getName()); 140 } 141 142 143 148 public int size() { 149 return ht.size(); 150 } 151 152 153 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 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 } 192 | Popular Tags |