KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Stat.java
3  *
4  * Version: $Revision: 1.2 $
5  *
6  * Date: $Date: 2005/04/20 14:22:41 $
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 /**
44  * This is a primitive class to represent a single statistic, which will
45  * generally be a key value pair but with the capabilities for being sorted
46  *
47  * Note: this class has a natural ordering that is inconsistent with equals
48  *
49  * @author Richard Jones
50  */

51 public class Stat implements Comparable JavaDoc
52 {
53     // FIXME: this class is functional but a bit messy, and should be neatened
54
// up and completed
55

56     /** the key, which is effectively the text of the statistic */
57     private String JavaDoc key = null;
58     
59     /** the value assigned to the key, generally a count of the key */
60     private int value = 0;
61     
62     /** a reference to an external resource which relates to this statistic */
63     private String JavaDoc reference = null;
64     
65     /** the units that this statistic is in */
66     private String JavaDoc units = null;
67     
68     /**
69      * constructor to create new statistic
70      *
71      * @param key the key for the statistic
72      * @param value the value for the statistic
73      */

74     Stat(String JavaDoc key, int value)
75     {
76         this.key = key;
77         this.value = value;
78     }
79     
80     /**
81      * constructor to create new statistic
82      *
83      * @param key the key for the statistic
84      * @param value the value for the statistic
85      * @param reference the value for the external reference
86      */

87     Stat(String JavaDoc key, int value, String JavaDoc reference)
88     {
89         this.key = key;
90         this.value = value;
91         this.reference = reference;
92     }
93     
94     /**
95      * set the units of this statistic
96      *
97      * @param unit the units that this statistic is measured in
98      */

99     public void setUnits(String JavaDoc unit)
100     {
101         this.units = unit;
102     }
103     
104     /**
105      * get the unts that this statistic is measured in
106      *
107      * @return the units this statistic is measured in
108      */

109     public String JavaDoc getUnits()
110     {
111         return this.units;
112     }
113     
114     /**
115      * get the value of the statistic
116      *
117      * @return the value of this statistic
118      */

119     public int getValue()
120     {
121         return this.value;
122     }
123     
124     
125     /**
126      * get the key (text describing) the statistic
127      *
128      * @return the key for this statistic
129      */

130     public String JavaDoc getKey()
131     {
132         return this.key;
133     }
134     
135     
136     /**
137      * get the reference to related statistic information
138      *
139      * @return the reference for this statistic
140      */

141     public String JavaDoc getReference()
142     {
143         return this.reference;
144     }
145     
146     
147     /**
148      * set the reference information
149      *
150      * @param key the key for this statistic
151      */

152     public void setKey(String JavaDoc key)
153     {
154         this.key = key;
155     }
156     
157     
158     /**
159      * set the reference information
160      *
161      * @param reference the reference for this statistic
162      */

163     public void setReference(String JavaDoc reference)
164     {
165         this.reference = reference;
166     }
167     
168     
169     /**
170      * compare the current object to the given object returning -1 if o is less
171      * than the current object, 0 if they are the same, and +1 if o is greater
172      * than the current object.
173      *
174      * @param o the object to compare to the current one
175      *
176      * @return +1, 0, -1 if o is less than, equal to, or greater than the
177      * current object value.
178      */

179     public int compareTo(Object JavaDoc o)
180     {
181         int objectValue = ((Stat) o).getValue();
182         
183         if (objectValue < this.getValue())
184         {
185             return -1;
186         }
187         else if (objectValue == this.getValue())
188         {
189             return 0;
190         }
191         else if (objectValue > this.getValue())
192         {
193             return 1;
194         }
195         
196         return 0;
197     }
198     
199 }
200
Popular Tags