1 46 47 package org.jfree.data; 48 49 import java.io.Serializable ; 50 import java.util.Collections ; 51 import java.util.List ; 52 53 58 public class DefaultPieDataset extends AbstractDataset 59 implements PieDataset, Cloneable , Serializable { 60 61 62 private DefaultKeyedValues data; 63 64 67 public DefaultPieDataset() { 68 69 this.data = new DefaultKeyedValues(); 70 71 } 72 73 78 public DefaultPieDataset(KeyedValues data) { 79 80 this.data = new DefaultKeyedValues(); 81 for (int i = 0; i < data.getItemCount(); i++) { 82 this.data.addValue(data.getKey(i), data.getValue(i)); 83 } 84 } 85 86 91 public int getItemCount() { 92 return this.data.getItemCount(); 93 } 94 95 100 public List getKeys() { 101 return Collections.unmodifiableList(this.data.getKeys()); 102 } 103 104 111 public Comparable getKey(int item) { 112 113 Comparable result = null; 114 if (getItemCount() > item) { 115 result = this.data.getKey(item); 116 } 117 return result; 118 119 } 120 121 128 public int getIndex(Comparable key) { 129 130 return this.data.getIndex(key); 131 132 } 133 134 141 public Number getValue(int item) { 142 143 Number result = null; 144 if (getItemCount() > item) { 145 result = this.data.getValue(item); 146 } 147 return result; 148 149 } 150 151 158 public Number getValue(Comparable key) { 159 160 if (key == null) { 162 throw new IllegalArgumentException ("PieDataset: null key not allowed."); 163 } 164 165 return this.data.getValue(key); 167 168 } 169 170 176 public void setValue(Comparable key, Number value) { 177 178 this.data.setValue(key, value); 179 fireDatasetChanged(); 180 181 } 182 183 189 public void setValue(Comparable key, double value) { 190 191 setValue(key, new Double (value)); 192 193 } 194 195 202 public boolean equals(Object o) { 203 204 if (o == null) { 205 return false; 206 } 207 if (o == this) { 208 return true; 209 } 210 211 if (o instanceof PieDataset) { 212 PieDataset pd = (PieDataset) o; 213 int count = getItemCount(); 214 for (int i = 0; i < count; i++) { 215 Comparable k1 = getKey(i); 216 Comparable k2 = pd.getKey(i); 217 if (k1.equals(k2)) { 218 Number v1 = getValue(i); 219 Number v2 = pd.getValue(i); 220 if (v1 == null) { 221 if (v2 != null) { 222 return false; 223 } 224 } 225 else { 226 if (!v1.equals(v2)) { 227 return false; 228 } 229 } 230 } 231 else { 232 return false; 233 } 234 } 235 return true; 236 } 237 238 return false; 239 240 } 241 242 250 public Object clone() throws CloneNotSupportedException { 251 DefaultPieDataset clone = (DefaultPieDataset) super.clone(); 252 clone.data = (DefaultKeyedValues) this.data.clone(); 253 return clone; 254 } 255 256 } 257 | Popular Tags |