Package org.jfree.data
Class DefaultKeyedValues
java.lang.Object
org.jfree.data.DefaultKeyedValues
- All Implemented Interfaces:
Serializable
,Cloneable
,KeyedValues
,Values
public class DefaultKeyedValues extends Object implements KeyedValues, Cloneable, Serializable
A collection of (key, value) pairs. This class provides a default
implementation of the
KeyedValues
interface.- See Also:
- Serialized Form
-
Constructor Summary
Constructors Constructor Description DefaultKeyedValues()
Creates a new collection (initially empty). -
Method Summary
Modifier and Type Method Description void
addValue(Comparable key, Number value)
Adds a new value to the collection, or updates an existing value.Object
clone()
Returns a clone.boolean
equals(Object o)
Tests if this object is equal to another.int
getIndex(Comparable key)
Returns the index for a given key or -1 if the key is not found.int
getItemCount()
Returns the number of items (values) in the collection.Comparable
getKey(int index)
Returns a key.List
getKeys()
Returns the keys for the values in the collection.Number
getValue(int item)
Returns a value.Number
getValue(Comparable key)
Returns the value (possiblynull
) for a given key.int
hashCode()
Returns a hash code.void
removeValue(int index)
Removes a value from the collection.void
removeValue(Comparable key)
Removes a value from the collection.void
setValue(Comparable key, Number value)
Updates an existing value, or adds a new value to the collection.void
sortByKeys(org.jfree.util.SortOrder order)
Sorts the items in the list by key.void
sortByValues(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
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. -
getKey
Returns a key.- Specified by:
getKey
in interfaceKeyedValues
- Parameters:
index
- the item index (zero-based).- Returns:
- the row key.
-
getIndex
Returns the index for a given key or -1 if the key is not found.- Specified by:
getIndex
in interfaceKeyedValues
- Parameters:
key
- the key.- Returns:
- the index.
-
getKeys
Returns the keys for the values in the collection.- Specified by:
getKeys
in interfaceKeyedValues
- Returns:
- The keys (never
null
).
-
getValue
Returns the value (possiblynull
) for a given key. If the key is not recognised, the method returnsnull
.- Specified by:
getValue
in interfaceKeyedValues
- Parameters:
key
- the key.- Returns:
- the value.
-
addValue
Adds a new value to the collection, or updates an existing value.This is the same as the setValue(...) method.
- Parameters:
key
- the key.value
- the value.
-
setValue
Updates an existing value, or adds a new value to the collection.This is the same as the addValue(...) method.
- Parameters:
key
- the key.value
- the value.
-
removeValue
public void removeValue(int index)Removes a value from the collection.- Parameters:
index
- the index of the item to remove.
-
removeValue
Removes a value from the collection. If there is no value with the specified key, then this method does nothing.- Parameters:
key
- the key of the item to remove.
-
sortByKeys
public void sortByKeys(org.jfree.util.SortOrder order)Sorts the items in the list by key.- Parameters:
order
- the sort order (ascending or descending).
-
sortByValues
public void sortByValues(org.jfree.util.SortOrder order)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 (ascending or descending).
-
equals
Tests if this object is equal to another. -
hashCode
public int hashCode()Returns a hash code. -
clone
Returns a clone.- Returns:
- A clone.
- Throws:
CloneNotSupportedException
- this class will not throw this exception, but subclasses might.
-