Frames | No Frames |
1: /* =========================================================== 2: * JFreeChart : a free chart library for the Java(tm) platform 3: * =========================================================== 4: * 5: * (C) Copyright 2000-2007, 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 20: * License along with this library; if not, write to the Free Software 21: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22: * USA. 23: * 24: * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 25: * in the United States and other countries.] 26: * 27: * -------------------- 28: * TimePeriodValue.java 29: * -------------------- 30: * (C) Copyright 2003-2007, by Object Refinery Limited. 31: * 32: * Original Author: David Gilbert (for Object Refinery Limited); 33: * Contributor(s): -; 34: * 35: * Changes 36: * ------- 37: * 22-Apr-2003 : Version 1 (DG); 38: * 03-Oct-2006 : Added null argument check to constructor (DG); 39: * 40: */ 41: 42: package org.jfree.data.time; 43: 44: import java.io.Serializable; 45: 46: /** 47: * Represents a time period and an associated value. 48: */ 49: public class TimePeriodValue implements Cloneable, Serializable { 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 value; 59: 60: /** 61: * Constructs a new data item. 62: * 63: * @param period the time period (<code>null</code> not permitted). 64: * @param value the value associated with the time period. 65: * 66: * @throws IllegalArgumentException if <code>period</code> is 67: * <code>null</code>. 68: */ 69: public TimePeriodValue(TimePeriod period, Number value) { 70: if (period == null) { 71: throw new IllegalArgumentException("Null 'period' argument."); 72: } 73: this.period = period; 74: this.value = value; 75: } 76: 77: /** 78: * Constructs a new data item. 79: * 80: * @param period the time period (<code>null</code> not permitted). 81: * @param value the value associated with the time period. 82: * 83: * @throws IllegalArgumentException if <code>period</code> is 84: * <code>null</code>. 85: */ 86: public TimePeriodValue(TimePeriod period, double value) { 87: this(period, new Double(value)); 88: } 89: 90: /** 91: * Returns the time period. 92: * 93: * @return The time period (never <code>null</code>). 94: */ 95: public TimePeriod getPeriod() { 96: return this.period; 97: } 98: 99: /** 100: * Returns the value. 101: * 102: * @return The value (possibly <code>null</code>). 103: * 104: * @see #setValue(Number) 105: */ 106: public Number getValue() { 107: return this.value; 108: } 109: 110: /** 111: * Sets the value for this data item. 112: * 113: * @param value the new value (<code>null</code> permitted). 114: * 115: * @see #getValue() 116: */ 117: public void setValue(Number value) { 118: this.value = value; 119: } 120: 121: /** 122: * Tests this object for equality with the target object. 123: * 124: * @param obj the object (<code>null</code> permitted). 125: * 126: * @return A boolean. 127: */ 128: public boolean equals(Object obj) { 129: if (this == obj) { 130: return true; 131: } 132: if (!(obj instanceof TimePeriodValue)) { 133: return false; 134: } 135: 136: TimePeriodValue timePeriodValue = (TimePeriodValue) obj; 137: 138: if (this.period != null ? !this.period.equals(timePeriodValue.period) 139: : timePeriodValue.period != null) { 140: return false; 141: } 142: if (this.value != null ? !this.value.equals(timePeriodValue.value) 143: : timePeriodValue.value != null) { 144: return false; 145: } 146: 147: return true; 148: } 149: 150: /** 151: * Returns a hash code value for the object. 152: * 153: * @return The hashcode 154: */ 155: public int hashCode() { 156: int result; 157: result = (this.period != null ? this.period.hashCode() : 0); 158: result = 29 * result + (this.value != null ? this.value.hashCode() : 0); 159: return result; 160: } 161: 162: /** 163: * Clones the object. 164: * <P> 165: * Note: no need to clone the period or value since they are immutable 166: * classes. 167: * 168: * @return A clone. 169: */ 170: public Object clone() { 171: Object clone = null; 172: try { 173: clone = super.clone(); 174: } 175: catch (CloneNotSupportedException e) { // won't get here... 176: e.printStackTrace(); 177: } 178: return clone; 179: } 180: 181: }