KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > data > SubSeriesDataset


1 /* ======================================
2  * JFreeChart : a free Java chart library
3  * ======================================
4  *
5  * Project Info: http://www.jfree.org/jfreechart/index.html
6  * Project Lead: David Gilbert (david.gilbert@object-refinery.com);
7  *
8  * (C) Copyright 2000-2003, by Object Refinery Limited and Contributors.
9  *
10  * This library is free software; you can redistribute it and/or modify it under the terms
11  * of the GNU Lesser General Public License as published by the Free Software Foundation;
12  * either version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License along with this
19  * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20  * Boston, MA 02111-1307, USA.
21  *
22  * ---------------------
23  * SubseriesDataset.java
24  * ---------------------
25  * (C) Copyright 2001-2003, by Bill Kelemen and Contributors.
26  *
27  * Original Author: Bill Kelemen;
28  * Contributor(s): Sylvain Vieujot;
29  * David Gilbert (for Object Refinery Limited);
30  *
31  * $Id: SubSeriesDataset.java,v 1.5 2003/07/24 11:09:13 mungady Exp $
32  *
33  * Changes
34  * -------
35  * 06-Dec-2001 : Version 1 (BK);
36  * 05-Feb-2002 : Added SignalsDataset (and small change to HighLowDataset interface) as requested
37  * by Sylvain Vieujot (DG);
38  * 28-Feb-2002 : Fixed bug: missing map[series] in IntervalXYDataset and SignalsDataset
39  * methods (BK);
40  * 07-Oct-2002 : Fixed errors reported by Checkstyle (DG);
41  *
42  */

43
44 package org.jfree.data;
45
46 /**
47  * This class will create a dataset with one or more series from another
48  * {@link SeriesDataset}.
49  *
50  * @author Bill Kelemen (bill@kelemen-usa.com)
51  */

