Package org.jfree.data
Class DefaultKeyedValues
- java.lang.Object
-
- org.jfree.data.DefaultKeyedValues
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable,KeyedValues,Values,org.jfree.util.PublicCloneable
public class DefaultKeyedValues extends java.lang.Object implements KeyedValues, java.lang.Cloneable, org.jfree.util.PublicCloneable, java.io.Serializable
An ordered list of (key, value) items. This class provides a default implementation of theKeyedValuesinterface.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description DefaultKeyedValues()Creates a new collection (initially empty).
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddValue(java.lang.Comparable key, double value)Updates an existing value, or adds a new value to the collection.voidaddValue(java.lang.Comparable key, java.lang.Number value)Adds a new value to the collection, or updates an existing value.voidclear()Clears all values from the collection.java.lang.Objectclone()Returns a clone.booleanequals(java.lang.Object obj)Tests if this object is equal to another.intgetIndex(java.lang.Comparable key)Returns the index for a given key.intgetItemCount()Returns the number of items (values) in the collection.java.lang.ComparablegetKey(int index)Returns a key.java.util.ListgetKeys()Returns the keys for the values in the collection.java.lang.NumbergetValue(int item)Returns a value.java.lang.NumbergetValue(java.lang.Comparable key)Returns the value for a given key.inthashCode()Returns a hash code.voidinsertValue(int position, java.lang.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, java.lang.Comparable key, java.lang.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(java.lang.Comparable key)Removes a value from the collection.voidsetValue(java.lang.Comparable key, double value)Updates an existing value, or adds a new value to the collection.voidsetValue(java.lang.Comparable key, java.lang.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 Detail
-
DefaultKeyedValues
public DefaultKeyedValues()
Creates a new collection (initially empty).
-
-
Method Detail
-
getItemCount
public int getItemCount()
Returns the number of items (values) in the collection.- Specified by:
getItemCountin interfaceValues- Returns:
- The item count.
-
getValue
public java.lang.Number getValue(int item)
Returns a value.
-
getKey
public java.lang.Comparable getKey(int index)
Returns a key.- Specified by:
getKeyin interfaceKeyedValues- Parameters:
index- the item index (zero-based).- Returns:
- The row key.
- Throws:
java.lang.IndexOutOfBoundsException- ifitemis out of bounds.
-
getIndex
public int getIndex(java.lang.Comparable key)
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:
java.lang.IllegalArgumentException- ifkeyisnull.
-
getKeys
public java.util.List getKeys()
Returns the keys for the values in the collection.- Specified by:
getKeysin interfaceKeyedValues- Returns:
- The keys (never
null).
-
getValue
public java.lang.Number getValue(java.lang.Comparable key)
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:
getValue(int)
-
addValue
public void addValue(java.lang.Comparable key, double value)
Updates an existing value, or adds a new value to the collection.- Parameters:
key- the key (nullnot permitted).value- the value.- See Also:
addValue(Comparable, Number)
-
addValue
public void addValue(java.lang.Comparable key, java.lang.Number value)
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
public void setValue(java.lang.Comparable key, double value)
Updates an existing value, or adds a new value to the collection.- Parameters:
key- the key (nullnot permitted).value- the value.
-
setValue
public void setValue(java.lang.Comparable key, java.lang.Number value)
Updates an existing value, or adds a new value to the collection.- Parameters:
key- the key (nullnot permitted).value- the value (nullpermitted).
-
insertValue
public void insertValue(int position, java.lang.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.- Parameters:
position- the position (in the range 0 to getItemCount()).key- the key (nullnot permitted).value- the value.- Since:
- 1.0.6
-
insertValue
public void insertValue(int position, java.lang.Comparable key, java.lang.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.- Parameters:
position- the position (in the range 0 to getItemCount()).key- the key (nullnot permitted).value- the value (nullpermitted).- Since:
- 1.0.6
-
removeValue
public void removeValue(int index)
Removes a value from the collection.- Parameters:
index- the index of the item to remove (in the range0togetItemCount() - 1).- Throws:
java.lang.IndexOutOfBoundsException- ifindexis not within the specified range.
-
removeValue
public void removeValue(java.lang.Comparable key)
Removes a value from the collection.- Parameters:
key- the item key (nullnot permitted).- Throws:
java.lang.IllegalArgumentException- ifkeyisnull.UnknownKeyException- ifkeyis not recognised.
-
clear
public void clear()
Clears all values from the collection.- Since:
- 1.0.2
-
sortByKeys
public void sortByKeys(org.jfree.util.SortOrder order)
Sorts the items in the list by key.- Parameters:
order- the sort order (nullnot permitted).
-
sortByValues
public void sortByValues(org.jfree.util.SortOrder order)
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
public boolean equals(java.lang.Object obj)
Tests if this object is equal to another.- Overrides:
equalsin classjava.lang.Object- Parameters:
obj- the object (nullpermitted).- Returns:
- A boolean.
-
hashCode
public int hashCode()
Returns a hash code.- Overrides:
hashCodein classjava.lang.Object- Returns:
- A hash code.
-
clone
public java.lang.Object clone() throws java.lang.CloneNotSupportedException
Returns a clone.- Specified by:
clonein interfaceorg.jfree.util.PublicCloneable- Overrides:
clonein classjava.lang.Object- Returns:
- A clone.
- Throws:
java.lang.CloneNotSupportedException- this class will not throw this exception, but subclasses might.
-
-