Package org.jfree.data
Class DefaultKeyedValues<K extends Comparable<K>>
java.lang.Object
org.jfree.data.DefaultKeyedValues<K>
- Type Parameters:
K- the key type (Stringis a good default).
- All Implemented Interfaces:
Serializable,Cloneable,PublicCloneable,KeyedValues<K>,Values
public class DefaultKeyedValues<K extends Comparable<K>>
extends Object
implements KeyedValues<K>, Cloneable, 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 TypeMethodDescriptionvoidUpdates an existing value, or adds a new value to the collection.voidAdds 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.intReturns 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.Returns the value for a given 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.voidremoveValue(int index) Removes a value from the collection.voidremoveValue(K key) Removes a value from the collection.voidUpdates an existing value, or adds a new value to the collection.voidUpdates an existing value, or adds a new value to the collection.voidsortByKeys(SortOrder order) Sorts the items in the list by key.voidsortByValues(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<K extends Comparable<K>>- 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<K extends Comparable<K>>- 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<K extends Comparable<K>>- Returns:
- The keys (never
null).
-
getValue
Returns the value for a given 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.- 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.
-
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).
-
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. -
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 interfacePublicCloneable- Overrides:
clonein classObject- Returns:
- A clone.
- Throws:
CloneNotSupportedException- this class will not throw this exception, but subclasses might.
-