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