org.jfree.data

Class DefaultKeyedValues

Implemented Interfaces:
Cloneable, KeyedValues, PublicCloneable, Serializable, Values

public class DefaultKeyedValues
extends java.lang.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

void
addValue(Comparable key, Number value)
Adds a new value to the collection, or updates an existing value.
void
addValue(Comparable key, double value)
Updates an existing value, or adds a new value to the collection.
void
clear()
Clears all values from the collection.
Object
clone()
Returns a clone.
boolean
equals(Object obj)
Tests if this object is equal to another.
int
getIndex(Comparable key)
Returns the index for a given key.
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(Comparable key)
Returns the value for a given key.
Number
getValue(int item)
Returns a value.
int
hashCode()
Returns a hash code.
void
removeValue(Comparable key)
Removes a value from the collection.
void
removeValue(int index)
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
setValue(Comparable key, double value)
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

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 setValue(Comparable,Number) method.
Parameters:
key - the key (null not permitted).
value - the value (null permitted).

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.

clear

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

clone

public Object clone()
            throws CloneNotSupportedException
Returns a clone.
Returns:
A clone.

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.
Specified by:
getIndex in interface KeyedValues
Parameters:
key - the key (null not permitted).
Returns:
The index, or -1 if the key is not recognised.

getItemCount

public int getItemCount()
Returns the number of items (values) in the collection.
Specified by:
getItemCount in interface Values
Returns:
The item count.

getKey

public Comparable getKey(int index)
Returns a key.
Specified by:
getKey in interface KeyedValues
Parameters:
index - the item index (zero-based).
Returns:
The row key.

getKeys

public List getKeys()
Returns the keys for the values in the collection.
Specified by:
getKeys in interface KeyedValues
Returns:
The keys (never null).

getValue

public Number getValue(Comparable key)
Returns the value for a given key.
Specified by:
getValue in interface KeyedValues
Parameters:
key - the key.
Returns:
The value (possibly null).

getValue

public Number getValue(int item)
Returns a value.
Specified by:
getValue in interface Values
Parameters:
item - the item of interest (zero-based index).
Returns:
The value.

hashCode

public int hashCode()
Returns a hash code.
Returns:
A hash code.

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).

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).

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).

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.

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).