KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > displaytag > sample > ListObject


1 /**
2  * Licensed under the Artistic License; you may not use this file
3  * except in compliance with the License.
4  * You may obtain a copy of the License at
5  *
6  * http://displaytag.sourceforge.net/license.html
7  *
8  * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
9  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
10  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
11  */

12 package org.displaytag.sample;
13
14 import java.util.ArrayList JavaDoc;
15 import java.util.Date JavaDoc;
16 import java.util.List JavaDoc;
17 import java.util.Random JavaDoc;
18
19 import org.apache.commons.lang.StringUtils;
20 import org.apache.commons.lang.builder.ToStringBuilder;
21 import org.apache.commons.lang.builder.ToStringStyle;
22
23
24 /**
25  * Just a test class that returns columns of data that are useful for testing out the ListTag class and ListColumn
26  * class.
27  * @author epesh
28  * @author Fabrizio Giustina
29  * @version $Revision$ ($Author$)
30  */

31 public class ListObject
32 {
33
34     /**
35      * random number generator.
36      */

37     private static Random JavaDoc random = new Random JavaDoc();
38
39     /**
40      * id.
41      */

42     private int id = -1;
43
44     /**
45      * name.
46      */

47     private String JavaDoc name;
48
49     /**
50      * email.
51      */

52     private String JavaDoc email;
53
54     /**
55      * date.
56      */

57     private Date JavaDoc date;
58
59     /**
60      * money.
61      */

62     private double money;
63
64     /**
65      * description.
66      */

67     private String JavaDoc description;
68
69     /**
70      * long description.
71      */

72     private String JavaDoc longDescription;
73
74     /**
75      * status.
76      */

77     private String JavaDoc status;
78
79     /**
80      * url.
81      */

82     private String JavaDoc url;
83
84     /**
85      * sub list used to test nested tables.
86      */

87     private List JavaDoc subList;
88
89     /**
90      * Constructor for ListObject.
91      */

92     public ListObject()
93     {
94         this.id = random.nextInt(99998) + 1;
95         this.money = (random.nextInt(999998) + 1) / 100;
96
97         String JavaDoc firstName = RandomSampleUtil.getRandomWord();
98         String JavaDoc lastName = RandomSampleUtil.getRandomWord();
99
100         this.name = StringUtils.capitalize(firstName) + ' ' + StringUtils.capitalize(lastName);
101
102         this.email = firstName + '-' + lastName + '@' + RandomSampleUtil.getRandomWord() + ".com"; //$NON-NLS-1$
103

104         this.date = RandomSampleUtil.getRandomDate();
105
106         this.description = RandomSampleUtil.getRandomWord() + ' ' //
107
+ RandomSampleUtil.getRandomWord() + "..."; //$NON-NLS-1$
108

109         this.longDescription = RandomSampleUtil.getRandomSentence(10);
110
111         this.status = RandomSampleUtil.getRandomWord().toUpperCase();
112
113         // added sublist for testing of nested tables
114
this.subList = new ArrayList JavaDoc();
115         this.subList.add(new SubListItem());
116         this.subList.add(new SubListItem());
117         this.subList.add(new SubListItem());
118
119         this.url = "http://www." + lastName + ".org/"; //$NON-NLS-1$ //$NON-NLS-2$
120
}
121
122     /**
123      * getter for id.
124      * @return int id
125      */

126     public int getId()
127     {
128         return this.id;
129     }
130
131     /**
132      * setter for id.
133      * @param value int id
134      */

135     public void setId(int value)
136     {
137         this.id = value;
138     }
139
140     /**
141      * getter for name.
142      * @return String name
143      */

144     public String JavaDoc getName()
145     {
146         return this.name;
147     }
148
149     /**
150      * getter for email.
151      * @return String email
152      */

153     public String JavaDoc getEmail()
154     {
155         return this.email;
156     }
157
158     /**
159      * setter for email.
160      * @param value String email
161      */

162     public void setEmail(String JavaDoc value)
163     {
164         this.email = value;
165     }
166
167     /**
168      * getter for date.
169      * @return Date
170      */

171     public Date JavaDoc getDate()
172     {
173         return (Date JavaDoc) this.date.clone();
174     }
175
176     /**
177      * getter for money.
178      * @return double money
179      */

180     public double getMoney()
181     {
182         return this.money;
183     }
184
185     /**
186      * getter for description.
187      * @return String description
188      */

189     public String JavaDoc getDescription()
190     {
191         return this.description;
192     }
193
194     /**
195      * getter for long description.
196      * @return String long description
197      */

198     public String JavaDoc getLongDescription()
199     {
200         return this.longDescription;
201     }
202
203     /**
204      * getter for status.
205      * @return String status
206      */

207     public String JavaDoc getStatus()
208     {
209         return this.status;
210     }
211
212     /**
213      * getter for url.
214      * @return String url
215      */

216     public String JavaDoc getUrl()
217     {
218         return this.url;
219     }
220
221     /**
222      * test for null values.
223      * @return null
224      */

225     public String JavaDoc getNullValue()
226     {
227         return null;
228     }
229
230     /**
231      * Returns a simple string representation of the object.
232      * @return String simple representation of the object
233      */

234     public String JavaDoc toString()
235     {
236         return "ListObject(" + this.id + ")"; //$NON-NLS-1$ //$NON-NLS-2$
237
}
238
239     /**
240      * Returns a detailed string representation of the object.
241      * @return String detailed representation of the object
242      */

243     public String JavaDoc toDetailedString()
244     {
245         return "ID: " //$NON-NLS-1$
246
+ this.id + "\n" //$NON-NLS-1$
247
+ "Name: " //$NON-NLS-1$
248
+ this.name + "\n" //$NON-NLS-1$
249
+ "Email: " //$NON-NLS-1$
250
+ this.email + "\n" //$NON-NLS-1$
251
+ "Date: " //$NON-NLS-1$
252
+ this.date + "\n" //$NON-NLS-1$
253
+ "Money: " //$NON-NLS-1$
254
+ this.money + "\n" //$NON-NLS-1$
255
+ "Description: " //$NON-NLS-1$
256
+ this.description + "\n" //$NON-NLS-1$
257
+ "Status: " //$NON-NLS-1$
258
+ this.status + "\n" //$NON-NLS-1$
259
+ "URL: " //$NON-NLS-1$
260
+ this.url + "\n"; //$NON-NLS-1$
261
}
262
263     /**
264      * Returns the subList.
265      * @return List
266      */

267     public List JavaDoc getSubList()
268     {
269         return this.subList;
270     }
271
272     /**
273      * Inner class used in testing nested tables.
274      * @author Fabrizio Giustina
275      */

276     public static class SubListItem
277     {
278
279         /**
280          * name.
281          */

282         private String JavaDoc itemName;
283
284         /**
285          * email.
286          */

287         private String JavaDoc itemEmail;
288
289         /**
290          * Constructor for SubListItem.
291          */

292         public SubListItem()
293         {
294             this.itemName = RandomSampleUtil.getRandomWord();
295             this.itemEmail = RandomSampleUtil.getRandomEmail();
296         }
297
298         /**
299          * getter for name.
300          * @return String name
301          */

302         public String JavaDoc getName()
303         {
304             return this.itemName;
305         }
306
307         /**
308          * getter for email.
309          * @return String
310          */

311         public String JavaDoc getEmail()
312         {
313             return this.itemEmail;
314         }
315
316         /**
317          * @see java.lang.Object#toString()
318          */

319         public String JavaDoc toString()
320         {
321             return new ToStringBuilder(this, ToStringStyle.SIMPLE_STYLE) //
322
.append("name", this.itemName) //$NON-NLS-1$
323
.append("email", this.itemEmail) //$NON-NLS-1$
324
.toString();
325         }
326     }
327
328 }
329
Popular Tags