org.jfree.data

Class DefaultKeyedValues

public class DefaultKeyedValues extends Object implements KeyedValues, Cloneable, PublicCloneable, Serializable

An ordered list of (key, value) items. This class provides a default implementation of the KeyedValues interface.
Constructor Summary
DefaultKeyedValues()
Creates a new collection (initially empty).
Method Summary
voidaddValue(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.
Objectclone()
Returns a clone.
booleanequals(Object obj)
Tests if this object is equal to another.
intgetIndex(Comparable key)
Returns the index for a given key.
intgetItemCount()
Returns the number of items (values) in the collection.
ComparablegetKey(int index)
Returns a key.
ListgetKeys()
Returns the keys for the values in the collection.
NumbergetValue(int item)
Returns a value.
NumbergetValue(Comparable key)
Returns the value for a given key.
inthashCode()
Returns a hash code.
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(SortOrder order)
Sorts the items in the list by key.
voidsortByValues(SortOrder order)
Sorts the items in the list by value.

Constructor Detail

DefaultKeyedValues

public DefaultKeyedValues()
Creates a new collection (initially empty).

Method Detail

addValue

public void addValue(Comparable key, double value)
Updates an existing value, or adds a new value to the collection.

Parameters: key the key (null not permitted). value the value.

addValue

public void addValue(Comparable key, Number value)
Adds a new value to the collection, or updates an existing value. This method passes control directly to the DefaultKeyedValues method.

Parameters: key the key (null not permitted). value the value (null permitted).

clear

public void clear()
Clears all values from the collection.

Since: 1.0.2

clone

public Object clone()
Returns a clone.

Returns: A clone.

Throws: CloneNotSupportedException this class will not throw this exception, but subclasses might.

equals

public boolean equals(Object obj)
Tests if this object is equal to another.

Parameters: obj the object (null permitted).

Returns: A boolean.

getIndex

public int getIndex(Comparable key)
Returns the index for a given key.

Parameters: key the key (null not permitted).

Returns: The index, or -1 if the key is not recognised.

Throws: IllegalArgumentException if key is null.

getItemCount

public int getItemCount()
Returns the number of items (values) in the collection.

Returns: The item count.

getKey

public Comparable getKey(int index)
Returns a key.

Parameters: index the item index (zero-based).

Returns: The row key.

Throws: IndexOutOfBoundsException if item is out of bounds.

getKeys

public List getKeys()
Returns the keys for the values in the collection.

Returns: The keys (never null).

getValue

public Number getValue(int item)
Returns a value.

Parameters: item the item of interest (zero-based index).

Returns: The value.

Throws: IndexOutOfBoundsException if item is out of bounds.

getValue

public Number getValue(Comparable key)
Returns the value for a given key.

Parameters: key the key.

Returns: The value (possibly null).

Throws: UnknownKeyException if the key is not recognised.

hashCode

public int hashCode()
Returns a hash code.

Returns: A hash code.

removeValue

public void removeValue(int index)
Removes a value from the collection.

Parameters: index the index of the item to remove (in the range 0 to getItemCount() - 1).

Throws: IndexOutOfBoundsException if index is not within the specified range.

removeValue

public void removeValue(Comparable key)
Removes a value from the collection. If there is no item with the specified key, this method does nothing.

Parameters: key the item key (null not permitted).

Throws: IllegalArgumentException if key is null.

setValue

public void setValue(Comparable key, double value)
Updates an existing value, or adds a new value to the collection.

Parameters: key the key (null not permitted). value the value.

setValue

public void setValue(Comparable key, Number value)
Updates an existing value, or adds a new value to the collection.

Parameters: key the key (null not permitted). value the value (null permitted).

sortByKeys

public void sortByKeys(SortOrder order)
Sorts the items in the list by key.

Parameters: order the sort order (null not permitted).

sortByValues

public void sortByValues(SortOrder order)
Sorts the items in the list by value. If the list contains null values, they will sort to the end of the list, irrespective of the sort order.

Parameters: order the sort order (null not permitted).