001: /*
002: * Statistics.java
003: *
004: * Version: $Revision: 1189 $
005: *
006: * Date: $Date: 2005-04-20 09:23:44 -0500 (Wed, 20 Apr 2005) $
007: *
008: * Copyright (c) 2002-2005, Hewlett-Packard Company and Massachusetts
009: * Institute of Technology. All rights reserved.
010: *
011: * Redistribution and use in source and binary forms, with or without
012: * modification, are permitted provided that the following conditions are
013: * met:
014: *
015: * - Redistributions of source code must retain the above copyright
016: * notice, this list of conditions and the following disclaimer.
017: *
018: * - Redistributions in binary form must reproduce the above copyright
019: * notice, this list of conditions and the following disclaimer in the
020: * documentation and/or other materials provided with the distribution.
021: *
022: * - Neither the name of the Hewlett-Packard Company nor the name of the
023: * Massachusetts Institute of Technology nor the names of their
024: * contributors may be used to endorse or promote products derived from
025: * this software without specific prior written permission.
026: *
027: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
028: * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
029: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
030: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
031: * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
032: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
033: * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
034: * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
035: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
036: * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
037: * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
038: * DAMAGE.
039: */
040:
041: package org.dspace.app.statistics;
042:
043: import org.dspace.app.statistics.Stat;
044:
045: import java.util.ArrayList;
046: import java.util.List;
047:
048: /**
049: * This class provides a wrapper for a related set of statistics. It contains
050: * headers for the Stat key and value pairs for the convenience of displaying
051: * them to users as, for example, HTML table headers. It also holds the
052: * list of statistics, and can have them added to itself individually or in
053: * arrays
054: *
055: * @author Richard Jones
056: */
057: public class Statistics {
058: // FIXME: this class could probably do with some tidying
059:
060: /** the header for the statistics type. Useful for outputting to user */
061: private String statName = null;
062:
063: /** the header for the results. Useful for outputting to user */
064: private String resultName = null;
065:
066: /** a list to hold all of the stat elements that this object contains */
067: private List stats = new ArrayList();
068:
069: /** the floor value for this set of statistics */
070: private int floor = 0;
071:
072: /** an explanation of this statistics set */
073: private String explanation = null;
074:
075: /** the main section header for this set of statistics */
076: private String sectionHeader = null;
077:
078: /**
079: * constructor to create new set of statistics
080: */
081: Statistics() {
082: // empty constructor
083: }
084:
085: /**
086: * constructor to create new statistic with relevant headers
087: *
088: * @param statName name of the statistic
089: * @param resultName name of the result
090: */
091: Statistics(String statName, String resultName) {
092: this .statName = statName;
093: this .resultName = resultName;
094: }
095:
096: /**
097: * constructor to create new statistic with relevant headers
098: *
099: * @param statName name of the statistic
100: * @param resultName name of the result
101: */
102: Statistics(String statName, String resultName, int floor) {
103: this .statName = statName;
104: this .resultName = resultName;
105: this .floor = floor;
106: }
107:
108: /**
109: * add an individual statistic to this object
110: *
111: * @param stat a statistic for this object
112: */
113: public void add(Stat stat) {
114: this .stats.add(stat);
115: return;
116: }
117:
118: /**
119: * set the name of the statistic column
120: *
121: * @param name the name of the statistic column
122: */
123: public void setStatName(String name) {
124: this .statName = name;
125: }
126:
127: /**
128: * set the name of the results column
129: *
130: * @param name the name of the results column
131: */
132: public void setResultName(String name) {
133: this .resultName = name;
134: }
135:
136: /**
137: * set the explanatory or clarification information for this block of stats
138: *
139: * @param explanation the explanation for this stat block
140: */
141: public void setExplanation(String explanation) {
142: this .explanation = explanation;
143: }
144:
145: /**
146: * get the explanation or clarification information for this block of stats
147: *
148: * @return the explanation for this stat block
149: */
150: public String getExplanation() {
151: return this .explanation;
152: }
153:
154: /**
155: * set the floor value used in this stat block
156: *
157: * @param floor the floor value for this stat block
158: */
159: public void setFloor(int floor) {
160: this .floor = floor;
161: }
162:
163: /**
164: * get the floor value used in this stat block
165: *
166: * @return the floor value for this stat block
167: */
168: public int getFloor() {
169: return this .floor;
170: }
171:
172: /**
173: * set the header for this particular stats block
174: *
175: * @param header for this stats block
176: */
177: public void setSectionHeader(String header) {
178: this .sectionHeader = header;
179: }
180:
181: /**
182: * get the header for this particular stats block
183: *
184: * @return the header for this stats block
185: */
186: public String getSectionHeader() {
187: return this .sectionHeader;
188: }
189:
190: /**
191: * add an array of statistics to this object
192: *
193: * @param stats an array of statistics
194: */
195: public void add(Stat[] stats) {
196: for (int i = 0; i < stats.length; i++) {
197: this .stats.add(stats[i]);
198: }
199: return;
200: }
201:
202: /**
203: * get an array of statistics back from this object
204: *
205: * @return the statistics array
206: */
207: public Stat[] getStats() {
208: Stat[] myStats = new Stat[stats.size()];
209: myStats = (Stat[]) stats.toArray(myStats);
210: return myStats;
211: }
212:
213: /**
214: * get the name of the statistic
215: *
216: * @return the name of the statistic
217: */
218: public String getStatName() {
219: return statName;
220: }
221:
222: /**
223: * get the name of the result set
224: *
225: * @return the name of the result set
226: */
227: public String getResultName() {
228: return resultName;
229: }
230: }
|