1 39 package org.jfree.data; 40 41 import java.io.Serializable ; 42 import java.util.List ; 43 44 49 public class DefaultCategoryDataset extends AbstractDataset 50 implements CategoryDataset, Serializable { 51 52 53 private DefaultKeyedValues2D data; 54 55 58 public DefaultCategoryDataset() { 59 this.data = new DefaultKeyedValues2D(); 60 } 61 62 67 public int getRowCount() { 68 return this.data.getRowCount(); 69 } 70 71 76 public int getColumnCount() { 77 return this.data.getColumnCount(); 78 } 79 80 88 public Number getValue(int row, int column) { 89 return this.data.getValue(row, column); 90 } 91 92 99 public Comparable getRowKey(int row) { 100 return this.data.getRowKey(row); 101 } 102 103 110 public int getRowIndex(Comparable key) { 111 return this.data.getRowIndex(key); 112 } 113 114 119 public List getRowKeys() { 120 return this.data.getRowKeys(); 121 } 122 123 130 public Comparable getColumnKey(int column) { 131 return this.data.getColumnKey(column); 132 } 133 134 141 public int getColumnIndex(Comparable key) { 142 return this.data.getColumnIndex(key); 143 } 144 145 150 public List getColumnKeys() { 151 return this.data.getColumnKeys(); 152 } 153 154 164 public Number getValue(Comparable rowKey, Comparable columnKey) { 165 return this.data.getValue(rowKey, columnKey); 166 } 167 168 175 public void addValue(Number value, Comparable rowKey, Comparable columnKey) { 176 this.data.addValue(value, rowKey, columnKey); 177 fireDatasetChanged(); 178 } 179 180 187 public void addValue(double value, Comparable rowKey, Comparable columnKey) { 188 this.addValue(new Double (value), rowKey, columnKey); 189 } 190 191 198 public void setValue(Number value, Comparable rowKey, Comparable columnKey) { 199 this.data.setValue(value, rowKey, columnKey); 200 fireDatasetChanged(); 201 } 202 203 210 public void setValue(double value, Comparable rowKey, Comparable columnKey) { 211 this.setValue(new Double (value), rowKey, columnKey); 212 } 213 214 222 public void incrementValue(double value, Comparable rowKey, Comparable columnKey) { 223 double existing = 0.0; 224 Number n = getValue(rowKey, columnKey); 225 if (n != null) { 226 existing = n.doubleValue(); 227 } 228 setValue(existing + value, rowKey, columnKey); 229 } 230 231 237 public void removeValue(Comparable rowKey, Comparable columnKey) { 238 this.data.removeValue(rowKey, columnKey); 239 fireDatasetChanged(); 240 } 241 242 247 public void removeRow(int rowIndex) { 248 this.data.removeRow(rowIndex); 249 fireDatasetChanged(); 250 } 251 252 257 public void removeRow(Comparable rowKey) { 258 this.data.removeRow(rowKey); 259 fireDatasetChanged(); 260 } 261 262 267 public void removeColumn(int columnIndex) { 268 this.data.removeColumn(columnIndex); 269 fireDatasetChanged(); 270 } 271 272 277 public void removeColumn(Comparable columnKey) { 278 this.data.removeColumn(columnKey); 279 fireDatasetChanged(); 280 } 281 282 289 public boolean equals(Object o) { 290 291 if (o == null) { 292 return false; 293 } 294 if (o == this) { 295 return true; 296 } 297 298 if (o instanceof CategoryDataset) { 299 CategoryDataset cd = (CategoryDataset) o; 300 boolean b1 = getRowKeys().equals(cd.getRowKeys()); 301 boolean b2 = getColumnKeys().equals(cd.getColumnKeys()); 302 if (b1 && b2) { 303 for (int r = 0; r < getRowCount(); r++) { 304 for (int c = 0; c < getColumnCount(); c++) { 305 Number v1 = getValue(r, c); 306 Number v2 = cd.getValue(r, c); 307 if (v1 == null) { 308 if (v2 != null) { 309 return false; 310 } 311 } 312 else { 313 if (!v1.equals(v2)) { 314 return false; 315 } 316 } 317 318 } 319 } 320 return true; 321 } 322 else { 323 return false; 324 } 325 } 326 327 return false; 328 329 } 330 331 332 } 333 | Popular Tags |