Package org.jfree.data.xy
Class DefaultXYDataset
- java.lang.Object
-
- org.jfree.data.general.AbstractDataset
-
- org.jfree.data.general.AbstractSeriesDataset
-
- org.jfree.data.xy.AbstractXYDataset
-
- org.jfree.data.xy.DefaultXYDataset
-
- All Implemented Interfaces:
java.io.ObjectInputValidation
,java.io.Serializable
,java.lang.Cloneable
,java.util.EventListener
,PublicCloneable
,Dataset
,SeriesChangeListener
,SeriesDataset
,XYDataset
public class DefaultXYDataset extends AbstractXYDataset implements XYDataset, PublicCloneable
A default implementation of theXYDataset
interface that stores data values in arrays of double primitives.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List
seriesKeys
Storage for the series keys.private java.util.List
seriesList
Storage for the series in the dataset.
-
Constructor Summary
Constructors Constructor Description DefaultXYDataset()
Creates a newDefaultXYDataset
instance, initially containing no data.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addSeries(java.lang.Comparable seriesKey, double[][] data)
Adds a series or if a series with the same key already exists replaces the data for that series, then sends aDatasetChangeEvent
to all registered listeners.java.lang.Object
clone()
Creates an independent copy of this dataset.boolean
equals(java.lang.Object obj)
Tests thisDefaultXYDataset
instance for equality with an arbitrary object.DomainOrder
getDomainOrder()
Returns the order of the domain (x-) values in the dataset.int
getItemCount(int series)
Returns the number of items in the specified series.int
getSeriesCount()
Returns the number of series in the dataset.java.lang.Comparable
getSeriesKey(int series)
Returns the key for a series.java.lang.Number
getX(int series, int item)
Returns the x-value for an item within a series.double
getXValue(int series, int item)
Returns the x-value for an item within a series.java.lang.Number
getY(int series, int item)
Returns the y-value for an item within a series.double
getYValue(int series, int item)
Returns the y-value for an item within a series.int
hashCode()
Returns a hash code for this instance.int
indexOf(java.lang.Comparable seriesKey)
Returns the index of the series with the specified key, or -1 if there is no such series in the dataset.void
removeSeries(java.lang.Comparable seriesKey)
Removes a series from the dataset, then sends aDatasetChangeEvent
to all registered listeners.-
Methods inherited from class org.jfree.data.general.AbstractSeriesDataset
seriesChanged
-
Methods inherited from class org.jfree.data.general.AbstractDataset
addChangeListener, canEqual, fireDatasetChanged, getGroup, getNotify, hasListener, notifyListeners, removeChangeListener, setGroup, setNotify, validateObject
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.jfree.data.general.Dataset
addChangeListener, getGroup, removeChangeListener, setGroup
-
-
-
-
Field Detail
-
seriesKeys
private java.util.List seriesKeys
Storage for the series keys. This list must be kept in sync with the seriesList.
-
seriesList
private java.util.List seriesList
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.
-
-
Method Detail
-
getSeriesCount
public int getSeriesCount()
Returns the number of series in the dataset.- Specified by:
getSeriesCount
in interfaceSeriesDataset
- Specified by:
getSeriesCount
in classAbstractSeriesDataset
- Returns:
- The series count.
-
getSeriesKey
public java.lang.Comparable getSeriesKey(int series)
Returns the key for a series.- Specified by:
getSeriesKey
in interfaceSeriesDataset
- Specified by:
getSeriesKey
in classAbstractSeriesDataset
- Parameters:
series
- the series index (in the range0
togetSeriesCount() - 1
).- Returns:
- The key for the series.
- Throws:
java.lang.IllegalArgumentException
- ifseries
is not in the specified range.
-
indexOf
public int indexOf(java.lang.Comparable seriesKey)
Returns the index of the series with the specified key, or -1 if there is no such series in the dataset.- Specified by:
indexOf
in interfaceSeriesDataset
- Overrides:
indexOf
in classAbstractSeriesDataset
- Parameters:
seriesKey
- the series key (null
permitted).- Returns:
- The index, or -1.
-
getDomainOrder
public DomainOrder getDomainOrder()
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 returnsDomainOrder.NONE
.- Specified by:
getDomainOrder
in interfaceXYDataset
- Overrides:
getDomainOrder
in classAbstractXYDataset
- Returns:
DomainOrder.NONE
.
-
getItemCount
public int getItemCount(int series)
Returns the number of items in the specified series.- Specified by:
getItemCount
in interfaceXYDataset
- Parameters:
series
- the series index (in the range0
togetSeriesCount() - 1
).- Returns:
- The item count.
- Throws:
java.lang.IllegalArgumentException
- ifseries
is not in the specified range.
-
getXValue
public double getXValue(int series, int item)
Returns the x-value for an item within a series.- Specified by:
getXValue
in interfaceXYDataset
- Overrides:
getXValue
in classAbstractXYDataset
- Parameters:
series
- the series index (in the range0
togetSeriesCount() - 1
).item
- the item index (in the range0
togetItemCount(series)
).- Returns:
- The x-value.
- Throws:
java.lang.ArrayIndexOutOfBoundsException
- ifseries
is not within the specified range.java.lang.ArrayIndexOutOfBoundsException
- ifitem
is not within the specified range.- See Also:
getX(int, int)
-
getX
public java.lang.Number getX(int series, int item)
Returns the x-value for an item within a series.- Specified by:
getX
in interfaceXYDataset
- Parameters:
series
- the series index (in the range0
togetSeriesCount() - 1
).item
- the item index (in the range0
togetItemCount(series)
).- Returns:
- The x-value.
- Throws:
java.lang.ArrayIndexOutOfBoundsException
- ifseries
is not within the specified range.java.lang.ArrayIndexOutOfBoundsException
- ifitem
is not within the specified range.- See Also:
getXValue(int, int)
-
getYValue
public double getYValue(int series, int item)
Returns the y-value for an item within a series.- Specified by:
getYValue
in interfaceXYDataset
- Overrides:
getYValue
in classAbstractXYDataset
- Parameters:
series
- the series index (in the range0
togetSeriesCount() - 1
).item
- the item index (in the range0
togetItemCount(series)
).- Returns:
- The y-value.
- Throws:
java.lang.ArrayIndexOutOfBoundsException
- ifseries
is not within the specified range.java.lang.ArrayIndexOutOfBoundsException
- ifitem
is not within the specified range.- See Also:
getY(int, int)
-
getY
public java.lang.Number getY(int series, int item)
Returns the y-value for an item within a series.- Specified by:
getY
in interfaceXYDataset
- Parameters:
series
- the series index (in the range0
togetSeriesCount() - 1
).item
- the item index (in the range0
togetItemCount(series)
).- Returns:
- The y-value.
- Throws:
java.lang.ArrayIndexOutOfBoundsException
- ifseries
is not within the specified range.java.lang.ArrayIndexOutOfBoundsException
- ifitem
is not within the specified range.- See Also:
getX(int, int)
-
addSeries
public void addSeries(java.lang.Comparable seriesKey, double[][] data)
Adds a series or if a series with the same key already exists replaces the data for that series, then sends aDatasetChangeEvent
to all registered listeners.- Parameters:
seriesKey
- the series key (null
not permitted).data
- the data (must be an array with length 2, containing two arrays of equal length, the first containing the x-values and the second containing the y-values).
-
removeSeries
public void removeSeries(java.lang.Comparable seriesKey)
Removes a series from the dataset, then sends aDatasetChangeEvent
to all registered listeners.- Parameters:
seriesKey
- the series key (null
not permitted).
-
equals
public boolean equals(java.lang.Object obj)
Tests thisDefaultXYDataset
instance for equality with an arbitrary object. This method returnstrue
if and only if:obj
is notnull
;obj
is an instance ofDefaultXYDataset
;- both datasets have the same number of series, each containing exactly the same values.
- Overrides:
equals
in classAbstractDataset
- Parameters:
obj
- the object (null
permitted).- Returns:
- A boolean.
-
hashCode
public int hashCode()
Returns a hash code for this instance.- Overrides:
hashCode
in classAbstractDataset
- Returns:
- A hash code.
-
clone
public java.lang.Object clone() throws java.lang.CloneNotSupportedException
Creates an independent copy of this dataset.- Specified by:
clone
in interfacePublicCloneable
- Overrides:
clone
in classAbstractDataset
- Returns:
- The cloned dataset.
- Throws:
java.lang.CloneNotSupportedException
- if there is a problem cloning the dataset (for instance, if a non-cloneable object is used for a series key).
-
-