1 43 44 package org.jfree.data.general; 45 46 import java.io.Serializable ; 47 48 import org.jfree.data.DefaultKeyedValue; 49 import org.jfree.data.KeyedValue; 50 import org.jfree.util.ObjectUtilities; 51 52 55 public class DefaultKeyedValueDataset extends AbstractDataset 56 implements KeyedValueDataset, 57 Serializable { 58 59 60 private static final long serialVersionUID = -8149484339560406750L; 61 62 63 private KeyedValue data; 64 65 68 public DefaultKeyedValueDataset() { 69 this(null); 70 } 71 72 78 public DefaultKeyedValueDataset(Comparable key, Number value) { 79 this(new DefaultKeyedValue(key, value)); 80 } 81 82 88 public DefaultKeyedValueDataset(KeyedValue data) { 89 this.data = data; 90 } 91 92 98 public Comparable getKey() { 99 Comparable result = null; 100 if (this.data != null) { 101 result = this.data.getKey(); 102 } 103 return result; 104 } 105 106 111 public Number getValue() { 112 Number result = null; 113 if (this.data != null) { 114 result = this.data.getValue(); 115 } 116 return result; 117 } 118 119 124 public void updateValue(Number value) { 125 if (this.data == null) { 126 throw new RuntimeException ("updateValue: can't update null."); 127 } 128 setValue(this.data.getKey(), value); 129 } 130 131 138 public void setValue(Comparable key, Number value) { 139 this.data = new DefaultKeyedValue(key, value); 140 notifyListeners(new DatasetChangeEvent(this, this)); 141 } 142 143 150 public boolean equals(Object obj) { 151 152 if (obj == this) { 153 return true; 154 } 155 if (!(obj instanceof KeyedValueDataset)) { 156 return false; 157 } 158 KeyedValueDataset that = (KeyedValueDataset) obj; 159 if (this.data == null) { 160 if (that.getKey() != null || that.getValue() != null) { 161 return false; 162 } 163 return true; 164 } 165 if (!ObjectUtilities.equal(this.data.getKey(), that.getKey())) { 166 return false; 167 } 168 if (!ObjectUtilities.equal(this.data.getValue(), that.getValue())) { 169 return false; 170 } 171 return true; 172 } 173 174 179 public int hashCode() { 180 return (this.data != null ? this.data.hashCode() : 0); 181 } 182 183 191 public Object clone() throws CloneNotSupportedException { 192 DefaultKeyedValueDataset clone 193 = (DefaultKeyedValueDataset) super.clone(); 194 return clone; 195 } 196 197 } 198 | Popular Tags |