001: /* ===========================================================
002: * JFreeChart : a free chart library for the Java(tm) platform
003: * ===========================================================
004: *
005: * (C) Copyright 2000-2006, 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: * XIntervalSeriesCollection.java
029: * ------------------------------
030: * (C) Copyright 2006, by Object Refinery Limited.
031: *
032: * Original Author: David Gilbert (for Object Refinery Limited);
033: * Contributor(s): -;
034: *
035: * $Id: XIntervalSeriesCollection.java,v 1.1.2.3 2006/11/27 17:27:52 mungady Exp $
036: *
037: * Changes
038: * -------
039: * 20-Oct-2006 : Version 1 (DG);
040: * 27-Nov-2006 : Added clone() override (DG);
041: *
042: */
043:
044: package org.jfree.data.xy;
045:
046: import java.io.Serializable;
047: import java.util.List;
048:
049: import org.jfree.data.general.DatasetChangeEvent;
050: import org.jfree.util.ObjectUtilities;
051:
052: /**
053: * A collection of {@link XIntervalSeries} objects.
054: *
055: * @since 1.0.3
056: *
057: * @see XIntervalSeries
058: */
059: public class XIntervalSeriesCollection extends
060: AbstractIntervalXYDataset implements IntervalXYDataset,
061: Serializable {
062:
063: /** Storage for the data series. */
064: private List data;
065:
066: /**
067: * Creates a new instance of <code>XIntervalSeriesCollection</code>.
068: */
069: public XIntervalSeriesCollection() {
070: this .data = new java.util.ArrayList();
071: }
072:
073: /**
074: * Adds a series to the collection and sends a {@link DatasetChangeEvent}
075: * to all registered listeners.
076: *
077: * @param series the series (<code>null</code> not permitted).
078: */
079: public void addSeries(XIntervalSeries series) {
080: if (series == null) {
081: throw new IllegalArgumentException(
082: "Null 'series' argument.");
083: }
084: this .data.add(series);
085: series.addChangeListener(this );
086: fireDatasetChanged();
087: }
088:
089: /**
090: * Returns the number of series in the collection.
091: *
092: * @return The series count.
093: */
094: public int getSeriesCount() {
095: return this .data.size();
096: }
097:
098: /**
099: * 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 XIntervalSeries getSeries(int series) {
109: if ((series < 0) || (series >= getSeriesCount())) {
110: throw new IllegalArgumentException(
111: "Series index out of bounds");
112: }
113: return (XIntervalSeries) this .data.get(series);
114: }
115:
116: /**
117: * Returns the key for a series.
118: *
119: * @param series the series index (in the range <code>0</code> to
120: * <code>getSeriesCount() - 1</code>).
121: *
122: * @return The key for a series.
123: *
124: * @throws IllegalArgumentException if <code>series</code> is not in the
125: * specified range.
126: */
127: public Comparable getSeriesKey(int series) {
128: // defer argument checking
129: return getSeries(series).getKey();
130: }
131:
132: /**
133: * Returns the number of items in the specified series.
134: *
135: * @param series the series (zero-based index).
136: *
137: * @return The item count.
138: *
139: * @throws IllegalArgumentException if <code>series</code> is not in the
140: * range <code>0</code> to <code>getSeriesCount() - 1</code>.
141: */
142: public int getItemCount(int series) {
143: // defer argument checking
144: return getSeries(series).getItemCount();
145: }
146:
147: /**
148: * Returns the x-value for an item within a series.
149: *
150: * @param series the series index.
151: * @param item the item index.
152: *
153: * @return The x-value.
154: */
155: public Number getX(int series, int item) {
156: XIntervalSeries s = (XIntervalSeries) this .data.get(series);
157: XIntervalDataItem di = (XIntervalDataItem) s.getDataItem(item);
158: return di.getX();
159: }
160:
161: /**
162: * Returns the y-value for an item within a series.
163: *
164: * @param series the series index.
165: * @param item the item index.
166: *
167: * @return The y-value.
168: */
169: public Number getY(int series, int item) {
170: XIntervalSeries s = (XIntervalSeries) this .data.get(series);
171: XIntervalDataItem di = (XIntervalDataItem) s.getDataItem(item);
172: return new Double(di.getYValue());
173: }
174:
175: /**
176: * Returns the start x-value for an item within a series.
177: *
178: * @param series the series index.
179: * @param item the item index.
180: *
181: * @return The x-value.
182: */
183: public Number getStartX(int series, int item) {
184: XIntervalSeries s = (XIntervalSeries) this .data.get(series);
185: XIntervalDataItem di = (XIntervalDataItem) s.getDataItem(item);
186: return new Double(di.getXLowValue());
187: }
188:
189: /**
190: * Returns the end x-value for an item within a series.
191: *
192: * @param series the series index.
193: * @param item the item index.
194: *
195: * @return The x-value.
196: */
197: public Number getEndX(int series, int item) {
198: XIntervalSeries s = (XIntervalSeries) this .data.get(series);
199: XIntervalDataItem di = (XIntervalDataItem) s.getDataItem(item);
200: return new Double(di.getXHighValue());
201: }
202:
203: /**
204: * Returns the start y-value for an item within a series. This method
205: * maps directly to {@link #getY(int, int)}.
206: *
207: * @param series the series index.
208: * @param item the item index.
209: *
210: * @return The start y-value.
211: */
212: public Number getStartY(int series, int item) {
213: return getY(series, item);
214: }
215:
216: /**
217: * Returns the end y-value for an item within a series. This method
218: * maps directly to {@link #getY(int, int)}.
219: *
220: * @param series the series index.
221: * @param item the item index.
222: *
223: * @return The end y-value.
224: */
225: public Number getEndY(int series, int item) {
226: return getY(series, item);
227: }
228:
229: /**
230: * Tests this instance for equality with an arbitrary object.
231: *
232: * @param obj the object (<code>null</code> permitted).
233: *
234: * @return A boolean.
235: */
236: public boolean equals(Object obj) {
237: if (obj == this ) {
238: return true;
239: }
240: if (!(obj instanceof XIntervalSeriesCollection)) {
241: return false;
242: }
243: XIntervalSeriesCollection that = (XIntervalSeriesCollection) obj;
244: return ObjectUtilities.equal(this .data, that.data);
245: }
246:
247: /**
248: * Returns a clone of this instance.
249: *
250: * @return A clone.
251: *
252: * @throws CloneNotSupportedException if there is a problem.
253: */
254: public Object clone() throws CloneNotSupportedException {
255: XIntervalSeriesCollection clone = (XIntervalSeriesCollection) super
256: .clone();
257: clone.data = (List) ObjectUtilities.deepClone(this.data);
258: return clone;
259: }
260:
261: }
|