1 54 55 package org.jfree.data.xy; 56 57 import java.io.Serializable ; 58 import java.util.Collections ; 59 import java.util.List ; 60 61 import org.jfree.data.DomainInfo; 62 import org.jfree.data.Range; 63 import org.jfree.data.general.DatasetChangeEvent; 64 import org.jfree.data.general.DatasetUtilities; 65 import org.jfree.util.ObjectUtilities; 66 67 71 public class XYSeriesCollection extends AbstractIntervalXYDataset 72 implements IntervalXYDataset, DomainInfo, 73 Serializable { 74 75 76 private static final long serialVersionUID = -7590013825931496766L; 77 78 79 private List data; 80 81 82 private IntervalXYDelegate intervalDelegate; 83 84 87 public XYSeriesCollection() { 88 this(null); 89 } 90 91 96 public XYSeriesCollection(XYSeries series) { 97 this.data = new java.util.ArrayList (); 98 this.intervalDelegate = new IntervalXYDelegate(this, false); 99 addChangeListener(this.intervalDelegate); 100 if (series != null) { 101 this.data.add(series); 102 series.addChangeListener(this); 103 } 104 } 105 106 112 public void addSeries(XYSeries series) { 113 114 if (series == null) { 115 throw new IllegalArgumentException ("Null 'series' argument."); 116 } 117 this.data.add(series); 118 series.addChangeListener(this); 119 fireDatasetChanged(); 120 121 } 122 123 129 public void removeSeries(int series) { 130 131 if ((series < 0) || (series > getSeriesCount())) { 132 throw new IllegalArgumentException ("Series index out of bounds."); 133 } 134 135 XYSeries ts = (XYSeries) this.data.get(series); 137 ts.removeChangeListener(this); 138 this.data.remove(series); 139 fireDatasetChanged(); 140 141 } 142 143 149 public void removeSeries(XYSeries series) { 150 151 if (series == null) { 152 throw new IllegalArgumentException ("Null 'series' argument."); 153 } 154 if (this.data.contains(series)) { 155 series.removeChangeListener(this); 156 this.data.remove(series); 157 fireDatasetChanged(); 158 } 159 160 } 161 162 166 public void removeAllSeries() { 167 for (int i = 0; i < this.data.size(); i++) { 170 XYSeries series = (XYSeries) this.data.get(i); 171 series.removeChangeListener(this); 172 } 173 174 this.data.clear(); 176 fireDatasetChanged(); 177 } 178 179 184 public int getSeriesCount() { 185 return this.data.size(); 186 } 187 188 193 public List getSeries() { 194 return Collections.unmodifiableList(this.data); 195 } 196 197 207 public XYSeries getSeries(int series) { 208 if ((series < 0) || (series >= getSeriesCount())) { 209 throw new IllegalArgumentException ("Series index out of bounds"); 210 } 211 return (XYSeries) this.data.get(series); 212 } 213 214 225 public Comparable getSeriesKey(int series) { 226 return getSeries(series).getKey(); 228 } 229 230 240 public int getItemCount(int series) { 241 return getSeries(series).getItemCount(); 243 } 244 245 253 public Number getX(int series, int item) { 254 XYSeries ts = (XYSeries) this.data.get(series); 255 XYDataItem xyItem = ts.getDataItem(item); 256 return xyItem.getX(); 257 } 258 259 267 public Number getStartX(int series, int item) { 268 return this.intervalDelegate.getStartX(series, item); 269 } 270 271 279 public Number getEndX(int series, int item) { 280 return this.intervalDelegate.getEndX(series, item); 281 } 282 283 291 public Number getY(int series, int index) { 292 293 XYSeries ts = (XYSeries) this.data.get(series); 294 XYDataItem xyItem = ts.getDataItem(index); 295 return xyItem.getY(); 296 297 } 298 299 307 public Number getStartY(int series, int item) { 308 return getY(series, item); 309 } 310 311 319 public Number getEndY(int series, int item) { 320 return getY(series, item); 321 } 322 323 330 public boolean equals(Object obj) { 331 339 340 if (obj == this) { 341 return true; 342 } 343 if (!(obj instanceof XYSeriesCollection)) { 344 return false; 345 } 346 XYSeriesCollection that = (XYSeriesCollection) obj; 347 return ObjectUtilities.equal(this.data, that.data); 348 } 349 350 355 public int hashCode() { 356 return (this.data != null ? this.data.hashCode() : 0); 358 } 359 360 368 public double getDomainLowerBound(boolean includeInterval) { 369 return this.intervalDelegate.getDomainLowerBound(includeInterval); 370 } 371 372 380 public double getDomainUpperBound(boolean includeInterval) { 381 return this.intervalDelegate.getDomainUpperBound(includeInterval); 382 } 383 384 392 public Range getDomainBounds(boolean includeInterval) { 393 if (includeInterval) { 394 return this.intervalDelegate.getDomainBounds(includeInterval); 395 } 396 else { 397 return DatasetUtilities.iterateDomainBounds(this, includeInterval); 398 } 399 400 } 401 402 408 public double getIntervalWidth() { 409 return this.intervalDelegate.getIntervalWidth(); 410 } 411 412 418 public void setIntervalWidth(double width) { 419 if (width < 0.0) { 420 throw new IllegalArgumentException ("Negative 'width' argument."); 421 } 422 this.intervalDelegate.setFixedIntervalWidth(width); 423 fireDatasetChanged(); 424 } 425 426 431 public double getIntervalPositionFactor() { 432 return this.intervalDelegate.getIntervalPositionFactor(); 433 } 434 435 442 public void setIntervalPositionFactor(double factor) { 443 this.intervalDelegate.setIntervalPositionFactor(factor); 444 fireDatasetChanged(); 445 } 446 447 452 public boolean isAutoWidth() { 453 return this.intervalDelegate.isAutoWidth(); 454 } 455 456 462 public void setAutoWidth(boolean b) { 463 this.intervalDelegate.setAutoWidth(b); 464 fireDatasetChanged(); 465 } 466 467 } 468 | Popular Tags |