Package org.jfree.data.general
Class DefaultPieDataset<K extends java.lang.Comparable<K>>
- java.lang.Object
-
- org.jfree.data.general.AbstractDataset
-
- org.jfree.data.general.DefaultPieDataset<K>
-
- Type Parameters:
K
- Key type for PieDataset
- All Implemented Interfaces:
java.io.ObjectInputValidation
,java.io.Serializable
,java.lang.Cloneable
,PublicCloneable
,Dataset
,PieDataset<K>
,KeyedValues<K>
,Values
- Direct Known Subclasses:
DefaultKeyedValuesDataset
,JDBCPieDataset
public class DefaultPieDataset<K extends java.lang.Comparable<K>> extends AbstractDataset implements PieDataset<K>, java.lang.Cloneable, PublicCloneable, java.io.Serializable
A default implementation of thePieDataset
interface.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private DefaultKeyedValues<K>
data
Storage for the data.private static long
serialVersionUID
For serialization.
-
Constructor Summary
Constructors Constructor Description DefaultPieDataset()
Constructs a new dataset, initially empty.DefaultPieDataset(KeyedValues<K> source)
Creates a new dataset by copying data from aKeyedValues
instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Clears all data from this dataset and sends aDatasetChangeEvent
to all registered listeners (unless the dataset was already empty).java.lang.Object
clone()
Returns a clone of the dataset.boolean
equals(java.lang.Object obj)
Tests if this object is equal to another.int
getIndex(K key)
Returns the index for a key, or -1 if the key is not recognised.int
getItemCount()
Returns the number of items in the dataset.K
getKey(int item)
Returns the key for the specified item, ornull
.java.util.List<K>
getKeys()
Returns the categories in the dataset.java.lang.Number
getValue(int item)
Returns a value.java.lang.Number
getValue(K key)
Returns the data value associated with a key.int
hashCode()
Returns a hash code.void
insertValue(int position, K 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, K key, java.lang.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(K key)
Removes an item from the dataset and sends aDatasetChangeEvent
to all registered listeners.void
setValue(K key, double value)
Sets the data value for a key and sends aDatasetChangeEvent
to all registered listeners.void
setValue(K key, java.lang.Number value)
Sets the data value for a key and sends aDatasetChangeEvent
to all registered listeners.void
sortByKeys(SortOrder order)
Sorts the dataset's items by key and sends aDatasetChangeEvent
to all registered listeners.void
sortByValues(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, 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
-
serialVersionUID
private static final long serialVersionUID
For serialization.- See Also:
- Constant Field Values
-
data
private DefaultKeyedValues<K extends java.lang.Comparable<K>> data
Storage for the data.
-
-
Constructor Detail
-
DefaultPieDataset
public DefaultPieDataset()
Constructs a new dataset, initially empty.
-
DefaultPieDataset
public DefaultPieDataset(KeyedValues<K> source)
Creates a new dataset by copying data from aKeyedValues
instance.- Parameters:
source
- the data (null
not permitted).
-
-
Method Detail
-
getItemCount
public int getItemCount()
Returns the number of items in the dataset.- Specified by:
getItemCount
in interfaceValues
- Returns:
- The item count.
-
getKeys
public java.util.List<K> getKeys()
Returns the categories in the dataset. The returned list is unmodifiable.- Specified by:
getKeys
in interfaceKeyedValues<K extends java.lang.Comparable<K>>
- Returns:
- The categories in the dataset.
-
getKey
public K getKey(int item)
Returns the key for the specified item, ornull
.- Specified by:
getKey
in interfaceKeyedValues<K extends java.lang.Comparable<K>>
- Parameters:
item
- the item index (in the range0
togetItemCount() - 1
).- Returns:
- The key, or
null
. - Throws:
java.lang.IndexOutOfBoundsException
- ifitem
is not in the specified range.
-
getIndex
public int getIndex(K key)
Returns the index for a key, or -1 if the key is not recognised.- Specified by:
getIndex
in interfaceKeyedValues<K extends java.lang.Comparable<K>>
- Parameters:
key
- the key (null
not permitted).- Returns:
- The index, or
-1
if the key is unrecognised. - Throws:
java.lang.IllegalArgumentException
- ifkey
isnull
.
-
getValue
public java.lang.Number getValue(int item)
Returns a value.
-
getValue
public java.lang.Number getValue(K key)
Returns the data value associated with a key.- Specified by:
getValue
in interfaceKeyedValues<K extends java.lang.Comparable<K>>
- Parameters:
key
- the key (null
not permitted).- Returns:
- The value (possibly
null
). - Throws:
UnknownKeyException
- if the key is not recognised.
-
setValue
public void setValue(K key, java.lang.Number value)
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:
java.lang.IllegalArgumentException
- ifkey
isnull
.
-
setValue
public void setValue(K key, double value)
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:
java.lang.IllegalArgumentException
- ifkey
isnull
.
-
insertValue
public void insertValue(int position, K 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. 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).
-
insertValue
public void insertValue(int position, K key, java.lang.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. 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).
-
remove
public void remove(K key)
Removes an item from the dataset and sends aDatasetChangeEvent
to all registered listeners.- Parameters:
key
- the key (null
not permitted).- Throws:
java.lang.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).
-
sortByKeys
public void sortByKeys(SortOrder order)
Sorts the dataset's items by key and sends aDatasetChangeEvent
to all registered listeners.- Parameters:
order
- the sort order (null
not permitted).
-
sortByValues
public void sortByValues(SortOrder order)
Sorts the dataset's items by value and sends aDatasetChangeEvent
to all registered listeners.- Parameters:
order
- the sort order (null
not permitted).
-
equals
public boolean equals(java.lang.Object obj)
Tests if this object is equal to another.- Overrides:
equals
in classAbstractDataset
- Parameters:
obj
- the other object.- Returns:
- A boolean.
-
hashCode
public int hashCode()
Returns a hash code.- Overrides:
hashCode
in classAbstractDataset
- Returns:
- A hash code.
-
clone
public java.lang.Object clone() throws java.lang.CloneNotSupportedException
Returns a clone of the dataset.- Specified by:
clone
in interfacePublicCloneable
- Overrides:
clone
in classAbstractDataset
- Returns:
- A clone.
- Throws:
java.lang.CloneNotSupportedException
- This class will not throw this exception, but subclasses (if any) might.
-
-