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: * DefaultValueDataset.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: * 27-Mar-2003 : Version 1 (DG); 38: * 18-Aug-2003 : Implemented Cloneable (DG); 39: * 03-Mar-2005 : Implemented PublicCloneable (DG); 40: * ------------- JFREECHART 1.0.x --------------------------------------------- 41: * 30-Jan-2007 : Added explicit super() call in constructor (for clarity) (DG); 42: * 43: */ 44: 45: package org.jfree.data.general; 46: 47: import java.io.Serializable; 48: 49: import org.jfree.util.ObjectUtilities; 50: import org.jfree.util.PublicCloneable; 51: 52: /** 53: * A dataset that stores a single value (that is possibly <code>null</code>). 54: * This class provides a default implementation of the {@link ValueDataset} 55: * interface. 56: */ 57: public class DefaultValueDataset extends AbstractDataset 58: implements ValueDataset, 59: Cloneable, PublicCloneable, 60: Serializable { 61: 62: /** For serialization. */ 63: private static final long serialVersionUID = 8137521217249294891L; 64: 65: /** The value. */ 66: private Number value; 67: 68: /** 69: * Constructs a new dataset, initially empty. 70: */ 71: public DefaultValueDataset() { 72: this(null); 73: } 74: 75: /** 76: * Creates a new dataset with the specified value. 77: * 78: * @param value the value. 79: */ 80: public DefaultValueDataset(double value) { 81: this(new Double(value)); 82: } 83: 84: /** 85: * Creates a new dataset with the specified value. 86: * 87: * @param value the initial value (<code>null</code> permitted). 88: */ 89: public DefaultValueDataset(Number value) { 90: super(); 91: this.value = value; 92: } 93: 94: /** 95: * Returns the value. 96: * 97: * @return The value (possibly <code>null</code>). 98: */ 99: public Number getValue() { 100: return this.value; 101: } 102: 103: /** 104: * Sets the value and sends a {@link DatasetChangeEvent} to all registered 105: * listeners. 106: * 107: * @param value the new value (<code>null</code> permitted). 108: */ 109: public void setValue(Number value) { 110: this.value = value; 111: notifyListeners(new DatasetChangeEvent(this, this)); 112: } 113: 114: /** 115: * Tests this dataset for equality with an arbitrary object. 116: * 117: * @param obj the object (<code>null</code> permitted). 118: * 119: * @return A boolean. 120: */ 121: public boolean equals(Object obj) { 122: if (obj == this) { 123: return true; 124: } 125: if (obj instanceof ValueDataset) { 126: ValueDataset vd = (ValueDataset) obj; 127: return ObjectUtilities.equal(this.value, vd.getValue()); 128: } 129: return false; 130: } 131: 132: /** 133: * Returns a hash code. 134: * 135: * @return A hash code. 136: */ 137: public int hashCode() { 138: return (this.value != null ? this.value.hashCode() : 0); 139: } 140: 141: }