001: /* ===========================================================
002: * JFreeChart : a free chart library for the Java(tm) platform
003: * ===========================================================
004: *
005: * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors.
006: *
007: * Project Info: http://www.jfree.org/jfreechart/index.html
008: *
009: * This library is free software; you can redistribute it and/or modify it
010: * under the terms of the GNU Lesser General Public License as published by
011: * the Free Software Foundation; either version 2.1 of the License, or
012: * (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful, but
015: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
016: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
017: * License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
022: * USA.
023: *
024: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
025: * in the United States and other countries.]
026: *
027: * ------------------------------
028: * YIntervalSeriesCollection.java
029: * ------------------------------
030: * (C) Copyright 2006, 2007, by Object Refinery Limited.
031: *
032: * Original Author: David Gilbert (for Object Refinery Limited);
033: * Contributor(s): -;
034: *
035: * $Id: YIntervalSeriesCollection.java,v 1.1.2.5 2007/02/20 16:22:01 mungady Exp $
036: *
037: * Changes
038: * -------
039: * 20-Oct-2006 : Version 1 (DG);
040: * 27-Nov-2006 : Added clone() override (DG);
041: * 20-Feb-2007 : Added getYValue(), getStartYValue() and getEndYValue()
042: * methods (DG);
043: *
044: */
045:
046: package org.jfree.data.xy;
047:
048: import java.io.Serializable;
049: import java.util.List;
050:
051: import org.jfree.data.general.DatasetChangeEvent;
052: import org.jfree.util.ObjectUtilities;
053:
054: /**
055: * A collection of {@link YIntervalSeries} objects.
056: *
057: * @since 1.0.3
058: *
059: * @see YIntervalSeries
060: */
061: public class YIntervalSeriesCollection extends
062: AbstractIntervalXYDataset implements IntervalXYDataset,
063: Serializable {
064:
065: /** Storage for the data series. */
066: private List data;
067:
068: /**
069: * Creates a new instance of <code>YIntervalSeriesCollection</code>.
070: */
071: public YIntervalSeriesCollection() {
072: this .data = new java.util.ArrayList();
073: }
074:
075: /**
076: * Adds a series to the collection and sends a {@link DatasetChangeEvent}
077: * to all registered listeners.
078: *
079: * @param series the series (<code>null</code> not permitted).
080: */
081: public void addSeries(YIntervalSeries series) {
082: if (series == null) {
083: throw new IllegalArgumentException(
084: "Null 'series' argument.");
085: }
086: this .data.add(series);
087: series.addChangeListener(this );
088: fireDatasetChanged();
089: }
090:
091: /**
092: * Returns the number of series in the collection.
093: *
094: * @return The series count.
095: */
096: public int getSeriesCount() {
097: return this .data.size();
098: }
099:
100: /**
101: * Returns a series from the collection.
102: *
103: * @param series the series index (zero-based).
104: *
105: * @return The series.
106: *
107: * @throws IllegalArgumentException if <code>series</code> is not in the
108: * range <code>0</code> to <code>getSeriesCount() - 1</code>.
109: */
110: public YIntervalSeries getSeries(int series) {
111: if ((series < 0) || (series >= getSeriesCount())) {
112: throw new IllegalArgumentException(
113: "Series index out of bounds");
114: }
115: return (YIntervalSeries) this .data.get(series);
116: }
117:
118: /**
119: * Returns the key for a series.
120: *
121: * @param series the series index (in the range <code>0</code> to
122: * <code>getSeriesCount() - 1</code>).
123: *
124: * @return The key for a series.
125: *
126: * @throws IllegalArgumentException if <code>series</code> is not in the
127: * specified range.
128: */
129: public Comparable getSeriesKey(int series) {
130: // defer argument checking
131: return getSeries(series).getKey();
132: }
133:
134: /**
135: * Returns the number of items in the specified series.
136: *
137: * @param series the series (zero-based index).
138: *
139: * @return The item count.
140: *
141: * @throws IllegalArgumentException if <code>series</code> is not in the
142: * range <code>0</code> to <code>getSeriesCount() - 1</code>.
143: */
144: public int getItemCount(int series) {
145: // defer argument checking
146: return getSeries(series).getItemCount();
147: }
148:
149: /**
150: * Returns the x-value for an item within a series.
151: *
152: * @param series the series index.
153: * @param item the item index.
154: *
155: * @return The x-value.
156: */
157: public Number getX(int series, int item) {
158: YIntervalSeries s = (YIntervalSeries) this .data.get(series);
159: return s.getX(item);
160: }
161:
162: /**
163: * Returns the y-value (as a double primitive) for an item within a
164: * series.
165: *
166: * @param series the series index (zero-based).
167: * @param item the item index (zero-based).
168: *
169: * @return The value.
170: */
171: public double getYValue(int series, int item) {
172: YIntervalSeries s = (YIntervalSeries) this .data.get(series);
173: return s.getYValue(item);
174: }
175:
176: /**
177: * Returns the start y-value (as a double primitive) for an item within a
178: * series.
179: *
180: * @param series the series index (zero-based).
181: * @param item the item index (zero-based).
182: *
183: * @return The value.
184: */
185: public double getStartYValue(int series, int item) {
186: YIntervalSeries s = (YIntervalSeries) this .data.get(series);
187: return s.getYLowValue(item);
188: }
189:
190: /**
191: * Returns the end y-value (as a double primitive) for an item within a
192: * series.
193: *
194: * @param series the series (zero-based index).
195: * @param item the item (zero-based index).
196: *
197: * @return The value.
198: */
199: public double getEndYValue(int series, int item) {
200: YIntervalSeries s = (YIntervalSeries) this .data.get(series);
201: return s.getYHighValue(item);
202: }
203:
204: /**
205: * Returns the y-value for an item within a series.
206: *
207: * @param series the series index.
208: * @param item the item index.
209: *
210: * @return The y-value.
211: */
212: public Number getY(int series, int item) {
213: YIntervalSeries s = (YIntervalSeries) this .data.get(series);
214: return new Double(s.getYValue(item));
215: }
216:
217: /**
218: * Returns the start x-value for an item within a series. This method
219: * maps directly to {@link #getX(int, int)}.
220: *
221: * @param series the series index.
222: * @param item the item index.
223: *
224: * @return The x-value.
225: */
226: public Number getStartX(int series, int item) {
227: return getX(series, item);
228: }
229:
230: /**
231: * Returns the end x-value for an item within a series. This method
232: * maps directly to {@link #getX(int, int)}.
233: *
234: * @param series the series index.
235: * @param item the item index.
236: *
237: * @return The x-value.
238: */
239: public Number getEndX(int series, int item) {
240: return getX(series, item);
241: }
242:
243: /**
244: * Returns the start y-value for an item within a series.
245: *
246: * @param series the series index.
247: * @param item the item index.
248: *
249: * @return The start y-value.
250: */
251: public Number getStartY(int series, int item) {
252: YIntervalSeries s = (YIntervalSeries) this .data.get(series);
253: return new Double(s.getYLowValue(item));
254: }
255:
256: /**
257: * Returns the end y-value for an item within a series.
258: *
259: * @param series the series index.
260: * @param item the item index.
261: *
262: * @return The end y-value.
263: */
264: public Number getEndY(int series, int item) {
265: YIntervalSeries s = (YIntervalSeries) this .data.get(series);
266: return new Double(s.getYHighValue(item));
267: }
268:
269: /**
270: * Tests this instance for equality with an arbitrary object.
271: *
272: * @param obj the object (<code>null</code> permitted).
273: *
274: * @return A boolean.
275: */
276: public boolean equals(Object obj) {
277: if (obj == this ) {
278: return true;
279: }
280: if (!(obj instanceof YIntervalSeriesCollection)) {
281: return false;
282: }
283: YIntervalSeriesCollection that = (YIntervalSeriesCollection) obj;
284: return ObjectUtilities.equal(this .data, that.data);
285: }
286:
287: /**
288: * Returns a clone of this instance.
289: *
290: * @return A clone.
291: *
292: * @throws CloneNotSupportedException if there is a problem.
293: */
294: public Object clone() throws CloneNotSupportedException {
295: YIntervalSeriesCollection clone = (YIntervalSeriesCollection) super
296: .clone();
297: clone.data = (List) ObjectUtilities.deepClone(this.data);
298: return clone;
299: }
300:
301: }
|