KickJava   Java API By Example, From Geeks To Geeks.

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


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  * XIntervalSeriesCollection.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: XIntervalSeriesCollection.java,v 1.1.2.2 2006/10/21 05:13:47 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 XIntervalSeries} objects.
53  *
54  * @since 1.0.3
55  *
56  * @see XIntervalSeries
57  */

58 public class XIntervalSeriesCollection 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 XIntervalSeriesCollection() {
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(XIntervalSeries 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 XIntervalSeries getSeries(int series) {
106         if ((series < 0) || (series >= getSeriesCount())) {
107             throw new IllegalArgumentException JavaDoc("Series index out of bounds");
108         }
109         return (XIntervalSeries) 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         XIntervalSeries s = (XIntervalSeries) this.data.get(series);
153         XIntervalDataItem di = (XIntervalDataItem) 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         XIntervalSeries s = (XIntervalSeries) this.data.get(series);
167         XIntervalDataItem di = (XIntervalDataItem) 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         XIntervalSeries s = (XIntervalSeries) this.data.get(series);
181         XIntervalDataItem di = (XIntervalDataItem) 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         XIntervalSeries s = (XIntervalSeries) this.data.get(series);
195         XIntervalDataItem di = (XIntervalDataItem) 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         return getY(series, item);
210     }
211
212     /**
213      * Returns the end y-value for an item within a series. This method
214      * maps directly to {@link #getY(int, int)}.
215      *
216      * @param series the series index.
217      * @param item the item index.
218      *
219      * @return The end y-value.
220      */

221     public Number JavaDoc getEndY(int series, int item) {
222         return getY(series, item);
223     }
224     
225     /**
226      * Tests this instance for equality with an arbitrary object.
227      *
228      * @param obj the object (<code>null</code> permitted).
229      *
230      * @return A boolean.
231      */

232     public boolean equals(Object JavaDoc obj) {
233         if (obj == this) {
234             return true;
235         }
236         if (!(obj instanceof XIntervalSeriesCollection)) {
237             return false;
238         }
239         XIntervalSeriesCollection that = (XIntervalSeriesCollection) obj;
240         return ObjectUtilities.equal(this.data, that.data);
241     }
242     
243 }
244
Popular Tags