1 45 46 package org.jfree.data.xy; 47 48 import java.util.ArrayList ; 49 import java.util.Arrays ; 50 import java.util.List ; 51 52 import org.jfree.data.DomainOrder; 53 import org.jfree.data.general.DatasetChangeEvent; 54 55 61 public class DefaultXYZDataset extends AbstractXYZDataset 62 implements XYZDataset { 63 64 68 private List seriesKeys; 69 70 75 private List seriesList; 76 77 81 public DefaultXYZDataset() { 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 121 public int indexOf(Comparable seriesKey) { 122 return this.seriesKeys.indexOf(seriesKey); 123 } 124 125 132 public DomainOrder getDomainOrder() { 133 return DomainOrder.NONE; 134 } 135 136 147 public int getItemCount(int series) { 148 if ((series < 0) || (series >= getSeriesCount())) { 149 throw new IllegalArgumentException ("Series index out of bounds"); 150 } 151 double[][] seriesArray = (double[][]) this.seriesList.get(series); 152 return seriesArray[0].length; 153 } 154 155 172 public double getXValue(int series, int item) { 173 double[][] seriesData = (double[][]) this.seriesList.get(series); 174 return seriesData[0][item]; 175 } 176 177 194 public Number getX(int series, int item) { 195 return new Double (getXValue(series, item)); 196 } 197 198 215 public double getYValue(int series, int item) { 216 double[][] seriesData = (double[][]) this.seriesList.get(series); 217 return seriesData[1][item]; 218 } 219 220 237 public Number getY(int series, int item) { 238 return new Double (getYValue(series, item)); 239 } 240 241 258 public double getZValue(int series, int item) { 259 double[][] seriesData = (double[][]) this.seriesList.get(series); 260 return seriesData[2][item]; 261 } 262 263 280 public Number getZ(int series, int item) { 281 return new Double (getZValue(series, item)); 282 } 283 284 295 public void addSeries(Comparable seriesKey, double[][] data) { 296 if (seriesKey == null) { 297 throw new IllegalArgumentException ( 298 "The 'seriesKey' cannot be null."); 299 } 300 if (data == null) { 301 throw new IllegalArgumentException ("The 'data' is null."); 302 } 303 if (data.length != 3) { 304 throw new IllegalArgumentException ( 305 "The 'data' array must have length == 3."); 306 } 307 if (data[0].length != data[1].length 308 || data[0].length != data[2].length) { 309 throw new IllegalArgumentException ("The 'data' array must contain " 310 + "three arrays all having the same length."); 311 } 312 int seriesIndex = indexOf(seriesKey); 313 if (seriesIndex == -1) { this.seriesKeys.add(seriesKey); 315 this.seriesList.add(data); 316 } 317 else { this.seriesList.remove(seriesIndex); 319 this.seriesList.add(seriesIndex, data); 320 } 321 notifyListeners(new DatasetChangeEvent(this, this)); 322 } 323 324 331 public void removeSeries(Comparable seriesKey) { 332 int seriesIndex = indexOf(seriesKey); 333 if (seriesIndex >= 0) { 334 this.seriesKeys.remove(seriesIndex); 335 this.seriesList.remove(seriesIndex); 336 notifyListeners(new DatasetChangeEvent(this, this)); 337 } 338 } 339 340 355 public boolean equals(Object obj) { 356 if (obj == this) { 357 return true; 358 } 359 if (!(obj instanceof DefaultXYZDataset)) { 360 return false; 361 } 362 DefaultXYZDataset that = (DefaultXYZDataset) obj; 363 if (!this.seriesKeys.equals(that.seriesKeys)) { 364 return false; 365 } 366 for (int i = 0; i < this.seriesList.size(); i++) { 367 double[][] d1 = (double[][]) this.seriesList.get(i); 368 double[][] d2 = (double[][]) that.seriesList.get(i); 369 double[] d1x = d1[0]; 370 double[] d2x = d2[0]; 371 if (!Arrays.equals(d1x, d2x)) { 372 return false; 373 } 374 double[] d1y = d1[1]; 375 double[] d2y = d2[1]; 376 if (!Arrays.equals(d1y, d2y)) { 377 return false; 378 } 379 double[] d1z = d1[2]; 380 double[] d2z = d2[2]; 381 if (!Arrays.equals(d1z, d2z)) { 382 return false; 383 } 384 } 385 return true; 386 } 387 388 397 public Object clone() throws CloneNotSupportedException { 398 DefaultXYZDataset clone = (DefaultXYZDataset) super.clone(); 399 clone.seriesKeys = new java.util.ArrayList (this.seriesKeys); 400 clone.seriesList = new ArrayList (this.seriesList.size()); 401 for (int i = 0; i < this.seriesList.size(); i++) { 402 double[][] data = (double[][]) this.seriesList.get(i); 403 double[] x = data[0]; 404 double[] y = data[1]; 405 double[] z = data[2]; 406 double[] xx = new double[x.length]; 407 double[] yy = new double[y.length]; 408 double[] zz = new double[z.length]; 409 System.arraycopy(x, 0, xx, 0, x.length); 410 System.arraycopy(y, 0, yy, 0, y.length); 411 System.arraycopy(z, 0, zz, 0, z.length); 412 clone.seriesList.add(i, new double[][] {xx, yy, zz}); 413 } 414 return clone; 415 } 416 417 } 418 | Popular Tags |