KickJava   Java API By Example, From Geeks To Geeks.

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


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.Random JavaDoc;
15
16 import org.apache.commons.lang.builder.CompareToBuilder;
17 import org.apache.commons.lang.builder.ToStringBuilder;
18 import org.apache.commons.lang.builder.ToStringStyle;
19
20
21 /**
22  * A test class that has data that looks more like information that comes back in a report.
23  * @author epesh
24  * @author Fabrizio Giustina
25  * @version $Revision$ ($Author$)
26  */

27 public class ReportableListObject extends Object JavaDoc implements Comparable JavaDoc
28 {
29
30     /**
31      * random number producer.
32      */

33     private static Random JavaDoc random = new Random JavaDoc();
34
35     /**
36      * city names.
37      */

38     private static String JavaDoc[] cities = //
39
{"Roma", "Olympia", "Neapolis", "Carthago"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
40

41     /**
42      * project names.
43      */

44     private static String JavaDoc[] projects = //
45
{"Taxes", "Arts", "Army", "Gladiators"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
46

47     /**
48      * city.
49      */

50     private String JavaDoc city;
51
52     /**
53      * project.
54      */

55     private String JavaDoc project;
56
57     /**
58      * task.
59      */

60     private String JavaDoc task;
61
62     /**
63      * amount.
64      */

65     private double amount;
66
67     /**
68      * count.
69      */

70     private int count;
71
72     /**
73      * Constructor for ReportableListObject.
74      */

75     public ReportableListObject()
76     {
77         this.amount = (random.nextInt(99999) + 1) / 100;
78         this.city = cities[random.nextInt(cities.length)];
79         this.project = projects[random.nextInt(projects.length)];
80         this.task = RandomSampleUtil.getRandomSentence(4);
81         this.count = random.nextInt(10);
82     }
83
84     /**
85      * getter for city.
86      * @return String city
87      */

88     public String JavaDoc getCity()
89     {
90         return this.city;
91     }
92
93     /**
94      * Getter for <code>count</code>.
95      * @return Returns the count.
96      */

97     public int getCount()
98     {
99         return this.count;
100     }
101
102     /**
103      * getter for project.
104      * @return String project
105      */

106     public String JavaDoc getProject()
107     {
108         return this.project;
109     }
110
111     /**
112      * getter for task.
113      * @return String task
114      */

115     public String JavaDoc getTask()
116     {
117         return this.task;
118     }
119
120     /**
121      * getter for amount.
122      * @return double amount
123      */

124     public double getAmount()
125     {
126         return this.amount;
127     }
128
129     /**
130      * @see java.lang.Comparable#compareTo(Object)
131      */

132     public int compareTo(Object JavaDoc object)
133     {
134         ReportableListObject myClass = (ReportableListObject) object;
135         return new CompareToBuilder().append(this.project, myClass.project).append(this.amount, myClass.amount).append(
136             this.city,
137             myClass.city).append(this.task, myClass.task).toComparison();
138     }
139
140     /**
141      * @see java.lang.Object#toString()
142      */

143     public String JavaDoc toString()
144     {
145         return new ToStringBuilder(this, ToStringStyle.SIMPLE_STYLE) //
146
.append("project", this.project) //$NON-NLS-1$
147
.append("amount", this.amount) //$NON-NLS-1$
148
.append("city", this.city) //$NON-NLS-1$
149
.append("task", this.task) //$NON-NLS-1$
150
.toString();
151     }
152
153 }
154
Popular Tags