1 49 50 package org.jfree.data.statistics; 51 52 import java.util.List ; 53 54 import org.jfree.data.KeyedObjects2D; 55 import org.jfree.data.Range; 56 import org.jfree.data.RangeInfo; 57 import org.jfree.data.general.AbstractDataset; 58 import org.jfree.util.ObjectUtilities; 59 60 66 public class DefaultBoxAndWhiskerCategoryDataset extends AbstractDataset 67 implements BoxAndWhiskerCategoryDataset, RangeInfo { 68 69 70 protected KeyedObjects2D data; 71 72 73 private Number minimumRangeValue; 74 75 76 private Number maximumRangeValue; 77 78 79 private Range rangeBounds; 80 81 84 public DefaultBoxAndWhiskerCategoryDataset() { 85 this.data = new KeyedObjects2D(); 86 this.minimumRangeValue = null; 87 this.maximumRangeValue = null; 88 this.rangeBounds = new Range(0.0, 0.0); 89 } 90 91 100 public void add(List list, Comparable rowKey, Comparable columnKey) { 101 BoxAndWhiskerItem item 102 = BoxAndWhiskerCalculator.calculateBoxAndWhiskerStatistics(list); 103 add(item, rowKey, columnKey); 104 } 105 106 114 public void add(BoxAndWhiskerItem item, 115 Comparable rowKey, 116 Comparable columnKey) { 117 118 this.data.addObject(item, rowKey, columnKey); 119 double minval = item.getMinOutlier().doubleValue(); 120 double maxval = item.getMaxOutlier().doubleValue(); 121 122 if (this.maximumRangeValue == null) { 123 this.maximumRangeValue = new Double (maxval); 124 } 125 else if (maxval > this.maximumRangeValue.doubleValue()) { 126 this.maximumRangeValue = new Double (maxval); 127 } 128 129 if (this.minimumRangeValue == null) { 130 this.minimumRangeValue = new Double (minval); 131 } 132 else if (minval < this.minimumRangeValue.doubleValue()) { 133 this.minimumRangeValue = new Double (minval); 134 } 135 136 this.rangeBounds = new Range( 137 this.minimumRangeValue.doubleValue(), 138 this.maximumRangeValue.doubleValue() 139 ); 140 141 fireDatasetChanged(); 142 143 } 144 145 153 public BoxAndWhiskerItem getItem(int row, int column) { 154 return (BoxAndWhiskerItem) this.data.getObject(row, column); 155 } 156 157 165 public Number getValue(int row, int column) { 166 return getMedianValue(row, column); 167 } 168 169 177 public Number getValue(Comparable rowKey, Comparable columnKey) { 178 return getMedianValue(rowKey, columnKey); 179 } 180 181 189 public Number getMeanValue(int row, int column) { 190 191 Number result = null; 192 BoxAndWhiskerItem item = (BoxAndWhiskerItem) this.data.getObject( 193 row, column 194 ); 195 if (item != null) { 196 result = item.getMean(); 197 } 198 return result; 199 200 } 201 202 210 public Number getMeanValue(Comparable rowKey, Comparable columnKey) { 211 212 Number result = null; 213 BoxAndWhiskerItem item = (BoxAndWhiskerItem) this.data.getObject( 214 rowKey, columnKey 215 ); 216 if (item != null) { 217 result = item.getMean(); 218 } 219 return result; 220 221 } 222 223 231 public Number getMedianValue(int row, int column) { 232 Number result = null; 233 BoxAndWhiskerItem item = (BoxAndWhiskerItem) this.data.getObject( 234 row, column 235 ); 236 if (item != null) { 237 result = item.getMedian(); 238 } 239 return result; 240 } 241 242 250 public Number getMedianValue(Comparable rowKey, Comparable columnKey) { 251 Number result = null; 252 BoxAndWhiskerItem item = (BoxAndWhiskerItem) this.data.getObject( 253 rowKey, columnKey 254 ); 255 if (item != null) { 256 result = item.getMedian(); 257 } 258 return result; 259 } 260 261 269 public Number getQ1Value(int row, int column) { 270 Number result = null; 271 BoxAndWhiskerItem item = (BoxAndWhiskerItem) this.data.getObject( 272 row, column 273 ); 274 if (item != null) { 275 result = item.getQ1(); 276 } 277 return result; 278 } 279 280 288 public Number getQ1Value(Comparable rowKey, Comparable columnKey) { 289 Number result = null; 290 BoxAndWhiskerItem item = (BoxAndWhiskerItem) this.data.getObject( 291 rowKey, columnKey 292 ); 293 if (item != null) { 294 result = item.getQ1(); 295 } 296 return result; 297 } 298 299 307 public Number getQ3Value(int row, int column) { 308 Number result = null; 309 BoxAndWhiskerItem item = (BoxAndWhiskerItem) this.data.getObject( 310 row, column 311 ); 312 if (item != null) { 313 result = item.getQ3(); 314 } 315 return result; 316 } 317 318 326 public Number getQ3Value(Comparable rowKey, Comparable columnKey) { 327 Number result = null; 328 BoxAndWhiskerItem item = (BoxAndWhiskerItem) this.data.getObject( 329 rowKey, columnKey 330 ); 331 if (item != null) { 332 result = item.getQ3(); 333 } 334 return result; 335 } 336 337 344 public int getColumnIndex(Comparable key) { 345 return this.data.getColumnIndex(key); 346 } 347 348 355 public Comparable getColumnKey(int column) { 356 return this.data.getColumnKey(column); 357 } 358 359 364 public List getColumnKeys() { 365 return this.data.getColumnKeys(); 366 } 367 368 375 public int getRowIndex(Comparable key) { 376 return this.data.getRowIndex(key); 377 } 378 379 386 public Comparable getRowKey(int row) { 387 return this.data.getRowKey(row); 388 } 389 390 395 public List getRowKeys() { 396 return this.data.getRowKeys(); 397 } 398 399 404 public int getRowCount() { 405 return this.data.getRowCount(); 406 } 407 408 413 public int getColumnCount() { 414 return this.data.getColumnCount(); 415 } 416 417 425 public double getRangeLowerBound(boolean includeInterval) { 426 double result = Double.NaN; 427 if (this.minimumRangeValue != null) { 428 result = this.minimumRangeValue.doubleValue(); 429 } 430 return result; 431 } 432 433 441 public double getRangeUpperBound(boolean includeInterval) { 442 double result = Double.NaN; 443 if (this.maximumRangeValue != null) { 444 result = this.maximumRangeValue.doubleValue(); 445 } 446 return result; 447 } 448 449 457 public Range getRangeBounds(boolean includeInterval) { 458 return this.rangeBounds; 459 } 460 461 469 public Number getMinRegularValue(int row, int column) { 470 471 Number result = null; 472 BoxAndWhiskerItem item = (BoxAndWhiskerItem) this.data.getObject( 473 row, column 474 ); 475 if (item != null) { 476 result = item.getMinRegularValue(); 477 } 478 return result; 479 480 } 481 482 490 public Number getMinRegularValue(Comparable rowKey, Comparable columnKey) { 491 492 Number result = null; 493 BoxAndWhiskerItem item = (BoxAndWhiskerItem) this.data.getObject( 494 rowKey, columnKey 495 ); 496 if (item != null) { 497 result = item.getMinRegularValue(); 498 } 499 return result; 500 501 } 502 503 511 public Number getMaxRegularValue(int row, int column) { 512 513 Number result = null; 514 BoxAndWhiskerItem item = (BoxAndWhiskerItem) this.data.getObject( 515 row, column 516 ); 517 if (item != null) { 518 result = item.getMaxRegularValue(); 519 } 520 return result; 521 522 } 523 524 532 public Number getMaxRegularValue(Comparable rowKey, Comparable columnKey) { 533 534 Number result = null; 535 BoxAndWhiskerItem item = (BoxAndWhiskerItem) this.data.getObject( 536 rowKey, columnKey 537 ); 538 if (item != null) { 539 result = item.getMaxRegularValue(); 540 } 541 return result; 542 543 } 544 545 553 public Number getMinOutlier(int row, int column) { 554 555 Number result = null; 556 BoxAndWhiskerItem item = (BoxAndWhiskerItem) this.data.getObject( 557 row, column 558 ); 559 if (item != null) { 560 result = item.getMinOutlier(); 561 } 562 return result; 563 564 } 565 566 574 public Number getMinOutlier(Comparable rowKey, Comparable columnKey) { 575 576 Number result = null; 577 BoxAndWhiskerItem item = (BoxAndWhiskerItem) this.data.getObject( 578 rowKey, columnKey 579 ); 580 if (item != null) { 581 result = item.getMinOutlier(); 582 } 583 return result; 584 585 } 586 587 595 public Number getMaxOutlier(int row, int column) { 596 597 Number result = null; 598 BoxAndWhiskerItem item = (BoxAndWhiskerItem) this.data.getObject( 599 row, column 600 ); 601 if (item != null) { 602 result = item.getMaxOutlier(); 603 } 604 return result; 605 606 } 607 608 616 public Number getMaxOutlier(Comparable rowKey, Comparable columnKey) { 617 618 Number result = null; 619 BoxAndWhiskerItem item = (BoxAndWhiskerItem) this.data.getObject( 620 rowKey, columnKey 621 ); 622 if (item != null) { 623 result = item.getMaxOutlier(); 624 } 625 return result; 626 627 } 628 629 637 public List getOutliers(int row, int column) { 638 639 List result = null; 640 BoxAndWhiskerItem item = (BoxAndWhiskerItem) this.data.getObject( 641 row, column 642 ); 643 if (item != null) { 644 result = item.getOutliers(); 645 } 646 return result; 647 648 } 649 650 658 public List getOutliers(Comparable rowKey, Comparable columnKey) { 659 660 List result = null; 661 BoxAndWhiskerItem item = (BoxAndWhiskerItem) this.data.getObject( 662 rowKey, columnKey 663 ); 664 if (item != null) { 665 result = item.getOutliers(); 666 } 667 return result; 668 669 } 670 671 678 public boolean equals(Object obj) { 679 680 if (obj == null) { 681 return false; 682 } 683 684 if (obj == this) { 685 return true; 686 } 687 688 if (obj instanceof DefaultBoxAndWhiskerCategoryDataset) { 689 DefaultBoxAndWhiskerCategoryDataset dataset 690 = (DefaultBoxAndWhiskerCategoryDataset) obj; 691 return ObjectUtilities.equal(this.data, dataset.data); 692 } 693 694 return false; 695 } 696 697 } 698 | Popular Tags |