Package org.jfree.data.general
Class DefaultPieDataset
java.lang.Object
org.jfree.data.general.AbstractDataset
org.jfree.data.general.DefaultPieDataset
- All Implemented Interfaces:
ObjectInputValidation
,Serializable
,Cloneable
,Dataset
,PieDataset
,KeyedValues
,Values
,org.jfree.util.PublicCloneable
- Direct Known Subclasses:
DefaultKeyedValuesDataset
,JDBCPieDataset
public class DefaultPieDataset
extends AbstractDataset
implements PieDataset, Cloneable, org.jfree.util.PublicCloneable, Serializable
A default implementation of the
PieDataset
interface.- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate DefaultKeyedValues
Storage for the data.private static final long
For serialization. -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new dataset, initially empty.DefaultPieDataset
(KeyedValues data) Creates a new dataset by copying data from aKeyedValues
instance. -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Clears all data from this dataset and sends aDatasetChangeEvent
to all registered listeners (unless the dataset was already empty).clone()
Returns a clone of the dataset.boolean
Tests if this object is equal to another.int
getIndex
(Comparable key) Returns the index for a key, or -1 if the key is not recognised.int
Returns the number of items in the dataset.getKey
(int item) Returns the key for the specified item, ornull
.getKeys()
Returns the categories in the dataset.getValue
(int item) Returns a value.getValue
(Comparable key) Returns the data value associated with a key.int
hashCode()
Returns a hash code.void
insertValue
(int position, Comparable key, double value) Inserts a new value at the specified position in the dataset or, if there is an existing item with the specified key, updates the value for that item and moves it to the specified position.void
insertValue
(int position, Comparable key, Number value) Inserts a new value at the specified position in the dataset or, if there is an existing item with the specified key, updates the value for that item and moves it to the specified position.void
remove
(Comparable key) Removes an item from the dataset and sends aDatasetChangeEvent
to all registered listeners.void
setValue
(Comparable key, double value) Sets the data value for a key and sends aDatasetChangeEvent
to all registered listeners.void
setValue
(Comparable key, Number value) Sets the data value for a key and sends aDatasetChangeEvent
to all registered listeners.void
sortByKeys
(org.jfree.util.SortOrder order) Sorts the dataset's items by key and sends aDatasetChangeEvent
to all registered listeners.void
sortByValues
(org.jfree.util.SortOrder order) Sorts the dataset's items by value and sends aDatasetChangeEvent
to all registered listeners.Methods inherited from class org.jfree.data.general.AbstractDataset
addChangeListener, 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 Details
-
serialVersionUID
private static final long serialVersionUIDFor serialization.- See Also:
-
data
Storage for the data.
-
-
Constructor Details
-
DefaultPieDataset
public DefaultPieDataset()Constructs a new dataset, initially empty. -
DefaultPieDataset
Creates a new dataset by copying data from aKeyedValues
instance.- Parameters:
data
- the data (null
not permitted).
-
-
Method Details
-
getItemCount
public int getItemCount()Returns the number of items in the dataset.- Specified by:
getItemCount
in interfaceValues
- Returns:
- The item count.
-
getKeys
Returns the categories in the dataset. The returned list is unmodifiable.- Specified by:
getKeys
in interfaceKeyedValues
- Returns:
- The categories in the dataset.
-
getKey
Returns the key for the specified item, ornull
.- Specified by:
getKey
in interfaceKeyedValues
- Parameters:
item
- the item index (in the range0
togetItemCount() - 1
).- Returns:
- The key, or
null
. - Throws:
IndexOutOfBoundsException
- ifitem
is not in the specified range.
-
getIndex
Returns the index for a key, or -1 if the key is not recognised.- Specified by:
getIndex
in interfaceKeyedValues
- Parameters:
key
- the key (null
not permitted).- Returns:
- The index, or
-1
if the key is unrecognised. - Throws:
IllegalArgumentException
- ifkey
isnull
.
-
getValue
Returns a value. -
getValue
Returns the data value associated with a key.- Specified by:
getValue
in interfaceKeyedValues
- Parameters:
key
- the key (null
not permitted).- Returns:
- The value (possibly
null
). - Throws:
UnknownKeyException
- if the key is not recognised.
-
setValue
Sets the data value for a key and sends aDatasetChangeEvent
to all registered listeners.- Parameters:
key
- the key (null
not permitted).value
- the value.- Throws:
IllegalArgumentException
- ifkey
isnull
.
-
setValue
Sets the data value for a key and sends aDatasetChangeEvent
to all registered listeners.- Parameters:
key
- the key (null
not permitted).value
- the value.- Throws:
IllegalArgumentException
- ifkey
isnull
.
-
insertValue
Inserts a new value at the specified position in the dataset or, if there is an existing item with the specified key, updates the value for that item and moves it to the specified position. After the change is made, this methods sends aDatasetChangeEvent
to all registered listeners.- Parameters:
position
- the position (in the range 0 to getItemCount()).key
- the key (null
not permitted).value
- the value (null
permitted).- Since:
- 1.0.6
-
insertValue
Inserts a new value at the specified position in the dataset or, if there is an existing item with the specified key, updates the value for that item and moves it to the specified position. After the change is made, this methods sends aDatasetChangeEvent
to all registered listeners.- Parameters:
position
- the position (in the range 0 to getItemCount()).key
- the key (null
not permitted).value
- the value (null
permitted).- Since:
- 1.0.6
-
remove
Removes an item from the dataset and sends aDatasetChangeEvent
to all registered listeners.- Parameters:
key
- the key (null
not permitted).- Throws:
IllegalArgumentException
- ifkey
isnull
.
-
clear
public void clear()Clears all data from this dataset and sends aDatasetChangeEvent
to all registered listeners (unless the dataset was already empty).- Since:
- 1.0.2
-
sortByKeys
public void sortByKeys(org.jfree.util.SortOrder order) Sorts the dataset's items by key and sends aDatasetChangeEvent
to all registered listeners.- Parameters:
order
- the sort order (null
not permitted).- Since:
- 1.0.3
-
sortByValues
public void sortByValues(org.jfree.util.SortOrder order) Sorts the dataset's items by value and sends aDatasetChangeEvent
to all registered listeners.- Parameters:
order
- the sort order (null
not permitted).- Since:
- 1.0.3
-
equals
Tests if this object is equal to another. -
hashCode
public int hashCode()Returns a hash code. -
clone
Returns a clone of the dataset.- Specified by:
clone
in interfaceorg.jfree.util.PublicCloneable
- Overrides:
clone
in classAbstractDataset
- Returns:
- A clone.
- Throws:
CloneNotSupportedException
- This class will not throw this exception, but subclasses (if any) might.
-