52 public class SubSeriesDataset extends AbstractSeriesDataset
53                               implements HighLowDataset, SignalsDataset, IntervalXYDataset,
54                                          CombinationDataset {
55
56     /** The parent dataset. */
57     private SeriesDataset parent = null;
58
59     /** Storage for map. */
60     private int[] map; // maps our series into our parent's
61

62     /**
63      * Creates a SubSeriesDataset using one or more series from <code>parent</code>.
64      * The series to use are passed as an array of int.
65      *
66      * @param parent underlying dataset
67      * @param map int[] of series from parent to include in this Dataset
68      */

69     public SubSeriesDataset(SeriesDataset parent, int[] map) {
70         this.parent = parent;
71         this.map = map;
72     }
73
74     /**
75      * Creates a SubSeriesDataset using one series from <code>parent</code>.
76      * The series to is passed as an int.
77      *
78      * @param parent underlying dataset
79      * @param series series from parent to include in this Dataset
80      */

81     public SubSeriesDataset(SeriesDataset parent, int series) {
82         this(parent, new int[] {series});
83     }
84
85     ///////////////////////////////////////////////////////////////////////////
86
// From HighLowDataset
87
///////////////////////////////////////////////////////////////////////////
88

89     /**
90      * Returns the high-value for the specified series and item.
91      * <p>
92      * Note: throws <code>ClassCastException</code> if the series if not from a
93      * {@link HighLowDataset}.
94      *
95      * @param series the index of the series of interest (zero-based).
96      * @param item the index of the item of interest (zero-based).
97      *
98      * @return the high-value for the specified series and item.
99      */

100     public Number JavaDoc getHighValue(int series, int item) {
101         return ((HighLowDataset) parent).getHighValue(map[series], item);
102     }
103
104     /**
105      * Returns the low-value for the specified series and item.
106      * <p>
107      * Note: throws <code>ClassCastException</code> if the series if not from a
108      * {@link HighLowDataset}.
109      *
110      * @param series the index of the series of interest (zero-based).
111      * @param item the index of the item of interest (zero-based).
112      *
113      * @return the low-value for the specified series and item.
114      */

115     public Number JavaDoc getLowValue(int series, int item) {
116         return ((HighLowDataset) parent).getLowValue(map[series], item);
117     }
118
119     /**
120      * Returns the open-value for the specified series and item.
121      * <p>
122      * Note: throws <code>ClassCastException</code> if the series if not from a
123      * {@link HighLowDataset}.
124      *
125      * @param series the index of the series of interest (zero-based).
126      * @param item the index of the item of interest (zero-based).
127      *
128      * @return the open-value for the specified series and item.
129      */

130     public Number JavaDoc getOpenValue(int series, int item) {
131         return ((HighLowDataset) parent).getOpenValue(map[series], item);
132     }
133
134     /**
135      * Returns the close-value for the specified series and item.
136      * <p>
137      * Note: throws <code>ClassCastException</code> if the series if not from a
138      * {@link HighLowDataset}.
139      *
140      * @param series the index of the series of interest (zero-based).
141      * @param item the index of the item of interest (zero-based).
142      *
143      * @return the close-value for the specified series and item.
144      */

145     public Number JavaDoc getCloseValue(int series, int item) {
146         return ((HighLowDataset) parent).getCloseValue(map[series], item);
147     }
148
149     /**
150      * Returns the volume.
151      * <p>
152      * Note: throws <code>ClassCastException</code> if the series if not from a
153      * {@link HighLowDataset}.
154      *
155      * @param series the series (zero based index).
156      * @param item the item (zero based index).
157      *
158      * @return the volume.
159      */

160     public Number JavaDoc getVolumeValue(int series, int item) {
161         return ((HighLowDataset) parent).getVolumeValue(map[series], item);
162     }
163
164
165     ///////////////////////////////////////////////////////////////////////////
166
// From XYDataset
167
///////////////////////////////////////////////////////////////////////////
168

169     /**
170      * Returns the X-value for the specified series and item.
171      * <p>
172      * Note: throws <code>ClassCastException</code> if the series if not from a
173      * {@link XYDataset}.
174      *
175      * @param series the index of the series of interest (zero-based);
176      * @param item the index of the item of interest (zero-based).
177      *
178      * @return the X-value for the specified series and item.
179      */

180     public Number JavaDoc getXValue(int series, int item) {
181         return ((XYDataset) parent).getXValue(map[series], item);
182     }
183
184     /**
185      * Returns the Y-value for the specified series and item.
186      * <p>
187      * Note: throws <code>ClassCastException</code> if the series if not from a
188      * {@link XYDataset}.
189      *
190      * @param series the index of the series of interest (zero-based).
191      * @param item the index of the item of interest (zero-based).
192      *
193      * @return the Y-value for the specified series and item.
194      */

195     public Number JavaDoc getYValue(int series, int item) {
196         return ((XYDataset) parent).getYValue(map[series], item);
197     }
198
199     /**
200      * Returns the number of items in a series.
201      * <p>
202      * Note: throws <code>ClassCastException</code> if the series if not from a
203      * {@link XYDataset}.
204      *
205      * @param series the index of the series of interest (zero-based).
206      *
207      * @return the number of items in a series.
208      */

209     public int getItemCount(int series) {
210         return ((XYDataset) parent).getItemCount(map[series]);
211     }
212
213     ///////////////////////////////////////////////////////////////////////////
214
// From SeriesDataset
215
///////////////////////////////////////////////////////////////////////////
216

217     /**
218      * Returns the number of series in the dataset.
219      *
220      * @return the number of series in the dataset.
221      */

222     public int getSeriesCount() {
223         return map.length;
224     }
225
226     /**
227      * Returns the name of a series.
228      *
229      * @param series the series (zero-based index).
230      *
231      * @return the name of a series.
232      */

233     public String JavaDoc getSeriesName(int series) {
234         return parent.getSeriesName(map[series]);
235     }
236
237     ///////////////////////////////////////////////////////////////////////////
238
// From IntervalXYDataset
239
///////////////////////////////////////////////////////////////////////////
240

241     /**
242      * Returns the starting X value for the specified series and item.
243      *
244      * @param series the index of the series of interest (zero-based).
245      * @param item the index of the item of interest (zero-based).
246      *
247      * @return the starting X value for the specified series and item.
248      */

249     public Number JavaDoc getStartXValue(int series, int item) {
250         if (parent instanceof IntervalXYDataset) {
251             return ((IntervalXYDataset) parent).getStartXValue(map[series], item);
252         }
253         else {
254             return getXValue(series, item);
255         }
256     }
257
258     /**
259      * Returns the ending X value for the specified series and item.
260      *
261      * @param series the index of the series of interest (zero-based).
262      * @param item the index of the item of interest (zero-based).
263      *
264      * @return the ending X value for the specified series and item.
265      */

266     public Number JavaDoc getEndXValue(int series, int item) {
267         if (parent instanceof IntervalXYDataset) {
268             return ((IntervalXYDataset) parent).getEndXValue(map[series], item);
269         }
270         else {
271             return getXValue(series, item);
272         }
273     }
274
275     /**
276      * Returns the starting Y value for the specified series and item.
277      *
278      * @param series the index of the series of interest (zero-based).
279      * @param item the index of the item of interest (zero-based).
280      *
281      * @return the starting Y value for the specified series and item.
282      */

283     public Number JavaDoc getStartYValue(int series, int item) {
284         if (parent instanceof IntervalXYDataset) {
285             return ((IntervalXYDataset) parent).getStartYValue(map[series], item);
286         }
287         else {
288             return getYValue(series, item);
289         }
290     }
291
292     /**
293      * Returns the ending Y value for the specified series and item.
294      *
295      * @param series the index of the series of interest (zero-based).
296      * @param item the index of the item of interest (zero-based).
297      *
298      * @return the ending Y value for the specified series and item.
299      */

300     public Number JavaDoc getEndYValue(int series, int item) {
301         if (parent instanceof IntervalXYDataset) {
302             return ((IntervalXYDataset) parent).getEndYValue(map[series], item);
303         }
304         else {
305             return getYValue(series, item);
306         }
307     }
308
309     ///////////////////////////////////////////////////////////////////////////
310
// From SignalsDataset
311
///////////////////////////////////////////////////////////////////////////
312

313     /**
314      * Returns the type.
315      *
316      * @param series the series (zero based index).
317      * @param item the item (zero based index).
318      *
319      * @return the type.
320      */

321     public int getType(int series, int item) {
322         if (parent instanceof SignalsDataset) {
323             return ((SignalsDataset) parent).getType(map[series], item);
324         }
325         else {
326             return getYValue(series, item).intValue();
327         }
328     }
329
330     /**
331      * Returns the level.
332      *
333      * @param series the series (zero based index).
334      * @param item the item (zero based index).
335      *
336      * @return the level.
337      */

338     public double getLevel(int series, int item) {
339         if (parent instanceof SignalsDataset) {
340             return ((SignalsDataset) parent).getLevel(map[series], item);
341         }
342         else {
343             return getYValue(series, item).doubleValue();
344         }
345     }
346
347     ///////////////////////////////////////////////////////////////////////////
348
// New methods from CombinationDataset
349
///////////////////////////////////////////////////////////////////////////
350

351     /**
352      * Returns the parent Dataset of this combination.
353      *
354      * @return the parent Dataset of this combination.
355      */

356     public SeriesDataset getParent() {
357         return parent;
358     }
359
360     /**
361      * Returns a map or indirect indexing form our series into parent's series.
362      *
363      * @return a map or indirect indexing form our series into parent's series.
364      */

365     public int[] getMap() {
366         return (int[]) map.clone();
367     }
368
369 }
370
Popular Tags