Package org.jfree.data
Class DefaultKeyedValues
java.lang.Object
org.jfree.data.DefaultKeyedValues
- All Implemented Interfaces:
Serializable,Cloneable,KeyedValues,Values,org.jfree.util.PublicCloneable
public class DefaultKeyedValues
extends Object
implements KeyedValues, Cloneable, org.jfree.util.PublicCloneable, Serializable
An ordered list of (key, value) items. This class provides a default
implementation of the
KeyedValues interface.- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddValue(Comparable key, double value) Updates an existing value, or adds a new value to the collection.voidaddValue(Comparable key, Number value) Adds a new value to the collection, or updates an existing value.voidclear()Clears all values from the collection.clone()Returns a clone.booleanTests if this object is equal to another.intgetIndex(Comparable key) Returns the index for a given key.intReturns the number of items (values) in the collection.getKey(int index) Returns a key.getKeys()Returns the keys for the values in the collection.getValue(int item) Returns a value.getValue(Comparable key) Returns the value for a given key.inthashCode()Returns a hash code.voidinsertValue(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.voidinsertValue(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.voidremoveValue(int index) Removes a value from the collection.voidremoveValue(Comparable key) Removes a value from the collection.voidsetValue(Comparable key, double value) Updates an existing value, or adds a new value to the collection.voidsetValue(Comparable key, Number value) Updates an existing value, or adds a new value to the collection.voidsortByKeys(org.jfree.util.SortOrder order) Sorts the items in the list by key.voidsortByValues(org.jfree.util.SortOrder order) Sorts the items in the list by value.
-
Constructor Details
-
DefaultKeyedValues
public DefaultKeyedValues()Creates a new collection (initially empty).
-
-
Method Details
-
getItemCount
Returns the number of items (values) in the collection.- Specified by:
getItemCountin interfaceValues- Returns:
- The item count.
-
getValue
Returns a value.- Specified by:
getValuein interfaceValues- Parameters:
item- the item of interest (zero-based index).- Returns:
- The value (possibly
null). - Throws:
IndexOutOfBoundsException- ifitemis out of bounds.
-
getKey
Returns a key.- Specified by:
getKeyin interfaceKeyedValues- Parameters:
index- the item index (zero-based).- Returns:
- The row key.
- Throws:
IndexOutOfBoundsException- ifitemis out of bounds.
-
getIndex
Returns the index for a given key.- Specified by:
getIndexin interfaceKeyedValues- Parameters:
key- the key (nullnot permitted).- Returns:
- The index, or
-1if the key is not recognised. - Throws:
IllegalArgumentException- ifkeyisnull.
-
getKeys
Returns the keys for the values in the collection.- Specified by:
getKeysin interfaceKeyedValues- Returns:
- The keys (never
null).
-
getValue
Returns the value for a given key.- Specified by:
getValuein interfaceKeyedValues- Parameters:
key- the key (nullnot permitted).- Returns:
- The value (possibly
null). - Throws:
UnknownKeyException- if the key is not recognised.- See Also:
-
addValue
Updates an existing value, or adds a new value to the collection.- Parameters:
key- the key (nullnot permitted).value- the value.- See Also:
-
addValue
Adds a new value to the collection, or updates an existing value. This method passes control directly to thesetValue(Comparable, Number)method.- Parameters:
key- the key (nullnot permitted).value- the value (nullpermitted).
-
setValue
Updates an existing value, or adds a new value to the collection.- Parameters:
key- the key (nullnot permitted).value- the value.
-
setValue
Updates an existing value, or adds a new value to the collection.- Parameters:
key- the key (nullnot permitted).value- the value (nullpermitted).
-
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.- Parameters:
position- the position (in the range 0 to getItemCount()).key- the key (nullnot permitted).value- the value.- 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.- Parameters:
position- the position (in the range 0 to getItemCount()).key- the key (nullnot permitted).value- the value (nullpermitted).- Since:
- 1.0.6
-
removeValue
Removes a value from the collection.- Parameters:
index- the index of the item to remove (in the range0togetItemCount() - 1).- Throws:
IndexOutOfBoundsException- ifindexis not within the specified range.
-
removeValue
Removes a value from the collection.- Parameters:
key- the item key (nullnot permitted).- Throws:
IllegalArgumentException- ifkeyisnull.UnknownKeyException- ifkeyis not recognised.
-
clear
Clears all values from the collection.- Since:
- 1.0.2
-
sortByKeys
Sorts the items in the list by key.- Parameters:
order- the sort order (nullnot permitted).
-
sortByValues
Sorts the items in the list by value. If the list containsnullvalues, they will sort to the end of the list, irrespective of the sort order.- Parameters:
order- the sort order (nullnot permitted).
-
equals
Tests if this object is equal to another. -
hashCode
Returns a hash code. -
clone
Returns a clone.- Specified by:
clonein interfaceorg.jfree.util.PublicCloneable- Overrides:
clonein classObject- Returns:
- A clone.
- Throws:
CloneNotSupportedException- this class will not throw this exception, but subclasses might.
-