1 46 47 package org.jfree.data.category; 48 49 import java.io.Serializable ; 50 import java.util.List ; 51 52 import org.jfree.data.DefaultKeyedValues2D; 53 import org.jfree.data.UnknownKeyException; 54 import org.jfree.data.general.AbstractDataset; 55 import org.jfree.data.general.DatasetChangeEvent; 56 57 60 public class DefaultCategoryDataset extends AbstractDataset 61 implements CategoryDataset, Serializable { 62 63 64 private static final long serialVersionUID = -8168173757291644622L; 65 66 67 private DefaultKeyedValues2D data; 68 69 72 public DefaultCategoryDataset() { 73 this.data = new DefaultKeyedValues2D(); 74 } 75 76 81 public int getRowCount() { 82 return this.data.getRowCount(); 83 } 84 85 90 public int getColumnCount() { 91 return this.data.getColumnCount(); 92 } 93 94 102 public Number getValue(int row, int column) { 103 return this.data.getValue(row, column); 104 } 105 106 113 public Comparable getRowKey(int row) { 114 return this.data.getRowKey(row); 115 } 116 117 124 public int getRowIndex(Comparable key) { 125 return this.data.getRowIndex(key); 126 } 127 128 133 public List getRowKeys() { 134 return this.data.getRowKeys(); 135 } 136 137 144 public Comparable getColumnKey(int column) { 145 return this.data.getColumnKey(column); 146 } 147 148 155 public int getColumnIndex(Comparable key) { 156 return this.data.getColumnIndex(key); 157 } 158 159 164 public List getColumnKeys() { 165 return this.data.getColumnKeys(); 166 } 167 168 178 public Number getValue(Comparable rowKey, Comparable columnKey) { 179 return this.data.getValue(rowKey, columnKey); 180 } 181 182 189 public void addValue(Number value, Comparable rowKey, 190 Comparable columnKey) { 191 this.data.addValue(value, rowKey, columnKey); 192 fireDatasetChanged(); 193 } 194 195 202 public void addValue(double value, Comparable rowKey, 203 Comparable columnKey) { 204 addValue(new Double (value), rowKey, columnKey); 205 } 206 207 215 public void setValue(Number value, Comparable rowKey, 216 Comparable columnKey) { 217 this.data.setValue(value, rowKey, columnKey); 218 fireDatasetChanged(); 219 } 220 221 229 public void setValue(double value, Comparable rowKey, 230 Comparable columnKey) { 231 setValue(new Double (value), rowKey, columnKey); 232 } 233 234 244 public void incrementValue(double value, 245 Comparable rowKey, 246 Comparable columnKey) { 247 double existing = 0.0; 248 Number n = getValue(rowKey, columnKey); 249 if (n != null) { 250 existing = n.doubleValue(); 251 } 252 setValue(existing + value, rowKey, columnKey); 253 } 254 255 261 public void removeValue(Comparable rowKey, Comparable columnKey) { 262 this.data.removeValue(rowKey, columnKey); 263 fireDatasetChanged(); 264 } 265 266 271 public void removeRow(int rowIndex) { 272 this.data.removeRow(rowIndex); 273 fireDatasetChanged(); 274 } 275 276 281 public void removeRow(Comparable rowKey) { 282 this.data.removeRow(rowKey); 283 fireDatasetChanged(); 284 } 285 286 291 public void removeColumn(int columnIndex) { 292 this.data.removeColumn(columnIndex); 293 fireDatasetChanged(); 294 } 295 296 301 public void removeColumn(Comparable columnKey) { 302 this.data.removeColumn(columnKey); 303 fireDatasetChanged(); 304 } 305 306 310 public void clear() { 311 this.data.clear(); 312 fireDatasetChanged(); 313 } 314 315 322 public boolean equals(Object obj) { 323 324 if (obj == this) { 325 return true; 326 } 327 328 if (!(obj instanceof CategoryDataset)) { 329 return false; 330 } 331 332 CategoryDataset that = (CategoryDataset) obj; 333 if (!getRowKeys().equals(that.getRowKeys())) { 334 return false; 335 } 336 337 if (!getColumnKeys().equals(that.getColumnKeys())) { 338 return false; 339 } 340 341 int rowCount = getRowCount(); 342 int colCount = getColumnCount(); 343 for (int r = 0; r < rowCount; r++) { 344 for (int c = 0; c < colCount; c++) { 345 Number v1 = getValue(r, c); 346 Number v2 = that.getValue(r, c); 347 if (v1 == null) { 348 if (v2 != null) { 349 return false; 350 } 351 } 352 else if (!v1.equals(v2)) { 353 return false; 354 } 355 } 356 } 357 return true; 358 } 359 360 365 public int hashCode() { 366 return this.data.hashCode(); 367 } 368 369 } 370 | Popular Tags |