KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dspace > app > statistics > Statistics


1 /*
2  * Statistics.java
3  *
4  * Version: $Revision: 1.2 $
5  *
6  * Date: $Date: 2005/04/20 14:22:42 $
7  *
8  * Copyright (c) 2002-2005, Hewlett-Packard Company and Massachusetts
9  * Institute of Technology. All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions are
13  * met:
14  *
15  * - Redistributions of source code must retain the above copyright
16  * notice, this list of conditions and the following disclaimer.
17  *
18  * - Redistributions in binary form must reproduce the above copyright
19  * notice, this list of conditions and the following disclaimer in the
20  * documentation and/or other materials provided with the distribution.
21  *
22  * - Neither the name of the Hewlett-Packard Company nor the name of the
23  * Massachusetts Institute of Technology nor the names of their
24  * contributors may be used to endorse or promote products derived from
25  * this software without specific prior written permission.
26  *
27  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
32  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
33  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
34  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
35  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
36  * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
37  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
38  * DAMAGE.
39  */

40
41 package org.dspace.app.statistics;
42
43 import org.dspace.app.statistics.Stat;
44
45 import java.util.ArrayList JavaDoc;
46 import java.util.List JavaDoc;
47
48 /**
49  * This class provides a wrapper for a related set of statistics. It contains
50  * headers for the Stat key and value pairs for the convenience of displaying
51  * them to users as, for example, HTML table headers. It also holds the
52  * list of statistics, and can have them added to itself individually or in
53  * arrays
54  *
55  * @author Richard Jones
56  */

57 public class Statistics
58 {
59     // FIXME: this class could probably do with some tidying
60

61     /** the header for the statistics type. Useful for outputting to user */
62     private String JavaDoc statName = null;
63     
64     /** the header for the results. Useful for outputting to user */
65     private String JavaDoc resultName = null;
66     
67     /** a list to hold all of the stat elements that this object contains */
68     private List JavaDoc stats = new ArrayList JavaDoc();
69     
70     /** the floor value for this set of statistics */
71     private int floor = 0;
72     
73     /** an explanation of this statistics set */
74     private String JavaDoc explanation = null;
75     
76     /** the main section header for this set of statistics */
77     private String JavaDoc sectionHeader = null;
78     
79     /**
80      * constructor to create new set of statistics
81      */

82     Statistics()
83     {
84         // empty constructor
85
}
86     
87     /**
88      * constructor to create new statistic with relevant headers
89      *
90      * @param statName name of the statistic
91      * @param resultName name of the result
92      */

93     Statistics(String JavaDoc statName, String JavaDoc resultName)
94     {
95         this.statName = statName;
96         this.resultName = resultName;
97     }
98     
99     /**
100      * constructor to create new statistic with relevant headers
101      *
102      * @param statName name of the statistic
103      * @param resultName name of the result
104      */

105     Statistics(String JavaDoc statName, String JavaDoc resultName, int floor)
106     {
107         this.statName = statName;
108         this.resultName = resultName;
109         this.floor = floor;
110     }
111     
112     /**
113      * add an individual statistic to this object
114      *
115      * @param stat a statistic for this object
116      */

117     public void add(Stat stat)
118     {
119         this.stats.add(stat);
120         return;
121     }
122     
123     /**
124      * set the name of the statistic column
125      *
126      * @param name the name of the statistic column
127      */

128     public void setStatName(String JavaDoc name)
129     {
130         this.statName = name;
131     }
132     
133     /**
134      * set the name of the results column
135      *
136      * @param name the name of the results column
137      */

138     public void setResultName(String JavaDoc name)
139     {
140         this.resultName = name;
141     }
142     
143     
144     /**
145      * set the explanatory or clarification information for this block of stats
146      *
147      * @param explanation the explanation for this stat block
148      */

149     public void setExplanation(String JavaDoc explanation)
150     {
151         this.explanation = explanation;
152     }
153     
154     
155     /**
156      * get the explanation or clarification information for this block of stats
157      *
158      * @return the explanation for this stat block
159      */

160     public String JavaDoc getExplanation()
161     {
162         return this.explanation;
163     }
164     
165     
166     /**
167      * set the floor value used in this stat block
168      *
169      * @param floor the floor value for this stat block
170      */

171     public void setFloor(int floor)
172     {
173         this.floor = floor;
174     }
175     
176     
177     /**
178      * get the floor value used in this stat block
179      *
180      * @return the floor value for this stat block
181      */

182     public int getFloor()
183     {
184         return this.floor;
185     }
186     
187     
188     /**
189      * set the header for this particular stats block
190      *
191      * @param header for this stats block
192      */

193     public void setSectionHeader(String JavaDoc header)
194     {
195         this.sectionHeader = header;
196     }
197     
198     
199     /**
200      * get the header for this particular stats block
201      *
202      * @return the header for this stats block
203      */

204     public String JavaDoc getSectionHeader()
205     {
206         return this.sectionHeader;
207     }
208     
209     /**
210      * add an array of statistics to this object
211      *
212      * @param stats an array of statistics
213      */

214     public void add(Stat[] stats)
215     {
216         for (int i = 0; i < stats.length; i++)
217         {
218             this.stats.add(stats[i]);
219         }
220         return;
221     }
222     
223     /**
224      * get an array of statistics back from this object
225      *
226      * @return the statistics array
227      */

228     public Stat[] getStats()
229     {
230         Stat[] myStats = new Stat[stats.size()];
231         myStats = (Stat[]) stats.toArray(myStats);
232         return myStats;
233     }
234     
235     /**
236      * get the name of the statistic
237      *
238      * @return the name of the statistic
239      */

240     public String JavaDoc getStatName()
241     {
242         return statName;
243     }
244     
245     /**
246      * get the name of the result set
247      *
248      * @return the name of the result set
249      */

250     public String JavaDoc getResultName()
251     {
252         return resultName;
253     }
254 }
255
Popular Tags