Module platform

Class DefaultKeyedValues<K extends Comparable<K>>

java.lang.Object
org.jfree.data.DefaultKeyedValues<K>
Type Parameters:
K - the key type (String is a good default).
All Implemented Interfaces:
Serializable, Cloneable, PublicCloneable, KeyedValues<K>, Values

public class DefaultKeyedValues<K extends Comparable<K>> extends Object implements KeyedValues<K>, Cloneable, PublicCloneable, Serializable
An ordered list of (key, value) items. This class provides a default implementation of the KeyedValues interface.
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new collection (initially empty).
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addValue(K key, double value)
    Updates an existing value, or adds a new value to the collection.
    void
    addValue(K key, Number value)
    Adds a new value to the collection, or updates an existing value.
    void
    Clears all values from the collection.
    Returns a clone.
    boolean
    Tests if this object is equal to another.
    int
    getIndex(K key)
    Returns the index for a given key.
    int
    Returns the number of items (values) in the collection.
    getKey(int index)
    Returns a key.
    Returns the keys for the values in the collection.
    getValue(int item)
    Returns a value.
    getValue(K key)
    Returns the value for a given key.
    int
    Returns a hash code.
    void
    insertValue(int position, K 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.
    void
    insertValue(int position, K key, 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.
    void
    removeValue(int index)
    Removes a value from the collection.
    void
    Removes a value from the collection.
    void
    setValue(K key, double value)
    Updates an existing value, or adds a new value to the collection.
    void
    setValue(K key, Number value)
    Updates an existing value, or adds a new value to the collection.
    void
    Sorts the items in the list by key.
    void
    Sorts the items in the list by value.

    Methods inherited from class java.lang.Object

    finalize, getClass, notify, notifyAll, toString, wait, wait, wait
  • 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 interface Values
      Returns:
      The item count.
    • 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 (possibly null).
      Throws:
      IndexOutOfBoundsException - if item is out of bounds.
    • getKey

      public K getKey(int index)
      Returns a key.
      Specified by:
      getKey in interface KeyedValues<K extends Comparable<K>>
      Parameters:
      index - the item index (zero-based).
      Returns:
      The row key.
      Throws:
      IndexOutOfBoundsException - if item is out of bounds.
    • getIndex

      public int getIndex(K key)
      Returns the index for a given key.
      Specified by:
      getIndex in interface KeyedValues<K extends Comparable<K>>
      Parameters:
      key - the key (null not permitted).
      Returns:
      The index, or -1 if the key is not recognised.
      Throws:
      IllegalArgumentException - if key is null.
    • getKeys

      public List<K> getKeys()
      Returns the keys for the values in the collection.
      Specified by:
      getKeys in interface KeyedValues<K extends Comparable<K>>
      Returns:
      The keys (never null).
    • getValue

      public Number getValue(K key)
      Returns the value for a given key.
      Specified by:
      getValue in interface KeyedValues<K extends Comparable<K>>
      Parameters:
      key - the key (null not permitted).
      Returns:
      The value (possibly null).
      Throws:
      UnknownKeyException - if the key is not recognised.
      See Also:
    • addValue

      public void addValue(K 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.
      See Also:
    • addValue

      public void addValue(K 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).
    • setValue

      public void setValue(K 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(K 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).
    • insertValue

      public void insertValue(int position, K 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 (null not permitted).
      value - the value.
    • insertValue

      public void insertValue(int position, K key, 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 (null not permitted).
      value - the value (null 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).
      Throws:
      IndexOutOfBoundsException - if index is not within the specified range.
    • removeValue

      public void removeValue(K key)
      Removes a value from the collection.
      Parameters:
      key - the item key (null not permitted).
      Throws:
      IllegalArgumentException - if key is null.
      UnknownKeyException - if key is not recognised.
    • clear

      public void clear()
      Clears all values from the collection.
    • 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).
    • equals

      public boolean equals(Object obj)
      Tests if this object is equal to another.
      Overrides:
      equals in class Object
      Parameters:
      obj - the object (null permitted).
      Returns:
      A boolean.
    • hashCode

      public int hashCode()
      Returns a hash code.
      Overrides:
      hashCode in class Object
      Returns:
      A hash code.
    • clone

      public Object clone() throws CloneNotSupportedException
      Returns a clone.
      Specified by:
      clone in interface PublicCloneable
      Overrides:
      clone in class Object
      Returns:
      A clone.
      Throws:
      CloneNotSupportedException - this class will not throw this exception, but subclasses might.