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: * XYIntervalSeriesCollection.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: XYIntervalSeriesCollection.java,v 1.1.2.5 2007/02/13 16:12:46 mungady Exp $
036: *
037: * Changes
038: * -------
039: * 20-Oct-2006 : Version 1 (DG);
040: * 13-Feb-2007 : Provided a number of method overrides that enhance
041: * performance, and added a proper clone()
042: * implementation (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 XYIntervalSeries} objects.
056: *
057: * @since 1.0.3
058: *
059: * @see XYIntervalSeries
060: */
061: public class XYIntervalSeriesCollection 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>XIntervalSeriesCollection</code>.
070: */
071: public XYIntervalSeriesCollection() {
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(XYIntervalSeries 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 XYIntervalSeries getSeries(int series) {
111: if ((series < 0) || (series >= getSeriesCount())) {
112: throw new IllegalArgumentException(
113: "Series index out of bounds");
114: }
115: return (XYIntervalSeries) 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: XYIntervalSeries s = (XYIntervalSeries) this .data.get(series);
159: return s.getX(item);
160: }
161:
162: /**
163: * Returns the start x-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 getStartXValue(int series, int item) {
172: XYIntervalSeries s = (XYIntervalSeries) this .data.get(series);
173: return s.getXLowValue(item);
174: }
175:
176: /**
177: * Returns the end x-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 getEndXValue(int series, int item) {
186: XYIntervalSeries s = (XYIntervalSeries) this .data.get(series);
187: return s.getXHighValue(item);
188: }
189:
190: /**
191: * Returns the y-value (as a double primitive) for an item within a
192: * series.
193: *
194: * @param series the series index (zero-based).
195: * @param item the item index (zero-based).
196: *
197: * @return The value.
198: */
199: public double getYValue(int series, int item) {
200: XYIntervalSeries s = (XYIntervalSeries) this .data.get(series);
201: return s.getYValue(item);
202: }
203:
204: /**
205: * Returns the start y-value (as a double primitive) for an item within a
206: * series.
207: *
208: * @param series the series index (zero-based).
209: * @param item the item index (zero-based).
210: *
211: * @return The value.
212: */
213: public double getStartYValue(int series, int item) {
214: XYIntervalSeries s = (XYIntervalSeries) this .data.get(series);
215: return s.getYLowValue(item);
216: }
217:
218: /**
219: * Returns the end y-value (as a double primitive) for an item within a
220: * series.
221: *
222: * @param series the series (zero-based index).
223: * @param item the item (zero-based index).
224: *
225: * @return The value.
226: */
227: public double getEndYValue(int series, int item) {
228: XYIntervalSeries s = (XYIntervalSeries) this .data.get(series);
229: return s.getYHighValue(item);
230: }
231:
232: /**
233: * Returns the y-value for an item within a series.
234: *
235: * @param series the series index.
236: * @param item the item index.
237: *
238: * @return The y-value.
239: */
240: public Number getY(int series, int item) {
241: return new Double(getYValue(series, item));
242: }
243:
244: /**
245: * Returns the start x-value for an item within a series.
246: *
247: * @param series the series index.
248: * @param item the item index.
249: *
250: * @return The x-value.
251: */
252: public Number getStartX(int series, int item) {
253: return new Double(getStartXValue(series, item));
254: }
255:
256: /**
257: * Returns the end x-value for an item within a series.
258: *
259: * @param series the series index.
260: * @param item the item index.
261: *
262: * @return The x-value.
263: */
264: public Number getEndX(int series, int item) {
265: return new Double(getEndXValue(series, item));
266: }
267:
268: /**
269: * Returns the start y-value for an item within a series. This method
270: * maps directly to {@link #getY(int, int)}.
271: *
272: * @param series the series index.
273: * @param item the item index.
274: *
275: * @return The start y-value.
276: */
277: public Number getStartY(int series, int item) {
278: return new Double(getStartYValue(series, item));
279: }
280:
281: /**
282: * Returns the end y-value for an item within a series. This method
283: * maps directly to {@link #getY(int, int)}.
284: *
285: * @param series the series index.
286: * @param item the item index.
287: *
288: * @return The end y-value.
289: */
290: public Number getEndY(int series, int item) {
291: return new Double(getEndYValue(series, item));
292: }
293:
294: /**
295: * Tests this instance for equality with an arbitrary object.
296: *
297: * @param obj the object (<code>null</code> permitted).
298: *
299: * @return A boolean.
300: */
301: public boolean equals(Object obj) {
302: if (obj == this ) {
303: return true;
304: }
305: if (!(obj instanceof XYIntervalSeriesCollection)) {
306: return false;
307: }
308: XYIntervalSeriesCollection that = (XYIntervalSeriesCollection) obj;
309: return ObjectUtilities.equal(this .data, that.data);
310: }
311:
312: /**
313: * Returns a clone of this dataset.
314: *
315: * @return A clone of this dataset.
316: *
317: * @throws CloneNotSupportedException if there is a problem cloning.
318: */
319: public Object clone() throws CloneNotSupportedException {
320: XYIntervalSeriesCollection clone = (XYIntervalSeriesCollection) super
321: .clone();
322: int seriesCount = getSeriesCount();
323: clone.data = new java.util.ArrayList(seriesCount);
324: for (int i = 0; i < this.data.size(); i++) {
325: clone.data.set(i, getSeries(i).clone());
326: }
327: return clone;
328: }
329:
330: }
|