1 58 59 package org.jfree.data.statistics; 60 61 import java.util.ArrayList ; 62 import java.util.Date ; 63 import java.util.List ; 64 65 import org.jfree.data.Range; 66 import org.jfree.data.RangeInfo; 67 import org.jfree.data.xy.AbstractXYDataset; 68 69 75 public class DefaultBoxAndWhiskerXYDataset extends AbstractXYDataset 76 implements BoxAndWhiskerXYDataset, 77 RangeInfo { 78 79 80 private Comparable seriesKey; 81 82 83 private List dates; 84 85 86 private List items; 87 88 89 private Number minimumRangeValue; 90 91 92 private Number maximumRangeValue; 93 94 95 private Range rangeBounds; 96 97 103 private double outlierCoefficient = 1.5; 104 105 111 private double faroutCoefficient = 2.0; 112 113 121 public DefaultBoxAndWhiskerXYDataset(Comparable seriesKey) { 122 this.seriesKey = seriesKey; 123 this.dates = new ArrayList (); 124 this.items = new ArrayList (); 125 this.minimumRangeValue = null; 126 this.maximumRangeValue = null; 127 this.rangeBounds = null; 128 } 129 130 136 public void add(Date date, BoxAndWhiskerItem item) { 137 this.dates.add(date); 138 this.items.add(item); 139 if (this.minimumRangeValue == null) { 140 this.minimumRangeValue = item.getMinRegularValue(); 141 } 142 else { 143 if (item.getMinRegularValue().doubleValue() 144 < this.minimumRangeValue.doubleValue()) { 145 this.minimumRangeValue = item.getMinRegularValue(); 146 } 147 } 148 if (this.maximumRangeValue == null) { 149 this.maximumRangeValue = item.getMaxRegularValue(); 150 } 151 else { 152 if (item.getMaxRegularValue().doubleValue() 153 > this.maximumRangeValue.doubleValue()) { 154 this.maximumRangeValue = item.getMaxRegularValue(); 155 } 156 } 157 this.rangeBounds = new Range( 158 this.minimumRangeValue.doubleValue(), 159 this.maximumRangeValue.doubleValue() 160 ); 161 } 162 163 170 public Comparable getSeriesKey(int i) { 171 return this.seriesKey; 172 } 173 174 183 public BoxAndWhiskerItem getItem(int series, int item) { 184 return (BoxAndWhiskerItem) this.items.get(item); 185 } 186 187 198 public Number getX(int series, int item) { 199 return new Long (((Date ) this.dates.get(item)).getTime()); 200 } 201 202 212 public Date getXDate(int series, int item) { 213 return (Date ) this.dates.get(item); 214 } 215 216 227 public Number getY(int series, int item) { 228 return new Double (getMeanValue(series, item).doubleValue()); 229 } 230 231 239 public Number getMeanValue(int series, int item) { 240 Number result = null; 241 BoxAndWhiskerItem stats = (BoxAndWhiskerItem) this.items.get(item); 242 if (stats != null) { 243 result = stats.getMean(); 244 } 245 return result; 246 } 247 248 256 public Number getMedianValue(int series, int item) { 257 Number result = null; 258 BoxAndWhiskerItem stats = (BoxAndWhiskerItem) this.items.get(item); 259 if (stats != null) { 260 result = stats.getMedian(); 261 } 262 return result; 263 } 264 265 273 public Number getQ1Value(int series, int item) { 274 Number result = null; 275 BoxAndWhiskerItem stats = (BoxAndWhiskerItem) this.items.get(item); 276 if (stats != null) { 277 result = stats.getQ1(); 278 } 279 return result; 280 } 281 282 290 public Number getQ3Value(int series, int item) { 291 Number result = null; 292 BoxAndWhiskerItem stats = (BoxAndWhiskerItem) this.items.get(item); 293 if (stats != null) { 294 result = stats.getQ3(); 295 } 296 return result; 297 } 298 299 307 public Number getMinRegularValue(int series, int item) { 308 Number result = null; 309 BoxAndWhiskerItem stats = (BoxAndWhiskerItem) this.items.get(item); 310 if (stats != null) { 311 result = stats.getMinRegularValue(); 312 } 313 return result; 314 } 315 316 324 public Number getMaxRegularValue(int series, int item) { 325 Number result = null; 326 BoxAndWhiskerItem stats = (BoxAndWhiskerItem) this.items.get(item); 327 if (stats != null) { 328 result = stats.getMaxRegularValue(); 329 } 330 return result; 331 } 332 333 340 public Number getMinOutlier(int series, int item) { 341 Number result = null; 342 BoxAndWhiskerItem stats = (BoxAndWhiskerItem) this.items.get(item); 343 if (stats != null) { 344 result = stats.getMinOutlier(); 345 } 346 return result; 347 } 348 349 358 public Number getMaxOutlier(int series, int item) { 359 Number result = null; 360 BoxAndWhiskerItem stats = (BoxAndWhiskerItem) this.items.get(item); 361 if (stats != null) { 362 result = stats.getMaxOutlier(); 363 } 364 return result; 365 } 366 367 375 public List getOutliers(int series, int item) { 376 List result = null; 377 BoxAndWhiskerItem stats = (BoxAndWhiskerItem) this.items.get(item); 378 if (stats != null) { 379 result = stats.getOutliers(); 380 } 381 return result; 382 } 383 384 394 public double getOutlierCoefficient() { 395 return this.outlierCoefficient; 396 } 397 398 405 public double getFaroutCoefficient() { 406 return this.faroutCoefficient; 407 } 408 409 416 public int getSeriesCount() { 417 return 1; 418 } 419 420 427 public int getItemCount(int series) { 428 return this.dates.size(); 429 } 430 431 437 public void setOutlierCoefficient(double outlierCoefficient) { 438 this.outlierCoefficient = outlierCoefficient; 439 } 440 441 448 public void setFaroutCoefficient(double faroutCoefficient) { 449 450 if (faroutCoefficient > getOutlierCoefficient()) { 451 this.faroutCoefficient = faroutCoefficient; 452 } 453 else { 454 throw new IllegalArgumentException ("Farout value must be greater " 455 + "than the outlier value, which is currently set at: (" 456 + getOutlierCoefficient() + ")"); 457 } 458 } 459 460 468 public double getRangeLowerBound(boolean includeInterval) { 469 double result = Double.NaN; 470 if (this.minimumRangeValue != null) { 471 result = this.minimumRangeValue.doubleValue(); 472 } 473 return result; 474 } 475 476 484 public double getRangeUpperBound(boolean includeInterval) { 485 double result = Double.NaN; 486 if (this.maximumRangeValue != null) { 487 result = this.maximumRangeValue.doubleValue(); 488 } 489 return result; 490 } 491 492 500 public Range getRangeBounds(boolean includeInterval) { 501 return this.rangeBounds; 502 } 503 504 } 505 | Popular Tags |