📄 defaultxyzdataset.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.]
*
* ----------------------
* DefaultXYZDataset.java
* ----------------------
* (C) Copyright 2006, by Object Refinery Limited.
*
* Original Author: David Gilbert (for Object Refinery Limited);
* Contributor(s): -;
*
* $Id: DefaultXYZDataset.java,v 1.1.2.4 2006/11/28 14:06:14 mungady Exp $
*
* Changes
* -------
* 12-Jul-2006 : Version 1 (DG);
* 06-Oct-2006 : Fixed API doc warnings (DG);
* 02-Nov-2006 : Fixed a problem with adding a new series with the same key
* as an existing series (see bug 1589392) (DG);
*
*/
package org.jfree.data.xy;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.jfree.data.DomainOrder;
import org.jfree.data.general.DatasetChangeEvent;
/**
* A default implementation of the {@link XYZDataset} interface that stores
* data values in arrays of double primitives.
*
* @since 1.0.2
*/
public class DefaultXYZDataset extends AbstractXYZDataset
implements XYZDataset {
/**
* 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>DefaultXYZDataset</code> instance, initially
* containing no data.
*/
public DefaultXYZDataset() {
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 index of the series with the specified key, or -1 if there
* is no such series in the dataset.
*
* @param seriesKey the series key (<code>null</code> permitted).
*
* @return The index, or -1.
*/
public int indexOf(Comparable seriesKey) {
return this.seriesKeys.indexOf(seriesKey);
}
/**
* Returns the order of the domain (x-) values in the dataset. In this
* implementation, we cannot guarantee that the x-values are ordered, so
* this method returns <code>DomainOrder.NONE</code>.
*
* @return <code>DomainOrder.NONE</code>.
*/
public DomainOrder getDomainOrder() {
return DomainOrder.NONE;
}
/**
* 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 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 #getXValue(int, int)
*/
public Number getX(int series, int item) {
return new Double(getXValue(series, 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) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -