1 42 43 package org.jfree.data; 44 45 import java.io.Serializable ; 46 import java.util.Collections ; 47 import java.util.List ; 48 49 import org.jfree.util.ObjectUtils; 50 51 56 public class XYSeriesCollection extends AbstractSeriesDataset 57 implements XYDataset, Serializable { 58 59 60 private List data; 61 62 65 public XYSeriesCollection() { 66 67 this.data = new java.util.ArrayList (); 68 69 } 70 71 76 public XYSeriesCollection(XYSeries series) { 77 78 this.data = new java.util.ArrayList (); 79 if (series != null) { 80 data.add(series); 81 series.addChangeListener(this); 82 } 83 84 } 85 86 93 public void addSeries(XYSeries series) { 94 95 if (series == null) { 97 throw new IllegalArgumentException ( 98 "XYSeriesCollection.addSeries(...): cannot add null series."); 99 } 100 101 data.add(series); 103 series.addChangeListener(this); 104 fireDatasetChanged(); 105 106 } 107 108 113 public int getSeriesCount() { 114 return this.data.size(); 115 } 116 117 122 public List getSeries() { 123 return Collections.unmodifiableList(this.data); 124 } 125 126 133 public XYSeries getSeries(int series) { 134 135 if ((series < 0) || (series > getSeriesCount())) { 137 throw new IllegalArgumentException ( 138 "XYSeriesCollection.getSeries(...): index outside valid range."); 139 } 140 141 XYSeries ts = (XYSeries) data.get(series); 143 return ts; 144 145 } 146 147 154 public String getSeriesName(int series) { 155 156 158 return getSeries(series).getName(); 160 161 } 162 163 170 public int getItemCount(int series) { 171 172 174 return getSeries(series).getItemCount(); 176 177 } 178 179 187 public Number getXValue(int series, int item) { 188 189 XYSeries ts = (XYSeries) data.get(series); 190 XYDataItem xyItem = ts.getDataItem(item); 191 return xyItem.getX(); 192 193 } 194 195 203 public Number getYValue(int series, int index) { 204 205 XYSeries ts = (XYSeries) data.get(series); 206 XYDataItem xyItem = ts.getDataItem(index); 207 return xyItem.getY(); 208 209 } 210 211 216 public void removeAllSeries() { 217 218 219 for (int i = 0; i < this.data.size(); i++) { 221 XYSeries series = (XYSeries) this.data.get(i); 222 series.removeChangeListener(this); 223 } 224 225 data.clear(); 227 fireDatasetChanged(); 228 229 } 230 231 238 public void removeSeries(XYSeries series) { 239 240 if (series == null) { 242 throw new IllegalArgumentException ( 243 "XYSeriesCollection.removeSeries(...): cannot remove null series."); 244 } 245 246 if (data.contains(series)) { 248 series.removeChangeListener(this); 249 data.remove(series); 250 fireDatasetChanged(); 251 } 252 253 } 254 255 262 public void removeSeries(int series) { 263 264 if ((series < 0) || (series > getSeriesCount())) { 266 throw new IllegalArgumentException ( 267 "XYSeriesCollection.removeSeries(...): index outside valid range."); 268 } 269 270 XYSeries ts = (XYSeries) data.get(series); 272 ts.removeChangeListener(this); 273 data.remove(series); 274 fireDatasetChanged(); 275 276 } 277 278 285 public boolean equals(Object obj) { 286 287 if (obj == null) { 288 return false; 289 } 290 291 if (obj == this) { 292 return true; 293 } 294 295 if (obj instanceof XYSeriesCollection) { 296 XYSeriesCollection c = (XYSeriesCollection) obj; 297 return ObjectUtils.equal(this.data, c.data); 298 } 299 300 return false; 301 302 } 303 304 } 305 | Popular Tags |