001: /* ===========================================================
002: * JFreeChart : a free chart library for the Java(tm) platform
003: * ===========================================================
004: *
005: * (C) Copyright 2000-2006, by Object Refinery Limited and Contributors.
006: *
007: * Project Info: http://www.jfree.org/jfreechart/index.html
008: *
009: * This library is free software; you can redistribute it and/or modify it
010: * under the terms of the GNU Lesser General Public License as published by
011: * the Free Software Foundation; either version 2.1 of the License, or
012: * (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful, but
015: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
016: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
017: * License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
022: * USA.
023: *
024: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
025: * in the United States and other countries.]
026: *
027: * --------------------
028: * TimePeriodValue.java
029: * --------------------
030: * (C) Copyright 2003-2006, by Object Refinery Limited.
031: *
032: * Original Author: David Gilbert (for Object Refinery Limited);
033: * Contributor(s): -;
034: *
035: * $Id: TimePeriodValue.java,v 1.4.2.2 2006/10/03 15:16:33 mungady Exp $
036: *
037: * Changes
038: * -------
039: * 22-Apr-2003 : Version 1 (DG);
040: * 03-Oct-2006 : Added null argument check to constructor (DG);
041: *
042: */
043:
044: package org.jfree.data.time;
045:
046: import java.io.Serializable;
047:
048: /**
049: * Represents a time period and an associated value.
050: */
051: public class TimePeriodValue implements Cloneable, Serializable {
052:
053: /** For serialization. */
054: private static final long serialVersionUID = 3390443360845711275L;
055:
056: /** The time period. */
057: private TimePeriod period;
058:
059: /** The value associated with the time period. */
060: private Number value;
061:
062: /**
063: * Constructs a new data item.
064: *
065: * @param period the time period (<code>null</code> not permitted).
066: * @param value the value associated with the time period.
067: *
068: * @throws IllegalArgumentException if <code>period</code> is
069: * <code>null</code>.
070: */
071: public TimePeriodValue(TimePeriod period, Number value) {
072: if (period == null) {
073: throw new IllegalArgumentException(
074: "Null 'period' argument.");
075: }
076: this .period = period;
077: this .value = value;
078: }
079:
080: /**
081: * Constructs a new data item.
082: *
083: * @param period the time period (<code>null</code> not permitted).
084: * @param value the value associated with the time period.
085: *
086: * @throws IllegalArgumentException if <code>period</code> is
087: * <code>null</code>.
088: */
089: public TimePeriodValue(TimePeriod period, double value) {
090: this (period, new Double(value));
091: }
092:
093: /**
094: * Returns the time period.
095: *
096: * @return The time period (never <code>null</code>).
097: */
098: public TimePeriod getPeriod() {
099: return this .period;
100: }
101:
102: /**
103: * Returns the value.
104: *
105: * @return The value (possibly <code>null</code>).
106: *
107: * @see #setValue(Number)
108: */
109: public Number getValue() {
110: return this .value;
111: }
112:
113: /**
114: * Sets the value for this data item.
115: *
116: * @param value the new value (<code>null</code> permitted).
117: *
118: * @see #getValue()
119: */
120: public void setValue(Number value) {
121: this .value = value;
122: }
123:
124: /**
125: * Tests this object for equality with the target object.
126: *
127: * @param obj the object (<code>null</code> permitted).
128: *
129: * @return A boolean.
130: */
131: public boolean equals(Object obj) {
132: if (this == obj) {
133: return true;
134: }
135: if (!(obj instanceof TimePeriodValue)) {
136: return false;
137: }
138:
139: TimePeriodValue timePeriodValue = (TimePeriodValue) obj;
140:
141: if (this .period != null ? !this .period
142: .equals(timePeriodValue.period)
143: : timePeriodValue.period != null) {
144: return false;
145: }
146: if (this .value != null ? !this .value
147: .equals(timePeriodValue.value)
148: : timePeriodValue.value != null) {
149: return false;
150: }
151:
152: return true;
153: }
154:
155: /**
156: * Returns a hash code value for the object.
157: *
158: * @return The hashcode
159: */
160: public int hashCode() {
161: int result;
162: result = (this .period != null ? this .period.hashCode() : 0);
163: result = 29 * result
164: + (this .value != null ? this .value.hashCode() : 0);
165: return result;
166: }
167:
168: /**
169: * Clones the object.
170: * <P>
171: * Note: no need to clone the period or value since they are immutable
172: * classes.
173: *
174: * @return A clone.
175: */
176: public Object clone() {
177: Object clone = null;
178: try {
179: clone = super .clone();
180: } catch (CloneNotSupportedException e) { // won't get here...
181: e.printStackTrace();
182: }
183: return clone;
184: }
185:
186: }
|