1 44 45 package org.jfree.data.xy; 46 47 import java.io.Serializable ; 48 import java.util.List ; 49 50 import org.jfree.util.ObjectUtilities; 51 52 60 public class MatrixSeriesCollection extends AbstractXYZDataset 61 implements XYZDataset, Serializable { 62 63 64 private static final long serialVersionUID = -3197705779242543945L; 65 66 67 private List seriesList; 68 69 72 public MatrixSeriesCollection() { 73 this(null); 74 } 75 76 77 82 public MatrixSeriesCollection(MatrixSeries series) { 83 this.seriesList = new java.util.ArrayList (); 84 85 if (series != null) { 86 this.seriesList.add(series); 87 series.addChangeListener(this); 88 } 89 } 90 91 98 public int getItemCount(int seriesIndex) { 99 return getSeries(seriesIndex).getItemCount(); 100 } 101 102 103 112 public MatrixSeries getSeries(int seriesIndex) { 113 if ((seriesIndex < 0) || (seriesIndex > getSeriesCount())) { 114 throw new IllegalArgumentException ("Index outside valid range."); 115 } 116 117 MatrixSeries series = (MatrixSeries) this.seriesList.get(seriesIndex); 118 119 return series; 120 } 121 122 123 128 public int getSeriesCount() { 129 return this.seriesList.size(); 130 } 131 132 133 140 public Comparable getSeriesKey(int seriesIndex) { 141 return getSeries(seriesIndex).getKey(); 142 } 143 144 145 156 public Number getX(int seriesIndex, int itemIndex) { 157 MatrixSeries series = (MatrixSeries) this.seriesList.get(seriesIndex); 158 int x = series.getItemColumn(itemIndex); 159 160 return new Integer (x); } 162 163 164 175 public Number getY(int seriesIndex, int itemIndex) { 176 MatrixSeries series = (MatrixSeries) this.seriesList.get(seriesIndex); 177 int y = series.getItemRow(itemIndex); 178 179 return new Integer (y); } 181 182 183 194 public Number getZ(int seriesIndex, int itemIndex) { 195 MatrixSeries series = (MatrixSeries) this.seriesList.get(seriesIndex); 196 Number z = series.getItem(itemIndex); 197 return z; 198 } 199 200 201 211 public void addSeries(MatrixSeries series) { 212 if (series == null) { 214 throw new IllegalArgumentException ("Cannot add null series."); 215 } 216 217 this.seriesList.add(series); 219 series.addChangeListener(this); 220 fireDatasetChanged(); 221 } 222 223 224 231 public boolean equals(Object obj) { 232 if (obj == null) { 233 return false; 234 } 235 236 if (obj == this) { 237 return true; 238 } 239 240 if (obj instanceof MatrixSeriesCollection) { 241 MatrixSeriesCollection c = (MatrixSeriesCollection) obj; 242 243 return ObjectUtilities.equal(this.seriesList, c.seriesList); 244 } 245 246 return false; 247 } 248 249 254 public int hashCode() { 255 return (this.seriesList != null ? this.seriesList.hashCode() : 0); 256 } 257 258 264 public void removeAllSeries() { 265 for (int i = 0; i < this.seriesList.size(); i++) { 268 MatrixSeries series = (MatrixSeries) this.seriesList.get(i); 269 series.removeChangeListener(this); 270 } 271 272 this.seriesList.clear(); 274 fireDatasetChanged(); 275 } 276 277 278 288 public void removeSeries(MatrixSeries series) { 289 if (series == null) { 291 throw new IllegalArgumentException ("Cannot remove null series."); 292 } 293 294 if (this.seriesList.contains(series)) { 296 series.removeChangeListener(this); 297 this.seriesList.remove(series); 298 fireDatasetChanged(); 299 } 300 } 301 302 303 312 public void removeSeries(int seriesIndex) { 313 if ((seriesIndex < 0) || (seriesIndex > getSeriesCount())) { 315 throw new IllegalArgumentException ("Index outside valid range."); 316 } 317 318 MatrixSeries series = (MatrixSeries) this.seriesList.get(seriesIndex); 320 series.removeChangeListener(this); 321 this.seriesList.remove(seriesIndex); 322 fireDatasetChanged(); 323 } 324 325 } 326 | Popular Tags |