📄 defaultintervalxydataset.java
字号:
/* ===========================================================
* JFreeChart : a free chart library for the Java(tm) platform
* ===========================================================
*
* (C) Copyright 2000-2006, by Object Refinery Limited and Contributors.
*
* Project Info: http://www.jfree.org/jfreechart/index.html
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* -----------------------------
* DefaultIntervalXYDataset.java
* -----------------------------
* (C) Copyright 2006, by Object Refinery Limited and Contributors.
*
* Original Author: David Gilbert (for Object Refinery Limited);
* Contributor(s): -;
*
* $Id: DefaultIntervalXYDataset.java,v 1.1.2.3 2006/11/28 14:06:14 mungady Exp $
*
* Changes
* -------
* 23-Oct-2006 : Version 1 (DG);
* 02-Nov-2006 : Fixed a problem with adding a new series with the same key
* as an existing series (see bug 1589392) (DG);
* 28-Nov-2006 : New override for clone() (DG);
*
*/
package org.jfree.data.xy;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.jfree.data.general.DatasetChangeEvent;
/**
* A dataset that defines a range (interval) for both the x-values and the
* y-values. This implementation uses six arrays to store the x, start-x,
* end-x, y, start-y and end-y values.
* <br><br>
* An alternative implementation of the {@link IntervalXYDataset} interface
* is provided by the {@link XYIntervalSeriesCollection} class.
*
* @since 1.0.3
*/
public class DefaultIntervalXYDataset extends AbstractIntervalXYDataset {
/**
* Storage for the series keys. This list must be kept in sync with the
* seriesList.
*/
private List seriesKeys;
/**
* Storage for the series in the dataset. We use a list because the
* order of the series is significant. This list must be kept in sync
* with the seriesKeys list.
*/
private List seriesList;
/**
* Creates a new <code>DefaultIntervalXYDataset</code> instance, initially
* containing no data.
*/
public DefaultIntervalXYDataset() {
this.seriesKeys = new java.util.ArrayList();
this.seriesList = new java.util.ArrayList();
}
/**
* Returns the number of series in the dataset.
*
* @return The series count.
*/
public int getSeriesCount() {
return this.seriesList.size();
}
/**
* Returns the key for a series.
*
* @param series the series index (in the range <code>0</code> to
* <code>getSeriesCount() - 1</code>).
*
* @return The key for the series.
*
* @throws IllegalArgumentException if <code>series</code> is not in the
* specified range.
*/
public Comparable getSeriesKey(int series) {
if ((series < 0) || (series >= getSeriesCount())) {
throw new IllegalArgumentException("Series index out of bounds");
}
return (Comparable) this.seriesKeys.get(series);
}
/**
* Returns the number of items in the specified series.
*
* @param series the series index (in the range <code>0</code> to
* <code>getSeriesCount() - 1</code>).
*
* @return The item count.
*
* @throws IllegalArgumentException if <code>series</code> is not in the
* specified range.
*/
public int getItemCount(int series) {
if ((series < 0) || (series >= getSeriesCount())) {
throw new IllegalArgumentException("Series index out of bounds");
}
double[][] seriesArray = (double[][]) this.seriesList.get(series);
return seriesArray[0].length;
}
/**
* Returns the x-value for an item within a series.
*
* @param series the series index (in the range <code>0</code> to
* <code>getSeriesCount() - 1</code>).
* @param item the item index (in the range <code>0</code> to
* <code>getItemCount(series)</code>).
*
* @return The x-value.
*
* @throws ArrayIndexOutOfBoundsException if <code>series</code> is not
* within the specified range.
* @throws ArrayIndexOutOfBoundsException if <code>item</code> is not
* within the specified range.
*
* @see #getX(int, int)
*/
public double getXValue(int series, int item) {
double[][] seriesData = (double[][]) this.seriesList.get(series);
return seriesData[0][item];
}
/**
* Returns the y-value for an item within a series.
*
* @param series the series index (in the range <code>0</code> to
* <code>getSeriesCount() - 1</code>).
* @param item the item index (in the range <code>0</code> to
* <code>getItemCount(series)</code>).
*
* @return The y-value.
*
* @throws ArrayIndexOutOfBoundsException if <code>series</code> is not
* within the specified range.
* @throws ArrayIndexOutOfBoundsException if <code>item</code> is not
* within the specified range.
*
* @see #getY(int, int)
*/
public double getYValue(int series, int item) {
double[][] seriesData = (double[][]) this.seriesList.get(series);
return seriesData[3][item];
}
/**
* Returns the starting x-value for an item within a series.
*
* @param series the series index (in the range <code>0</code> to
* <code>getSeriesCount() - 1</code>).
* @param item the item index (in the range <code>0</code> to
* <code>getItemCount(series)</code>).
*
* @return The starting x-value.
*
* @throws ArrayIndexOutOfBoundsException if <code>series</code> is not
* within the specified range.
* @throws ArrayIndexOutOfBoundsException if <code>item</code> is not
* within the specified range.
*
* @see #getStartX(int, int)
*/
public double getStartXValue(int series, int item) {
double[][] seriesData = (double[][]) this.seriesList.get(series);
return seriesData[1][item];
}
/**
* Returns the ending x-value for an item within a series.
*
* @param series the series index (in the range <code>0</code> to
* <code>getSeriesCount() - 1</code>).
* @param item the item index (in the range <code>0</code> to
* <code>getItemCount(series)</code>).
*
* @return The ending x-value.
*
* @throws ArrayIndexOutOfBoundsException if <code>series</code> is not
* within the specified range.
* @throws ArrayIndexOutOfBoundsException if <code>item</code> is not
* within the specified range.
*
* @see #getEndX(int, int)
*/
public double getEndXValue(int series, int item) {
double[][] seriesData = (double[][]) this.seriesList.get(series);
return seriesData[2][item];
}
/**
* Returns the starting y-value for an item within a series.
*
* @param series the series index (in the range <code>0</code> to
* <code>getSeriesCount() - 1</code>).
* @param item the item index (in the range <code>0</code> to
* <code>getItemCount(series)</code>).
*
* @return The starting y-value.
*
* @throws ArrayIndexOutOfBoundsException if <code>series</code> is not
* within the specified range.
* @throws ArrayIndexOutOfBoundsException if <code>item</code> is not
* within the specified range.
*
* @see #getStartY(int, int)
*/
public double getStartYValue(int series, int item) {
double[][] seriesData = (double[][]) this.seriesList.get(series);
return seriesData[4][item];
}
/**
* Returns the ending y-value for an item within a series.
*
* @param series the series index (in the range <code>0</code> to
* <code>getSeriesCount() - 1</code>).
* @param item the item index (in the range <code>0</code> to
* <code>getItemCount(series)</code>).
*
* @return The ending y-value.
*
* @throws ArrayIndexOutOfBoundsException if <code>series</code> is not
* within the specified range.
* @throws ArrayIndexOutOfBoundsException if <code>item</code> is not
* within the specified range.
*
* @see #getEndY(int, int)
*/
public double getEndYValue(int series, int item) {
double[][] seriesData = (double[][]) this.seriesList.get(series);
return seriesData[5][item];
}
/**
* Returns the ending x-value for an item within a series.
*
* @param series the series index (in the range <code>0</code> to
* <code>getSeriesCount() - 1</code>).
* @param item the item index (in the range <code>0</code> to
* <code>getItemCount(series)</code>).
*
* @return The ending x-value.
*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -