KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > data > xy > XYIntervalSeriesCollection


1 /* ===========================================================
2  * JFreeChart : a free chart library for the Java(tm) platform
3  * ===========================================================
4  *
5  * (C) Copyright 2000-2006, 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  * XYIntervalSeriesCollection.java
29  * -------------------------------
30  * (C) Copyright 2006, by Object Refinery Limited.
31  *
32  * Original Author: David Gilbert (for Object Refinery Limited);
33  * Contributor(s): -;
34  *
35  * $Id: XYIntervalSeriesCollection.java,v 1.1.2.3 2006/10/23 09:22:41 mungady Exp $
36  *
37  * Changes
38  * -------
39  * 20-Oct-2006 : Version 1 (DG);
40  *
41  */

42
43 package org.jfree.data.xy;
44
45 import java.io.Serializable JavaDoc;
46 import java.util.List JavaDoc;
47
48 import org.jfree.data.general.DatasetChangeEvent;
49 import org.jfree.util.ObjectUtilities;
50
51 /**
52  * A collection of {@link XYIntervalSeries} objects.
53  *
54  * @since 1.0.3
55  *
56  * @see XIntervalSeries
57  */

58 public class XYIntervalSeriesCollection extends AbstractIntervalXYDataset
59                                 implements IntervalXYDataset, Serializable JavaDoc {
60
61     /** Storage for the data series. */
62     private List JavaDoc data;
63     
64     /**
65      * Creates a new instance of <code>XIntervalSeriesCollection</code>.
66      */

67     public XYIntervalSeriesCollection() {
68         this.data = new java.util.ArrayList JavaDoc();
69     }
70
71     /**
72      * Adds a series to the collection and sends a {@link DatasetChangeEvent}
73      * to all registered listeners.
74      *
75      * @param series the series (<code>null</code> not permitted).
76      */

77     public void addSeries(XYIntervalSeries series) {
78         if (series == null) {
79             throw new IllegalArgumentException JavaDoc("Null 'series' argument.");
80         }
81         this.data.add(series);
82         series.addChangeListener(this);
83         fireDatasetChanged();
84     }
85
86     /**
87      * Returns the number of series in the collection.
88      *
89      * @return The series count.
90      */

91     public int getSeriesCount() {
92         return this.data.size();
93     }
94
95     /**
96      * Returns a series from the collection.
97      *
98      * @param series the series index (zero-based).
99      *
100      * @return The series.
101      *
102      * @throws IllegalArgumentException if <code>series</code> is not in the
103      * range <code>0</code> to <code>getSeriesCount() - 1</code>.
104      */

105     public XYIntervalSeries getSeries(int series) {
106         if ((series < 0) || (series >= getSeriesCount())) {
107             throw new IllegalArgumentException JavaDoc("Series index out of bounds");
108         }
109         return (XYIntervalSeries) this.data.get(series);
110     }
111
112     /**
113      * Returns the key for a series.
114      *
115      * @param series the series index (in the range <code>0</code> to
116      * <code>getSeriesCount() - 1</code>).
117      *
118      * @return The key for a series.
119      *
120      * @throws IllegalArgumentException if <code>series</code> is not in the
121      * specified range.
122      */

123     public Comparable JavaDoc getSeriesKey(int series) {
124         // defer argument checking
125
return getSeries(series).getKey();
126     }
127
128     /**
129      * Returns the number of items in the specified series.
130      *
131      * @param series the series (zero-based index).
132      *
133      * @return The item count.
134      *
135      * @throws IllegalArgumentException if <code>series</code> is not in the
136      * range <code>0</code> to <code>getSeriesCount() - 1</code>.
137      */

138     public int getItemCount(int series) {
139         // defer argument checking
140
return getSeries(series).getItemCount();
141     }
142
143     /**
144      * Returns the x-value for an item within a series.
145      *
146      * @param series the series index.
147      * @param item the item index.
148      *
149      * @return The x-value.
150      */

151     public Number JavaDoc getX(int series, int item) {
152         XYIntervalSeries s = (XYIntervalSeries) this.data.get(series);
153         XYIntervalDataItem di = (XYIntervalDataItem) s.getDataItem(item);
154         return di.getX();
155     }
156
157     /**
158      * Returns the y-value for an item within a series.
159      *
160      * @param series the series index.
161      * @param item the item index.
162      *
163      * @return The y-value.
164      */

165     public Number JavaDoc getY(int series, int item) {
166         XYIntervalSeries s = (XYIntervalSeries) this.data.get(series);
167         XYIntervalDataItem di = (XYIntervalDataItem) s.getDataItem(item);
168         return new Double JavaDoc(di.getYValue());
169     }
170
171     /**
172      * Returns the start x-value for an item within a series.
173      *
174      * @param series the series index.
175      * @param item the item index.
176      *
177      * @return The x-value.
178      */

179     public Number JavaDoc getStartX(int series, int item) {
180         XYIntervalSeries s = (XYIntervalSeries) this.data.get(series);
181         XYIntervalDataItem di = (XYIntervalDataItem) s.getDataItem(item);
182         return new Double JavaDoc(di.getXLowValue());
183     }
184
185     /**
186      * Returns the end x-value for an item within a series.
187      *
188      * @param series the series index.
189      * @param item the item index.
190      *
191      * @return The x-value.
192      */

193     public Number JavaDoc getEndX(int series, int item) {
194         XYIntervalSeries s = (XYIntervalSeries) this.data.get(series);
195         XYIntervalDataItem di = (XYIntervalDataItem) s.getDataItem(item);
196         return new Double JavaDoc(di.getXHighValue());
197     }
198
199     /**
200      * Returns the start y-value for an item within a series. This method
201      * maps directly to {@link #getY(int, int)}.
202      *
203      * @param series the series index.
204      * @param item the item index.
205      *
206      * @return The start y-value.
207      */

208     public Number JavaDoc getStartY(int series, int item) {
209         XYIntervalSeries s = (XYIntervalSeries) this.data.get(series);
210         XYIntervalDataItem di = (XYIntervalDataItem) s.getDataItem(item);
211         return new Double JavaDoc(di.getYLowValue());
212     }
213
214     /**
215      * Returns the end y-value for an item within a series. This method
216      * maps directly to {@link #getY(int, int)}.
217      *
218      * @param series the series index.
219      * @param item the item index.
220      *
221      * @return The end y-value.
222      */

223     public Number JavaDoc getEndY(int series, int item) {
224         XYIntervalSeries s = (XYIntervalSeries) this.data.get(series);
225         XYIntervalDataItem di = (XYIntervalDataItem) s.getDataItem(item);
226         return new Double JavaDoc(di.getYHighValue());
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 JavaDoc obj) {
237         if (obj == this) {
238             return true;
239         }
240         if (!(obj instanceof XYIntervalSeriesCollection)) {
241             return false;
242         }
243         XYIntervalSeriesCollection that = (XYIntervalSeriesCollection) obj;
244         return ObjectUtilities.equal(this.data, that.data);
245     }
246     
247 }
248
Popular Tags