1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.betwixt;
18
19 import java.io.Serializable;
20 import java.math.BigDecimal;
21 import java.math.BigInteger;
22 import java.sql.Date;
23 import java.sql.Time;
24 import java.sql.Timestamp;
25 import java.util.ArrayList;
26 import java.util.Enumeration;
27 import java.util.Iterator;
28 import java.util.List;
29 import java.util.Map;
30
31 import org.apache.commons.logging.Log;
32 import org.apache.commons.logging.LogFactory;
33
34
35
36
37
38
39
40 public class CustomerBean implements Serializable {
41
42
43 private static final Log log = LogFactory.getLog( CustomerBean.class );
44
45 private String id;
46 private String name;
47 private String nickName;
48 private String[] emails;
49 private int[] numbers;
50 private AddressBean address;
51 private Map projectMap;
52 private List locations = new ArrayList();
53 private Date date;
54 private Time time;
55 private Timestamp timestamp;
56 private BigDecimal bigDecimal;
57 private BigInteger bigInteger;
58
59 public CustomerBean() {
60 }
61
62 public String getID() {
63 return id;
64 }
65
66 public String getNickName() {
67 return nickName;
68 }
69
70
71 public String getName() {
72 return name;
73 }
74
75 public String[] getEmails() {
76 return emails;
77 }
78
79 public int[] getNumbers() {
80 return numbers;
81 }
82
83 public AddressBean getAddress() {
84 return address;
85 }
86
87 public Map getProjectMap() {
88 return projectMap;
89 }
90
91 public Iterator getProjectNames() {
92 if ( projectMap == null ) {
93 return null;
94 }
95 return projectMap.keySet().iterator();
96 }
97
98 public Enumeration getProjectURLs() {
99 if ( projectMap == null ) {
100 return null;
101 }
102 return new IteratorEnumeration( projectMap.values().iterator() );
103 }
104
105 public List getLocations() {
106 return locations;
107 }
108
109
110 public String getLocation(int index) {
111 return (String) locations.get(index);
112 }
113
114 public void setID(String id) {
115 this.id = id;
116 }
117
118 public void setName(String name) {
119 this.name = name;
120 }
121
122 public void setNickName(String nickName) {
123 this.nickName = nickName;
124 }
125
126 public void setEmails(String[] emails) {
127 this.emails = emails;
128 }
129
130 public void addEmail(String email) {
131 int newLength = (emails == null) ? 1 : emails.length+1;
132 String[] newArray = new String[newLength];
133 for (int i=0; i< newLength-1; i++) {
134 newArray[i] = emails[i];
135 }
136 newArray[newLength-1] = email;
137 emails = newArray;
138 }
139
140 public void setNumbers(int[] numbers) {
141 this.numbers = numbers;
142 }
143
144 public void addNumber(int number) {
145 if ( log.isDebugEnabled() ) {
146 log.debug( "Adding number: " + number );
147 }
148
149 int newLength = (numbers == null) ? 1 : numbers.length+1;
150 int[] newArray = new int[newLength];
151 for (int i=0; i< newLength-1; i++) {
152 newArray[i] = numbers[i];
153 }
154 newArray[newLength-1] = number;
155 numbers = newArray;
156 }
157
158 public void setAddress(AddressBean address) {
159 this.address = address;
160
161 if ( log.isDebugEnabled() ) {
162 log.debug( "Setting the address to be: " + address );
163 }
164 }
165
166 public void setProjectMap(Map projectMap) {
167 this.projectMap = projectMap;
168 }
169
170 public void addLocation(String location) {
171 locations.add(location);
172 }
173
174
175 public void setLocation(int index, String location) {
176 if ( index == locations.size() ) {
177 locations.add( location );
178 }
179 else {
180 locations.set(index, location);
181 }
182 }
183
184 public String toString() {
185 return "[" + this.getClass().getName() + ": ID=" + id + ", name=" + name
186 + ", address=" + address + "]";
187 }
188
189 public boolean equals( Object obj ) {
190 if ( obj == null ) return false;
191 return this.hashCode() == obj.hashCode();
192 }
193
194 public int hashCode() {
195 return toString().hashCode();
196 }
197
198
199
200
201 public Date getDate() {
202 return date;
203 }
204
205
206
207
208
209 public Time getTime() {
210 return time;
211 }
212
213
214
215
216
217 public Timestamp getTimestamp() {
218 return timestamp;
219 }
220
221
222
223
224
225 public void setDate(Date date) {
226 this.date = date;
227 }
228
229
230
231
232
233 public void setTime(Time time) {
234 this.time = time;
235 }
236
237
238
239
240
241 public void setTimestamp(Timestamp timestamp) {
242 this.timestamp = timestamp;
243 }
244
245
246
247
248
249 public BigDecimal getBigDecimal() {
250 return bigDecimal;
251 }
252
253
254
255
256
257 public BigInteger getBigInteger() {
258 return bigInteger;
259 }
260
261
262
263
264
265 public void setBigDecimal(BigDecimal bigDecimal) {
266 this.bigDecimal = bigDecimal;
267 }
268
269
270
271
272
273 public void setBigInteger(BigInteger bigInteger) {
274 this.bigInteger = bigInteger;
275 }
276
277
278
279
280
281
282
283
284 private static final class IteratorEnumeration implements Enumeration {
285
286
287 private Iterator iterator;
288
289
290
291
292
293
294 public IteratorEnumeration() {
295 super();
296 }
297
298
299
300
301
302
303
304 public IteratorEnumeration( Iterator iterator ) {
305 super();
306 this.iterator = iterator;
307 }
308
309
310
311
312
313
314
315
316
317 public boolean hasMoreElements() {
318 return iterator.hasNext();
319 }
320
321
322
323
324
325
326
327
328 public Object nextElement() {
329 return iterator.next();
330 }
331
332
333
334
335
336
337
338
339
340 public Iterator getIterator() {
341 return iterator;
342 }
343
344
345
346
347
348
349 public void setIterator( Iterator iterator ) {
350 this.iterator = iterator;
351 }
352
353 }
354
355
356 }