Module org.jfree.chart
Package org.jfree.data.general
Class DefaultPieDataset<K extends 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:
ObjectInputValidation,Serializable,Cloneable,PublicCloneable,Dataset,PieDataset<K>,KeyedValues<K>,Values
- Direct Known Subclasses:
DefaultKeyedValuesDataset
public class DefaultPieDataset<K extends Comparable<K>> extends AbstractDataset implements PieDataset<K>, Cloneable, PublicCloneable, Serializable
A default implementation of thePieDatasetinterface.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description DefaultPieDataset()Constructs a new dataset, initially empty.DefaultPieDataset(KeyedValues<K> source)Creates a new dataset by copying data from aKeyedValuesinstance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Clears all data from this dataset and sends aDatasetChangeEventto all registered listeners (unless the dataset was already empty).Objectclone()Returns a clone of the dataset.booleanequals(Object obj)Tests if this object is equal to another.intgetIndex(K key)Returns the index for a key, or -1 if the key is not recognised.intgetItemCount()Returns the number of items in the dataset.KgetKey(int item)Returns the key for the specified item, ornull.List<K>getKeys()Returns the categories in the dataset.NumbergetValue(int item)Returns a value.NumbergetValue(K key)Returns the data value associated with a key.inthashCode()Returns a hash code.voidinsertValue(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.voidinsertValue(int position, K 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.voidremove(K key)Removes an item from the dataset and sends aDatasetChangeEventto all registered listeners.voidsetValue(K key, double value)Sets the data value for a key and sends aDatasetChangeEventto all registered listeners.voidsetValue(K key, Number value)Sets the data value for a key and sends aDatasetChangeEventto all registered listeners.voidsortByKeys(SortOrder order)Sorts the dataset's items by key and sends aDatasetChangeEventto all registered listeners.voidsortByValues(SortOrder order)Sorts the dataset's items by value and sends aDatasetChangeEventto all registered listeners.-
Methods inherited from class org.jfree.data.general.AbstractDataset
addChangeListener, fireDatasetChanged, getNotify, hasListener, notifyListeners, removeChangeListener, 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, removeChangeListener
-
-
-
-
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 aKeyedValuesinstance.- Parameters:
source- the data (nullnot permitted).
-
-
Method Detail
-
getItemCount
public int getItemCount()
Returns the number of items in the dataset.- Specified by:
getItemCountin interfaceValues- Returns:
- The item count.
-
getKeys
public List<K> getKeys()
Returns the categories in the dataset. The returned list is unmodifiable.- Specified by:
getKeysin interfaceKeyedValues<K extends Comparable<K>>- Returns:
- The categories in the dataset.
-
getKey
public K getKey(int item)
Returns the key for the specified item, ornull.- Specified by:
getKeyin interfaceKeyedValues<K extends Comparable<K>>- Parameters:
item- the item index (in the range0togetItemCount() - 1).- Returns:
- The key, or
null. - Throws:
IndexOutOfBoundsException- ifitemis 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:
getIndexin interfaceKeyedValues<K extends Comparable<K>>- Parameters:
key- the key (nullnot permitted).- Returns:
- The index, or
-1if the key is unrecognised. - Throws:
IllegalArgumentException- ifkeyisnull.
-
getValue
public Number getValue(K key)
Returns the data value associated with a key.- Specified by:
getValuein interfaceKeyedValues<K extends Comparable<K>>- Parameters:
key- the key (nullnot permitted).- Returns:
- The value (possibly
null). - Throws:
UnknownKeyException- if the key is not recognised.
-
setValue
public void setValue(K key, Number value)
Sets the data value for a key and sends aDatasetChangeEventto all registered listeners.- Parameters:
key- the key (nullnot permitted).value- the value.- Throws:
IllegalArgumentException- ifkeyisnull.
-
setValue
public void setValue(K key, double value)
Sets the data value for a key and sends aDatasetChangeEventto all registered listeners.- Parameters:
key- the key (nullnot permitted).value- the value.- Throws:
IllegalArgumentException- ifkeyisnull.
-
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 aDatasetChangeEventto all registered listeners.- Parameters:
position- the position (in the range 0 to getItemCount()).key- the key (nullnot permitted).value- the value (nullpermitted).- Since:
- 1.0.6
-
insertValue
public void insertValue(int position, K 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. After the change is made, this methods sends aDatasetChangeEventto all registered listeners.- Parameters:
position- the position (in the range 0 to getItemCount()).key- the key (nullnot permitted).value- the value (nullpermitted).- Since:
- 1.0.6
-
remove
public void remove(K key)
Removes an item from the dataset and sends aDatasetChangeEventto all registered listeners.- Parameters:
key- the key (nullnot permitted).- Throws:
IllegalArgumentException- ifkeyisnull.
-
clear
public void clear()
Clears all data from this dataset and sends aDatasetChangeEventto all registered listeners (unless the dataset was already empty).- Since:
- 1.0.2
-
sortByKeys
public void sortByKeys(SortOrder order)
Sorts the dataset's items by key and sends aDatasetChangeEventto all registered listeners.- Parameters:
order- the sort order (nullnot permitted).- Since:
- 1.0.3
-
sortByValues
public void sortByValues(SortOrder order)
Sorts the dataset's items by value and sends aDatasetChangeEventto all registered listeners.- Parameters:
order- the sort order (nullnot permitted).- Since:
- 1.0.3
-
hashCode
public int hashCode()
Returns a hash code.
-
clone
public Object clone() throws CloneNotSupportedException
Returns a clone of the dataset.- Specified by:
clonein interfacePublicCloneable- Overrides:
clonein classAbstractDataset- Returns:
- A clone.
- Throws:
CloneNotSupportedException- This class will not throw this exception, but subclasses (if any) might.
-
-