org.jfree.data
Class DefaultKeyedValues

java.lang.Object
  |
  +--org.jfree.data.DefaultKeyedValues
All Implemented Interfaces:
KeyedValues, java.io.Serializable, Values

public class DefaultKeyedValues
extends java.lang.Object
implements KeyedValues, java.io.Serializable

A collection of (key, value) pairs.

This class provides a default implementation of the KeyedValues interface.

Author:
David Gilbert
See Also:
Serialized Form

Constructor Summary
DefaultKeyedValues()
          Creates a new collection (initially empty).
 
Method Summary
 void addValue(java.lang.Comparable key, java.lang.Number value)
          Adds a new value to the collection, or updates an existing value.
 boolean equals(java.lang.Object o)
          Tests if this object is equal to another.
 int getIndex(java.lang.Comparable key)
          Returns the index for a given key.
 int getItemCount()
          Returns the number of items (values) in the collection.
 java.lang.Comparable getKey(int index)
          Returns a key.
 java.util.List getKeys()
          Returns the keys.
 java.lang.Number getValue(java.lang.Comparable key)
          Returns the value (possibly null) for a given key.
 java.lang.Number getValue(int item)
          Returns a value.
 void removeValue(java.lang.Comparable key)
          Removes a value from the collection.
 void removeValue(int index)
          Removes a value from the collection.
 void setValue(java.lang.Comparable key, java.lang.Number 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.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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:
getItemCount in interface Values
Returns:
the item count.

getValue

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

getKey

public java.lang.Comparable getKey(int index)
Returns a key.

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

getIndex

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

Specified by:
getIndex in interface KeyedValues
Parameters:
key - the key.
Returns:
the index.

getKeys

public java.util.List getKeys()
Returns the keys.

Specified by:
getKeys in interface KeyedValues
Returns:
the keys.

getValue

public java.lang.Number getValue(java.lang.Comparable key)
Returns the value (possibly null) for a given key.

If the key is not recognised, the method should return null.

Specified by:
getValue in interface KeyedValues
Parameters:
key - the key.
Returns:
the value.

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 is the same as the setValue(...) method.

Parameters:
key - the key.
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.

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

public void removeValue(java.lang.Comparable key)
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(SortOrder order)
Sorts the items in the list by key.

Parameters:
order - the sort order (ascending or descending).

sortByValues

public void sortByValues(SortOrder order)
Sorts the items in the list by value.

Parameters:
order - the sort order (ascending or descending).

equals

public boolean equals(java.lang.Object o)
Tests if this object is equal to another.

Overrides:
equals in class java.lang.Object
Parameters:
o - the other object.
Returns:
A boolean.