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: * Changes 36: * ------- 37: * 20-Oct-2006 : Version 1 (DG); 38: * 27-Nov-2006 : Added clone() override (DG); 39: * 20-Feb-2007 : Added getYValue(), getStartYValue() and getEndYValue() 40: * methods (DG); 41: * 42: */ 43: 44: package org.jfree.data.xy; 45: 46: import java.io.Serializable; 47: import java.util.List; 48: 49: import org.jfree.data.general.DatasetChangeEvent; 50: import org.jfree.util.ObjectUtilities; 51: 52: /** 53: * A collection of {@link YIntervalSeries} objects. 54: * 55: * @since 1.0.3 56: * 57: * @see YIntervalSeries 58: */ 59: public class YIntervalSeriesCollection extends AbstractIntervalXYDataset 60: implements IntervalXYDataset, Serializable { 61: 62: /** Storage for the data series. */ 63: private List data; 64: 65: /** 66: * Creates a new instance of <code>YIntervalSeriesCollection</code>. 67: */ 68: public YIntervalSeriesCollection() { 69: this.data = new java.util.ArrayList(); 70: } 71: 72: /** 73: * Adds a series to the collection and sends a {@link DatasetChangeEvent} 74: * to all registered listeners. 75: * 76: * @param series the series (<code>null</code> not permitted). 77: */ 78: public void addSeries(YIntervalSeries series) { 79: if (series == null) { 80: throw new IllegalArgumentException("Null 'series' argument."); 81: } 82: this.data.add(series); 83: series.addChangeListener(this); 84: fireDatasetChanged(); 85: } 86: 87: /** 88: * Returns the number of series in the collection. 89: * 90: * @return The series count. 91: */ 92: public int getSeriesCount() { 93: return this.data.size(); 94: } 95: 96: /** 97: * Returns a series from the collection. 98: * 99: * @param series the series index (zero-based). 100: * 101: * @return The series. 102: * 103: * @throws IllegalArgumentException if <code>series</code> is not in the 104: * range <code>0</code> to <code>getSeriesCount() - 1</code>. 105: */ 106: public YIntervalSeries getSeries(int series) { 107: if ((series < 0) || (series >= getSeriesCount())) { 108: throw new IllegalArgumentException("Series index out of bounds"); 109: } 110: return (YIntervalSeries) this.data.get(series); 111: } 112: 113: /** 114: * Returns the key for a series. 115: * 116: * @param series the series index (in the range <code>0</code> to 117: * <code>getSeriesCount() - 1</code>). 118: * 119: * @return The key for a series. 120: * 121: * @throws IllegalArgumentException if <code>series</code> is not in the 122: * specified range. 123: */ 124: public Comparable getSeriesKey(int series) { 125: // defer argument checking 126: return getSeries(series).getKey(); 127: } 128: 129: /** 130: * Returns the number of items in the specified series. 131: * 132: * @param series the series (zero-based index). 133: * 134: * @return The item count. 135: * 136: * @throws IllegalArgumentException if <code>series</code> is not in the 137: * range <code>0</code> to <code>getSeriesCount() - 1</code>. 138: */ 139: public int getItemCount(int series) { 140: // defer argument checking 141: return getSeries(series).getItemCount(); 142: } 143: 144: /** 145: * Returns the x-value for an item within a series. 146: * 147: * @param series the series index. 148: * @param item the item index. 149: * 150: * @return The x-value. 151: */ 152: public Number getX(int series, int item) { 153: YIntervalSeries s = (YIntervalSeries) this.data.get(series); 154: return s.getX(item); 155: } 156: 157: /** 158: * Returns the y-value (as a double primitive) for an item within a 159: * series. 160: * 161: * @param series the series index (zero-based). 162: * @param item the item index (zero-based). 163: * 164: * @return The value. 165: */ 166: public double getYValue(int series, int item) { 167: YIntervalSeries s = (YIntervalSeries) this.data.get(series); 168: return s.getYValue(item); 169: } 170: 171: /** 172: * Returns the start y-value (as a double primitive) for an item within a 173: * series. 174: * 175: * @param series the series index (zero-based). 176: * @param item the item index (zero-based). 177: * 178: * @return The value. 179: */ 180: public double getStartYValue(int series, int item) { 181: YIntervalSeries s = (YIntervalSeries) this.data.get(series); 182: return s.getYLowValue(item); 183: } 184: 185: /** 186: * Returns the end y-value (as a double primitive) for an item within a 187: * series. 188: * 189: * @param series the series (zero-based index). 190: * @param item the item (zero-based index). 191: * 192: * @return The value. 193: */ 194: public double getEndYValue(int series, int item) { 195: YIntervalSeries s = (YIntervalSeries) this.data.get(series); 196: return s.getYHighValue(item); 197: } 198: 199: /** 200: * Returns the y-value for an item within a series. 201: * 202: * @param series the series index. 203: * @param item the item index. 204: * 205: * @return The y-value. 206: */ 207: public Number getY(int series, int item) { 208: YIntervalSeries s = (YIntervalSeries) this.data.get(series); 209: return new Double(s.getYValue(item)); 210: } 211: 212: /** 213: * Returns the start x-value for an item within a series. This method 214: * maps directly to {@link #getX(int, int)}. 215: * 216: * @param series the series index. 217: * @param item the item index. 218: * 219: * @return The x-value. 220: */ 221: public Number getStartX(int series, int item) { 222: return getX(series, item); 223: } 224: 225: /** 226: * Returns the end x-value for an item within a series. This method 227: * maps directly to {@link #getX(int, int)}. 228: * 229: * @param series the series index. 230: * @param item the item index. 231: * 232: * @return The x-value. 233: */ 234: public Number getEndX(int series, int item) { 235: return getX(series, item); 236: } 237: 238: /** 239: * Returns the start y-value for an item within a series. 240: * 241: * @param series the series index. 242: * @param item the item index. 243: * 244: * @return The start y-value. 245: */ 246: public Number getStartY(int series, int item) { 247: YIntervalSeries s = (YIntervalSeries) this.data.get(series); 248: return new Double(s.getYLowValue(item)); 249: } 250: 251: /** 252: * Returns the end y-value for an item within a series. 253: * 254: * @param series the series index. 255: * @param item the item index. 256: * 257: * @return The end y-value. 258: */ 259: public Number getEndY(int series, int item) { 260: YIntervalSeries s = (YIntervalSeries) this.data.get(series); 261: return new Double(s.getYHighValue(item)); 262: } 263: 264: /** 265: * Tests this instance for equality with an arbitrary object. 266: * 267: * @param obj the object (<code>null</code> permitted). 268: * 269: * @return A boolean. 270: */ 271: public boolean equals(Object obj) { 272: if (obj == this) { 273: return true; 274: } 275: if (!(obj instanceof YIntervalSeriesCollection)) { 276: return false; 277: } 278: YIntervalSeriesCollection that = (YIntervalSeriesCollection) obj; 279: return ObjectUtilities.equal(this.data, that.data); 280: } 281: 282: /** 283: * Returns a clone of this instance. 284: * 285: * @return A clone. 286: * 287: * @throws CloneNotSupportedException if there is a problem. 288: */ 289: public Object clone() throws CloneNotSupportedException { 290: YIntervalSeriesCollection clone 291: = (YIntervalSeriesCollection) super.clone(); 292: clone.data = (List) ObjectUtilities.deepClone(this.data); 293: return clone; 294: } 295: 296: }