Frames | No Frames |
1: /* =========================================================== 2: * JFreeChart : a free chart library for the Java(tm) platform 3: * =========================================================== 4: * 5: * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. 6: * 7: * Project Info: http://www.jfree.org/jfreechart/index.html 8: * 9: * This library is free software; you can redistribute it and/or modify it 10: * under the terms of the GNU Lesser General Public License as published by 11: * the Free Software Foundation; either version 2.1 of the License, or 12: * (at your option) any later version. 13: * 14: * This library is distributed in the hope that it will be useful, but 15: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 16: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 17: * License for more details. 18: * 19: * You should have received a copy of the GNU Lesser General Public 20: * License along with this library; if not, write to the Free Software 21: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22: * USA. 23: * 24: * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 25: * in the United States and other countries.] 26: * 27: * ------------------------------- 28: * XYIntervalSeriesCollection.java 29: * ------------------------------- 30: * (C) Copyright 2006, 2007, by Object Refinery Limited. 31: * 32: * Original Author: David Gilbert (for Object Refinery Limited); 33: * Contributor(s): -; 34: * 35: * $Id: XYIntervalSeriesCollection.java,v 1.1.2.5 2007/02/13 16:12:46 mungady Exp $ 36: * 37: * Changes 38: * ------- 39: * 20-Oct-2006 : Version 1 (DG); 40: * 13-Feb-2007 : Provided a number of method overrides that enhance 41: * performance, and added a proper clone() 42: * implementation (DG); 43: * 44: */ 45: 46: package org.jfree.data.xy; 47: 48: import java.io.Serializable; 49: import java.util.List; 50: 51: import org.jfree.data.general.DatasetChangeEvent; 52: import org.jfree.util.ObjectUtilities; 53: 54: /** 55: * A collection of {@link XYIntervalSeries} objects. 56: * 57: * @since 1.0.3 58: * 59: * @see XYIntervalSeries 60: */ 61: public class XYIntervalSeriesCollection extends AbstractIntervalXYDataset 62: implements IntervalXYDataset, Serializable { 63: 64: /** Storage for the data series. */ 65: private List data; 66: 67: /** 68: * Creates a new instance of <code>XIntervalSeriesCollection</code>. 69: */ 70: public XYIntervalSeriesCollection() { 71: this.data = new java.util.ArrayList(); 72: } 73: 74: /** 75: * Adds a series to the collection and sends a {@link DatasetChangeEvent} 76: * to all registered listeners. 77: * 78: * @param series the series (<code>null</code> not permitted). 79: */ 80: public void addSeries(XYIntervalSeries series) { 81: if (series == null) { 82: throw new IllegalArgumentException("Null 'series' argument."); 83: } 84: this.data.add(series); 85: series.addChangeListener(this); 86: fireDatasetChanged(); 87: } 88: 89: /** 90: * Returns the number of series in the collection. 91: * 92: * @return The series count. 93: */ 94: public int getSeriesCount() { 95: return this.data.size(); 96: } 97: 98: /** 99: * Returns a series from the collection. 100: * 101: * @param series the series index (zero-based). 102: * 103: * @return The series. 104: * 105: * @throws IllegalArgumentException if <code>series</code> is not in the 106: * range <code>0</code> to <code>getSeriesCount() - 1</code>. 107: */ 108: public XYIntervalSeries getSeries(int series) { 109: if ((series < 0) || (series >= getSeriesCount())) { 110: throw new IllegalArgumentException("Series index out of bounds"); 111: } 112: return (XYIntervalSeries) this.data.get(series); 113: } 114: 115: /** 116: * Returns the key for a series. 117: * 118: * @param series the series index (in the range <code>0</code> to 119: * <code>getSeriesCount() - 1</code>). 120: * 121: * @return The key for a series. 122: * 123: * @throws IllegalArgumentException if <code>series</code> is not in the 124: * specified range. 125: */ 126: public Comparable getSeriesKey(int series) { 127: // defer argument checking 128: return getSeries(series).getKey(); 129: } 130: 131: /** 132: * Returns the number of items in the specified series. 133: * 134: * @param series the series (zero-based index). 135: * 136: * @return The item count. 137: * 138: * @throws IllegalArgumentException if <code>series</code> is not in the 139: * range <code>0</code> to <code>getSeriesCount() - 1</code>. 140: */ 141: public int getItemCount(int series) { 142: // defer argument checking 143: return getSeries(series).getItemCount(); 144: } 145: 146: /** 147: * Returns the x-value for an item within a series. 148: * 149: * @param series the series index. 150: * @param item the item index. 151: * 152: * @return The x-value. 153: */ 154: public Number getX(int series, int item) { 155: XYIntervalSeries s = (XYIntervalSeries) this.data.get(series); 156: return s.getX(item); 157: } 158: 159: /** 160: * Returns the start x-value (as a double primitive) for an item within a 161: * series. 162: * 163: * @param series the series index (zero-based). 164: * @param item the item index (zero-based). 165: * 166: * @return The value. 167: */ 168: public double getStartXValue(int series, int item) { 169: XYIntervalSeries s = (XYIntervalSeries) this.data.get(series); 170: return s.getXLowValue(item); 171: } 172: 173: /** 174: * Returns the end x-value (as a double primitive) for an item within a 175: * series. 176: * 177: * @param series the series index (zero-based). 178: * @param item the item index (zero-based). 179: * 180: * @return The value. 181: */ 182: public double getEndXValue(int series, int item) { 183: XYIntervalSeries s = (XYIntervalSeries) this.data.get(series); 184: return s.getXHighValue(item); 185: } 186: 187: /** 188: * Returns the y-value (as a double primitive) for an item within a 189: * series. 190: * 191: * @param series the series index (zero-based). 192: * @param item the item index (zero-based). 193: * 194: * @return The value. 195: */ 196: public double getYValue(int series, int item) { 197: XYIntervalSeries s = (XYIntervalSeries) this.data.get(series); 198: return s.getYValue(item); 199: } 200: 201: /** 202: * Returns the start y-value (as a double primitive) for an item within a 203: * series. 204: * 205: * @param series the series index (zero-based). 206: * @param item the item index (zero-based). 207: * 208: * @return The value. 209: */ 210: public double getStartYValue(int series, int item) { 211: XYIntervalSeries s = (XYIntervalSeries) this.data.get(series); 212: return s.getYLowValue(item); 213: } 214: 215: /** 216: * Returns the end y-value (as a double primitive) for an item within a 217: * series. 218: * 219: * @param series the series (zero-based index). 220: * @param item the item (zero-based index). 221: * 222: * @return The value. 223: */ 224: public double getEndYValue(int series, int item) { 225: XYIntervalSeries s = (XYIntervalSeries) this.data.get(series); 226: return s.getYHighValue(item); 227: } 228: 229: /** 230: * Returns the y-value for an item within a series. 231: * 232: * @param series the series index. 233: * @param item the item index. 234: * 235: * @return The y-value. 236: */ 237: public Number getY(int series, int item) { 238: return new Double(getYValue(series, item)); 239: } 240: 241: /** 242: * Returns the start x-value for an item within a series. 243: * 244: * @param series the series index. 245: * @param item the item index. 246: * 247: * @return The x-value. 248: */ 249: public Number getStartX(int series, int item) { 250: return new Double(getStartXValue(series, item)); 251: } 252: 253: /** 254: * Returns the end x-value for an item within a series. 255: * 256: * @param series the series index. 257: * @param item the item index. 258: * 259: * @return The x-value. 260: */ 261: public Number getEndX(int series, int item) { 262: return new Double(getEndXValue(series, item)); 263: } 264: 265: /** 266: * Returns the start y-value for an item within a series. This method 267: * maps directly to {@link #getY(int, int)}. 268: * 269: * @param series the series index. 270: * @param item the item index. 271: * 272: * @return The start y-value. 273: */ 274: public Number getStartY(int series, int item) { 275: return new Double(getStartYValue(series, item)); 276: } 277: 278: /** 279: * Returns the end y-value for an item within a series. This method 280: * maps directly to {@link #getY(int, int)}. 281: * 282: * @param series the series index. 283: * @param item the item index. 284: * 285: * @return The end y-value. 286: */ 287: public Number getEndY(int series, int item) { 288: return new Double(getEndYValue(series, item)); 289: } 290: 291: /** 292: * Tests this instance for equality with an arbitrary object. 293: * 294: * @param obj the object (<code>null</code> permitted). 295: * 296: * @return A boolean. 297: */ 298: public boolean equals(Object obj) { 299: if (obj == this) { 300: return true; 301: } 302: if (!(obj instanceof XYIntervalSeriesCollection)) { 303: return false; 304: } 305: XYIntervalSeriesCollection that = (XYIntervalSeriesCollection) obj; 306: return ObjectUtilities.equal(this.data, that.data); 307: } 308: 309: /** 310: * Returns a clone of this dataset. 311: * 312: * @return A clone of this dataset. 313: * 314: * @throws CloneNotSupportedException if there is a problem cloning. 315: */ 316: public Object clone() throws CloneNotSupportedException { 317: XYIntervalSeriesCollection clone 318: = (XYIntervalSeriesCollection) super.clone(); 319: int seriesCount = getSeriesCount(); 320: clone.data = new java.util.ArrayList(seriesCount); 321: for (int i = 0; i < this.data.size(); i++) { 322: clone.data.set(i, getSeries(i).clone()); 323: } 324: return clone; 325: } 326: 327: }