java.lang.Object
org.jfree.data.DefaultKeyedValues<K>
- Type Parameters:
K
- the key type (String
is 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
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Updates an existing value, or adds a new value to the collection.void
Adds a new value to the collection, or updates an existing value.void
clear()
Clears all values from the collection.clone()
Returns a clone.boolean
Tests if this object is equal to another.int
Returns the index for a given key.int
Returns 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.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, 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
removeValue
(int index) Removes a value from the collection.void
removeValue
(K key) Removes a value from the collection.void
Updates an existing value, or adds a new value to the collection.void
Updates an existing value, or adds a new value to the collection.void
sortByKeys
(SortOrder order) Sorts the items in the list by key.void
sortByValues
(SortOrder order) Sorts the items in the list by value.
-
Constructor Details
-
DefaultKeyedValues
public DefaultKeyedValues()Creates a new collection (initially empty).
-
-
Method Details
-
getItemCount
public int getItemCount()Returns the number of items (values) in the collection.- Specified by:
getItemCount
in interfaceValues
- Returns:
- The item count.
-
getValue
Returns a value.- Specified by:
getValue
in interfaceValues
- Parameters:
item
- the item of interest (zero-based index).- Returns:
- The value (possibly
null
). - Throws:
IndexOutOfBoundsException
- ifitem
is out of bounds.
-
getKey
Returns a key.- Specified by:
getKey
in interfaceKeyedValues<K extends Comparable<K>>
- Parameters:
index
- the item index (zero-based).- Returns:
- The row key.
- Throws:
IndexOutOfBoundsException
- ifitem
is out of bounds.
-
getIndex
Returns the index for a given key.- Specified by:
getIndex
in interfaceKeyedValues<K extends Comparable<K>>
- Parameters:
key
- the key (null
not permitted).- Returns:
- The index, or
-1
if the key is not recognised. - Throws:
IllegalArgumentException
- ifkey
isnull
.
-
getKeys
Returns the keys for the values in the collection.- Specified by:
getKeys
in interfaceKeyedValues<K extends Comparable<K>>
- Returns:
- The keys (never
null
).
-
getValue
Returns the value for a given key.- Specified by:
getValue
in interfaceKeyedValues<K extends Comparable<K>>
- Parameters:
key
- the key (null
not 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 (null
not 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 (null
not permitted).value
- the value (null
permitted).
-
setValue
Updates an existing value, or adds a new value to the collection.- Parameters:
key
- the key (null
not permitted).value
- the value.
-
setValue
Updates an existing value, or adds a new value to the collection.- Parameters:
key
- the key (null
not permitted).value
- the value (null
permitted).
-
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 (null
not 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 (null
not permitted).value
- the value (null
permitted).
-
removeValue
public void removeValue(int index) Removes a value from the collection.- Parameters:
index
- the index of the item to remove (in the range0
togetItemCount() -1
).- Throws:
IndexOutOfBoundsException
- ifindex
is not within the specified range.
-
removeValue
Removes a value from the collection.- Parameters:
key
- the item key (null
not permitted).- Throws:
IllegalArgumentException
- ifkey
isnull
.UnknownKeyException
- ifkey
is not recognised.
-
clear
public void clear()Clears all values from the collection. -
sortByKeys
Sorts the items in the list by key.- Parameters:
order
- the sort order (null
not permitted).
-
sortByValues
Sorts the items in the list by value. If the list containsnull
values, they will sort to the end of the list, irrespective of the sort order.- Parameters:
order
- the sort order (null
not permitted).
-
equals
Tests if this object is equal to another. -
hashCode
public int hashCode()Returns a hash code. -
clone
Returns a clone.- Specified by:
clone
in interfacePublicCloneable
- Overrides:
clone
in classObject
- Returns:
- A clone.
- Throws:
CloneNotSupportedException
- this class will not throw this exception, but subclasses might.
-