KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > betwixt > CustomerBean


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.commons.betwixt;
17
18 import java.io.Serializable JavaDoc;
19 import java.math.BigDecimal JavaDoc;
20 import java.math.BigInteger JavaDoc;
21 import java.sql.Date JavaDoc;
22 import java.sql.Time JavaDoc;
23 import java.sql.Timestamp JavaDoc;
24 import java.util.ArrayList JavaDoc;
25 import java.util.Enumeration JavaDoc;
26 import java.util.Iterator JavaDoc;
27 import java.util.List JavaDoc;
28 import java.util.Map JavaDoc;
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: 1.10 $
38   */

39 public class CustomerBean implements Serializable JavaDoc {
40
41     /** Logger */
42     private static final Log log = LogFactory.getLog( CustomerBean.class );
43     
44     private String JavaDoc id;
45     private String JavaDoc name;
46     private String JavaDoc nickName;
47     private String JavaDoc[] emails;
48     private int[] numbers;
49     private AddressBean address;
50     private Map JavaDoc projectMap;
51     private List JavaDoc locations = new ArrayList JavaDoc();
52     private Date JavaDoc date;
53     private Time JavaDoc time;
54     private Timestamp JavaDoc timestamp;
55     private BigDecimal JavaDoc bigDecimal;
56     private BigInteger JavaDoc bigInteger;
57         
58     public CustomerBean() {
59     }
60
61     public String JavaDoc getID() {
62         return id;
63     }
64     
65     public String JavaDoc getNickName() {
66        return nickName;
67     }
68
69     
70     public String JavaDoc getName() {
71         return name;
72     }
73     
74     public String JavaDoc[] 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 JavaDoc getProjectMap() {
87         return projectMap;
88     }
89     
90     public Iterator JavaDoc getProjectNames() {
91         if ( projectMap == null ) {
92             return null;
93         }
94         return projectMap.keySet().iterator();
95     }
96     
97     public Enumeration JavaDoc getProjectURLs() {
98         if ( projectMap == null ) {
99             return null;
100         }
101         return new IteratorEnumeration( projectMap.values().iterator() );
102     }
103     
104     public List JavaDoc getLocations() {
105         return locations;
106     }
107     
108     /** An indexed property */
109     public String JavaDoc getLocation(int index) {
110         return (String JavaDoc) locations.get(index);
111     }
112     
113     public void setID(String JavaDoc id) {
114         this.id = id;
115     }
116     
117     public void setName(String JavaDoc name) {
118         this.name = name;
119     }
120  
121     public void setNickName(String JavaDoc nickName) {
122         this.nickName = nickName;
123     }
124     
125     public void setEmails(String JavaDoc[] emails) {
126         this.emails = emails;
127     }
128     
129     public void addEmail(String JavaDoc email) {
130         int newLength = (emails == null) ? 1 : emails.length+1;
131         String JavaDoc[] newArray = new String JavaDoc[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 JavaDoc projectMap) {
166         this.projectMap = projectMap;
167     }
168     
169     public void addLocation(String JavaDoc location) {
170         locations.add(location);
171     }
172     
173     /** An indexed property */
174     public void setLocation(int index, String JavaDoc location) {
175         if ( index == locations.size() ) {
176             locations.add( location );
177         }
178         else {
179             locations.set(index, location);
180         }
181     }
182
183     public String JavaDoc toString() {
184         return "[" + this.getClass().getName() + ": ID=" + id + ", name=" + name
185                 + ", address=" + address + "]";
186     }
187     
188     public boolean equals( Object JavaDoc 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 JavaDoc getDate() {
201         return date;
202     }
203
204     /**
205      * Returns the time.
206      * @return Time
207      */

208     public Time JavaDoc getTime() {
209         return time;
210     }
211
212     /**
213      * Returns the timestamp.
214      * @return Timestamp
215      */

216     public Timestamp JavaDoc getTimestamp() {
217         return timestamp;
218     }
219
220     /**
221      * Sets the date.
222      * @param date The date to set
223      */

224     public void setDate(Date JavaDoc 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 JavaDoc 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 JavaDoc timestamp) {
241         this.timestamp = timestamp;
242     }
243
244     /**
245      * Returns the bigDecimal.
246      * @return BigDecimal
247      */

248     public BigDecimal JavaDoc getBigDecimal() {
249         return bigDecimal;
250     }
251
252     /**
253      * Returns the bigInteger.
254      * @return BigInteger
255      */

256     public BigInteger JavaDoc getBigInteger() {
257         return bigInteger;
258     }
259
260     /**
261      * Sets the bigDecimal.
262      * @param bigDecimal The bigDecimal to set
263      */

264     public void setBigDecimal(BigDecimal JavaDoc 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 JavaDoc 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 JavaDoc {
284         
285         /** The iterator being decorated. */
286         private Iterator JavaDoc 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 JavaDoc iterator ) {
304             super();
305             this.iterator = iterator;
306         }
307
308         // Iterator interface
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 JavaDoc nextElement() {
328             return iterator.next();
329         }
330
331         // Properties
332
//-------------------------------------------------------------------------
333

334         /**
335          * Returns the underlying iterator.
336          *
337          * @return the underlying iterator
338          */

339         public Iterator JavaDoc 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 JavaDoc iterator ) {
349             this.iterator = iterator;
350         }
351         
352     }
353
354
355 }
356
Popular Tags