📄 combineddataset.java
字号:
/* ======================================
* JFreeChart : a free Java chart library
* ======================================
*
* Project Info: http://www.jfree.org/jfreechart/index.html
* Project Lead: David Gilbert (david.gilbert@object-refinery.com);
*
* (C) Copyright 2000-2003, by Object Refinery Limited and Contributors.
*
* This library is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation;
* either version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* --------------------
* CombinedDataset.java
* --------------------
* (C) Copyright 2001-2003, by Bill Kelemen.
*
* Original Author: Bill Kelemen;
* Contributor(s): -;
*
* $Id: CombinedDataset.java,v 1.5 2003/07/25 12:31:09 mungady Exp $
*
* Changes
* -------
* 06-Dec-2001 : Version 1 (BK);
* 27-Dec-2001 : Fixed bug in getChildPosition method (BK);
* 29-Dec-2001 : Fixed bug in getChildPosition method with complex CombinePlot (BK);
* 05-Feb-2002 : Small addition to the interface HighLowDataset, as requested by Sylvain
* Vieujot (DG);
* 14-Feb-2002 : Added bug fix for IntervalXYDataset methods, submitted by Gyula Kun-Szabo (DG);
* 11-Jun-2002 : Updated for change in event constructor (DG);
* 04-Oct-2002 : Fixed errors reported by Checkstyle (DG);
*
*/
package org.jfree.data;
import java.util.List;
/**
* This class can combine instances of {@link XYDataset}, {@link HighLowDataset} and
* {@link IntervalXYDataset} together exposing the union of all the series under one dataset.
*
* @author Bill Kelemen (bill@kelemen-usa.com)
*/
public class CombinedDataset extends AbstractSeriesDataset
implements XYDataset, HighLowDataset, IntervalXYDataset,
CombinationDataset {
/** Storage for the datasets we combine. */
private List datasetInfo = new java.util.ArrayList();
/**
* Default constructor for an empty combination.
*/
public CombinedDataset() {
}
/**
* Creates a CombinedDataset initialized with an array of SeriesDatasets.
*
* @param data array of SeriesDataset that contains the SeriesDatasets to combine.
*/
public CombinedDataset(SeriesDataset[] data) {
add(data);
}
/**
* Adds one SeriesDataset to the combination. Listeners are notified of the change.
*
* @param data the SeriesDataset to add.
*/
public void add(SeriesDataset data) {
fastAdd(data);
DatasetChangeEvent event = new DatasetChangeEvent(this, this);
notifyListeners(event);
}
/**
* Adds an array of SeriesDataset's to the combination. Listeners are
* notified of the change.
*
* @param data array of SeriesDataset to add
*/
public void add(SeriesDataset[] data) {
for (int i = 0; i < data.length; i++) {
fastAdd(data[i]);
}
DatasetChangeEvent event = new DatasetChangeEvent(this, this);
notifyListeners(event);
}
/**
* Adds one series from a SeriesDataset to the combination. Listeners are
* notified of the change.
*
* @param data the SeriesDataset where series is contained
* @param series series to add
*/
public void add(SeriesDataset data, int series) {
add(new SubSeriesDataset(data, series));
}
/**
* Fast add of a SeriesDataset. Does not notify listeners of the change.
*
* @param data SeriesDataset to add
*/
private void fastAdd(SeriesDataset data) {
for (int i = 0; i < data.getSeriesCount(); i++) {
datasetInfo.add(new DatasetInfo(data, i));
}
}
///////////////////////////////////////////////////////////////////////////
// From SeriesDataset
///////////////////////////////////////////////////////////////////////////
/**
* Returns the number of series in the dataset.
*
* @return The number of series in the dataset.
*/
public int getSeriesCount() {
return datasetInfo.size();
}
/**
* Returns the name of a series.
*
* @param series the series (zero-based index).
*
* @return the name of a series.
*/
public String getSeriesName(int series) {
DatasetInfo di = getDatasetInfo(series);
return di.data.getSeriesName(di.series);
}
///////////////////////////////////////////////////////////////////////////
// From XYDataset
///////////////////////////////////////////////////////////////////////////
/**
* Returns the X-value for the specified series and item.
* <P>
* Note: throws <code>ClassCastException</code> if the series is not from a {@link XYDataset}.
*
* @param series the index of the series of interest (zero-based).
* @param item the index of the item of interest (zero-based).
*
* @return the X-value for the specified series and item.
*/
public Number getXValue(int series, int item) {
DatasetInfo di = getDatasetInfo(series);
return ((XYDataset) di.data).getXValue(di.series, item);
}
/**
* Returns the Y-value for the specified series and item.
* <P>
* Note: throws <code>ClassCastException</code> if the series is not from a {@link XYDataset}.
*
* @param series the index of the series of interest (zero-based).
* @param item the index of the item of interest (zero-based).
*
* @return the Y-value for the specified series and item.
*/
public Number getYValue(int series, int item) {
DatasetInfo di = getDatasetInfo(series);
return ((XYDataset) di.data).getYValue(di.series, item);
}
/**
* Returns the number of items in a series.
* <P>
* Note: throws <code>ClassCastException</code> if the series is not from a {@link XYDataset}.
*
* @param series the index of the series of interest (zero-based).
*
* @return the number of items in a series.
*/
public int getItemCount(int series) {
DatasetInfo di = getDatasetInfo(series);
return ((XYDataset) di.data).getItemCount(di.series);
}
///////////////////////////////////////////////////////////////////////////
// From HighLowDataset
///////////////////////////////////////////////////////////////////////////
/**
* Returns the high-value for the specified series and item.
* <P>
* Note: throws <code>ClassCastException</code> if the series is not from a
* {@link HighLowDataset}.
*
* @param series the index of the series of interest (zero-based).
* @param item the index of the item of interest (zero-based).
*
* @return the high-value for the specified series and item.
*/
public Number getHighValue(int series, int item) {
DatasetInfo di = getDatasetInfo(series);
return ((HighLowDataset) di.data).getHighValue(di.series, item);
}
/**
* Returns the low-value for the specified series and item.
* <P>
* Note: throws <code>ClassCastException</code> if the series is not from a
* {@link HighLowDataset}.
*
* @param series the index of the series of interest (zero-based).
* @param item the index of the item of interest (zero-based).
*
* @return the low-value for the specified series and item.
*/
public Number getLowValue(int series, int item) {
DatasetInfo di = getDatasetInfo(series);
return ((HighLowDataset) di.data).getLowValue(di.series, item);
}
/**
* Returns the open-value for the specified series and item.
* <P>
* Note: throws <code>ClassCastException</code> if the series is not from a
* {@link HighLowDataset}.
*
* @param series the index of the series of interest (zero-based).
* @param item the index of the item of interest (zero-based).
*
* @return the open-value for the specified series and item.
*/
public Number getOpenValue(int series, int item) {
DatasetInfo di = getDatasetInfo(series);
return ((HighLowDataset) di.data).getOpenValue(di.series, item);
}
/**
* Returns the close-value for the specified series and item.
* <P>
* Note: throws <code>ClassCastException</code> if the series is not from a
* {@link HighLowDataset}.
*
* @param series the index of the series of interest (zero-based).
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -