KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > data > DefaultValueDataset


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

38
39 package org.jfree.data;
40
41 import java.io.Serializable JavaDoc;
42
43 import org.jfree.util.ObjectUtils;
44
45 /**
46  * A default implementation of the {@link ValueDataset} interface.
47  *
48  * @author David Gilbert
49  */

50 public class DefaultValueDataset extends AbstractDataset
51                                  implements ValueDataset, Cloneable JavaDoc, Serializable JavaDoc {
52
53     /** The value. */
54     private Number JavaDoc value;
55
56     /**
57      * Constructs a new dataset, initially empty.
58      */

59     public DefaultValueDataset() {
60
61         this(null);
62
63     }
64     
65     /**
66      * Creates a new dataset.
67      *
68      * @param value the value.
69      */

70     public DefaultValueDataset(double value) {
71         this(new Double JavaDoc(value));
72     }
73
74     /**
75      * Creates a new dataset.
76      *
77      * @param value the initial value.
78      */

79     public DefaultValueDataset(Number JavaDoc value) {
80         this.value = value;
81     }
82
83     /**
84      * Returns the value.
85      *
86      * @return the value.
87      */

88     public Number JavaDoc getValue() {
89         return this.value;
90     }
91
92     /**
93      * Sets the value. A {@link DatasetChangeEvent} is sent to all registered listeners.
94      *
95      * @param value the new value.
96      */

97     public void setValue(Number JavaDoc value) {
98         this.value = value;
99         notifyListeners(new DatasetChangeEvent(this, this));
100     }
101
102     /**
103      * Tests this dataset for equality with an arbitrary object.
104      *
105      * @param obj the object.
106      *
107      * @return A boolean.
108      */

109     public boolean equals(Object JavaDoc obj) {
110
111         if (obj == null) {
112             return false;
113         }
114
115         if (obj == this) {
116             return true;
117         }
118
119         if (obj instanceof ValueDataset) {
120             ValueDataset vd = (ValueDataset) obj;
121             return ObjectUtils.equal(this.value, vd.getValue());
122         }
123
124         return false;
125     }
126
127 }
128
Popular Tags