KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > data > time > TimePeriodValue


1 /* ===========================================================
2  * JFreeChart : a free chart library for the Java(tm) platform
3  * ===========================================================
4  *
5  * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
6  *
7  * Project Info: http://www.jfree.org/jfreechart/index.html
8  *
9  * This library is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU Lesser General Public License as published by
11  * the Free Software Foundation; either version 2.1 of the License, or
12  * (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17  * License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with this library; if not, write to the Free Software Foundation,
21  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
24  * in the United States and other countries.]
25  *
26  * --------------------
27  * TimePeriodValue.java
28  * --------------------
29  * (C) Copyright 2003-2005, by Object Refinery Limited.
30  *
31  * Original Author: David Gilbert (for Object Refinery Limited);
32  * Contributor(s): -;
33  *
34  * $Id: TimePeriodValue.java,v 1.4 2005/05/19 10:35:27 mungady Exp $
35  *
36  * Changes
37  * -------
38  * 22-Apr-2003 : Version 1 (DG);
39  *
40  */

41
42 package org.jfree.data.time;
43
44 import java.io.Serializable JavaDoc;
45
46 /**
47  * Represents a time period and an associated value.
48  */

49 public class TimePeriodValue implements Cloneable JavaDoc, Serializable JavaDoc {
50
51     /** For serialization. */
52     private static final long serialVersionUID = 3390443360845711275L;
53     
54     /** The time period. */
55     private TimePeriod period;
56
57     /** The value associated with the time period. */
58     private Number JavaDoc value;
59
60     /**
61      * Constructs a new data item.
62      *
63      * @param period the time period.
64      * @param value the value associated with the time period.
65      */

66     public TimePeriodValue(TimePeriod period, Number JavaDoc value) {
67         this.period = period;
68         this.value = value;
69     }
70
71     /**
72      * Constructs a new data pair.
73      *
74      * @param period the time period.
75      * @param value the value associated with the time period.
76      */

77     public TimePeriodValue(TimePeriod period, double value) {
78         this(period, new Double JavaDoc(value));
79     }
80
81     /**
82      * Returns the time period.
83      *
84      * @return The time period.
85      */

86     public TimePeriod getPeriod() {
87         return this.period;
88     }
89
90     /**
91      * Returns the value.
92      *
93      * @return The value (possibly <code>null</code>).
94      */

95     public Number JavaDoc getValue() {
96         return this.value;
97     }
98
99     /**
100      * Sets the value for this data item.
101      *
102      * @param value the new value (<code>null</code> permitted).
103      */

104     public void setValue(Number JavaDoc value) {
105         this.value = value;
106     }
107
108     /**
109      * Tests this object for equality with the target object.
110      *
111      * @param obj the object (<code>null</code> permitted).
112      *
113      * @return A boolean.
114      */

115     public boolean equals(Object JavaDoc obj) {
116         if (this == obj) {
117             return true;
118         }
119         if (!(obj instanceof TimePeriodValue)) {
120             return false;
121         }
122
123         TimePeriodValue timePeriodValue = (TimePeriodValue) obj;
124
125         if (this.period != null ? !this.period.equals(timePeriodValue.period)
126                 : timePeriodValue.period != null) {
127             return false;
128         }
129         if (this.value != null ? !this.value.equals(timePeriodValue.value)
130                 : timePeriodValue.value != null) {
131             return false;
132         }
133
134         return true;
135     }
136
137     /**
138      * Returns a hash code value for the object.
139      *
140      * @return The hashcode
141      */

142     public int hashCode() {
143         int result;
144         result = (this.period != null ? this.period.hashCode() : 0);
145         result = 29 * result + (this.value != null ? this.value.hashCode() : 0);
146         return result;
147     }
148
149     /**
150      * Clones the object.
151      * <P>
152      * Note: no need to clone the period or value since they are immutable
153      * classes.
154      *
155      * @return A clone.
156      */

157     public Object JavaDoc clone() {
158         Object JavaDoc clone = null;
159         try {
160             clone = super.clone();
161         }
162         catch (CloneNotSupportedException JavaDoc e) { // won't get here...
163
System.err.println("Operation not supported.");
164         }
165         return clone;
166
167     }
168
169 }
170
Popular Tags