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: * YIntervalSeriesCollection.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: YIntervalSeriesCollection.java,v 1.1.2.5 2007/02/20 16:22:01 mungady Exp $ 36: * 37: * Changes 38: * ------- 39: * 20-Oct-2006 : Version 1 (DG); 40: * 27-Nov-2006 : Added clone() override (DG); 41: * 20-Feb-2007 : Added getYValue(), getStartYValue() and getEndYValue() 42: * methods (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 YIntervalSeries} objects. 56: * 57: * @since 1.0.3 58: * 59: * @see YIntervalSeries 60: */ 61: public class YIntervalSeriesCollection 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>YIntervalSeriesCollection</code>. 69: */ 70: public YIntervalSeriesCollection() { 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(YIntervalSeries 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 YIntervalSeries getSeries(int series) { 109: if ((series < 0) || (series >= getSeriesCount())) { 110: throw new IllegalArgumentException("Series index out of bounds"); 111: } 112: return (YIntervalSeries) 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: YIntervalSeries s = (YIntervalSeries) this.data.get(series); 156: return s.getX(item); 157: } 158: 159: /** 160: * Returns the y-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 getYValue(int series, int item) { 169: YIntervalSeries s = (YIntervalSeries) this.data.get(series); 170: return s.getYValue(item); 171: } 172: 173: /** 174: * Returns the start y-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 getStartYValue(int series, int item) { 183: YIntervalSeries s = (YIntervalSeries) this.data.get(series); 184: return s.getYLowValue(item); 185: } 186: 187: /** 188: * Returns the end y-value (as a double primitive) for an item within a 189: * series. 190: * 191: * @param series the series (zero-based index). 192: * @param item the item (zero-based index). 193: * 194: * @return The value. 195: */ 196: public double getEndYValue(int series, int item) { 197: YIntervalSeries s = (YIntervalSeries) this.data.get(series); 198: return s.getYHighValue(item); 199: } 200: 201: /** 202: * Returns the y-value for an item within a series. 203: * 204: * @param series the series index. 205: * @param item the item index. 206: * 207: * @return The y-value. 208: */ 209: public Number getY(int series, int item) { 210: YIntervalSeries s = (YIntervalSeries) this.data.get(series); 211: return new Double(s.getYValue(item)); 212: } 213: 214: /** 215: * Returns the start x-value for an item within a series. This method 216: * maps directly to {@link #getX(int, int)}. 217: * 218: * @param series the series index. 219: * @param item the item index. 220: * 221: * @return The x-value. 222: */ 223: public Number getStartX(int series, int item) { 224: return getX(series, item); 225: } 226: 227: /** 228: * Returns the end x-value for an item within a series. This method 229: * maps directly to {@link #getX(int, int)}. 230: * 231: * @param series the series index. 232: * @param item the item index. 233: * 234: * @return The x-value. 235: */ 236: public Number getEndX(int series, int item) { 237: return getX(series, item); 238: } 239: 240: /** 241: * Returns the start y-value for an item within a series. 242: * 243: * @param series the series index. 244: * @param item the item index. 245: * 246: * @return The start y-value. 247: */ 248: public Number getStartY(int series, int item) { 249: YIntervalSeries s = (YIntervalSeries) this.data.get(series); 250: return new Double(s.getYLowValue(item)); 251: } 252: 253: /** 254: * Returns the end y-value for an item within a series. 255: * 256: * @param series the series index. 257: * @param item the item index. 258: * 259: * @return The end y-value. 260: */ 261: public Number getEndY(int series, int item) { 262: YIntervalSeries s = (YIntervalSeries) this.data.get(series); 263: return new Double(s.getYHighValue(item)); 264: } 265: 266: /** 267: * Tests this instance for equality with an arbitrary object. 268: * 269: * @param obj the object (<code>null</code> permitted). 270: * 271: * @return A boolean. 272: */ 273: public boolean equals(Object obj) { 274: if (obj == this) { 275: return true; 276: } 277: if (!(obj instanceof YIntervalSeriesCollection)) { 278: return false; 279: } 280: YIntervalSeriesCollection that = (YIntervalSeriesCollection) obj; 281: return ObjectUtilities.equal(this.data, that.data); 282: } 283: 284: /** 285: * Returns a clone of this instance. 286: * 287: * @return A clone. 288: * 289: * @throws CloneNotSupportedException if there is a problem. 290: */ 291: public Object clone() throws CloneNotSupportedException { 292: YIntervalSeriesCollection clone 293: = (YIntervalSeriesCollection) super.clone(); 294: clone.data = (List) ObjectUtilities.deepClone(this.data); 295: return clone; 296: } 297: 298: }