1 44 45 package org.jfree.data.xy; 46 47 import java.util.Arrays ; 48 import java.util.List ; 49 50 import org.jfree.data.general.DatasetChangeEvent; 51 52 62 public class DefaultIntervalXYDataset extends AbstractIntervalXYDataset { 63 64 68 private List seriesKeys; 69 70 75 private List seriesList; 76 77 81 public DefaultIntervalXYDataset() { 82 this.seriesKeys = new java.util.ArrayList (); 83 this.seriesList = new java.util.ArrayList (); 84 } 85 86 91 public int getSeriesCount() { 92 return this.seriesList.size(); 93 } 94 95 106 public Comparable getSeriesKey(int series) { 107 if ((series < 0) || (series >= getSeriesCount())) { 108 throw new IllegalArgumentException ("Series index out of bounds"); 109 } 110 return (Comparable ) this.seriesKeys.get(series); 111 } 112 113 124 public int getItemCount(int series) { 125 if ((series < 0) || (series >= getSeriesCount())) { 126 throw new IllegalArgumentException ("Series index out of bounds"); 127 } 128 double[][] seriesArray = (double[][]) this.seriesList.get(series); 129 return seriesArray[0].length; 130 } 131 132 149 public double getXValue(int series, int item) { 150 double[][] seriesData = (double[][]) this.seriesList.get(series); 151 return seriesData[0][item]; 152 } 153 154 171 public double getYValue(int series, int item) { 172 double[][] seriesData = (double[][]) this.seriesList.get(series); 173 return seriesData[3][item]; 174 } 175 176 193 public double getStartXValue(int series, int item) { 194 double[][] seriesData = (double[][]) this.seriesList.get(series); 195 return seriesData[1][item]; 196 } 197 198 215 public double getEndXValue(int series, int item) { 216 double[][] seriesData = (double[][]) this.seriesList.get(series); 217 return seriesData[2][item]; 218 } 219 220 237 public double getStartYValue(int series, int item) { 238 double[][] seriesData = (double[][]) this.seriesList.get(series); 239 return seriesData[4][item]; 240 } 241 242 259 public double getEndYValue(int series, int item) { 260 double[][] seriesData = (double[][]) this.seriesList.get(series); 261 return seriesData[5][item]; 262 } 263 264 281 public Number getEndX(int series, int item) { 282 return new Double (getEndXValue(series, item)); 283 } 284 285 302 public Number getEndY(int series, int item) { 303 return new Double (getEndYValue(series, item)); 304 } 305 306 323 public Number getStartX(int series, int item) { 324 return new Double (getStartXValue(series, item)); 325 } 326 327 344 public Number getStartY(int series, int item) { 345 return new Double (getStartYValue(series, item)); 346 } 347 348 365 public Number getX(int series, int item) { 366 return new Double (getXValue(series, item)); 367 } 368 369 386 public Number getY(int series, int item) { 387 return new Double (getYValue(series, item)); 388 } 389 390 400 public void addSeries(Comparable seriesKey, double[][] data) { 401 if (seriesKey == null) { 402 throw new IllegalArgumentException ( 403 "The 'seriesKey' cannot be null."); 404 } 405 if (data == null) { 406 throw new IllegalArgumentException ("The 'data' is null."); 407 } 408 if (data.length != 6) { 409 throw new IllegalArgumentException ( 410 "The 'data' array must have length == 6."); 411 } 412 int length = data[0].length; 413 if (length != data[1].length || length != data[2].length 414 || length != data[3].length || length != data[4].length 415 || length != data[5].length) { 416 throw new IllegalArgumentException ( 417 "The 'data' array must contain two arrays with equal length."); 418 } 419 int seriesIndex = indexOf(seriesKey); 420 if (seriesIndex == -1) { this.seriesKeys.add(seriesKey); 422 this.seriesList.add(data); 423 } 424 else { this.seriesList.remove(seriesIndex); 426 this.seriesList.add(seriesIndex, data); 427 } 428 notifyListeners(new DatasetChangeEvent(this, this)); 429 } 430 431 447 public boolean equals(Object obj) { 448 if (obj == this) { 449 return true; 450 } 451 if (!(obj instanceof DefaultIntervalXYDataset)) { 452 return false; 453 } 454 DefaultIntervalXYDataset that = (DefaultIntervalXYDataset) obj; 455 if (!this.seriesKeys.equals(that.seriesKeys)) { 456 return false; 457 } 458 for (int i = 0; i < this.seriesList.size(); i++) { 459 double[][] d1 = (double[][]) this.seriesList.get(i); 460 double[][] d2 = (double[][]) that.seriesList.get(i); 461 double[] d1x = d1[0]; 462 double[] d2x = d2[0]; 463 if (!Arrays.equals(d1x, d2x)) { 464 return false; 465 } 466 double[] d1xs = d1[1]; 467 double[] d2xs = d2[1]; 468 if (!Arrays.equals(d1xs, d2xs)) { 469 return false; 470 } 471 double[] d1xe = d1[2]; 472 double[] d2xe = d2[2]; 473 if (!Arrays.equals(d1xe, d2xe)) { 474 return false; 475 } 476 double[] d1y = d1[3]; 477 double[] d2y = d2[3]; 478 if (!Arrays.equals(d1y, d2y)) { 479 return false; 480 } 481 double[] d1ys = d1[4]; 482 double[] d2ys = d2[4]; 483 if (!Arrays.equals(d1ys, d2ys)) { 484 return false; 485 } 486 double[] d1ye = d1[5]; 487 double[] d2ye = d2[5]; 488 if (!Arrays.equals(d1ye, d2ye)) { 489 return false; 490 } 491 } 492 return true; 493 } 494 495 } 496 | Popular Tags |