com.orsoncharts.data

## Class DefaultKeyedValues<T>

- java.lang.Object
- - com.orsoncharts.data.DefaultKeyedValues<T>

- All Implemented Interfaces:
    KeyedValues<T>, Values<T>, java.io.Serializable

      public final class DefaultKeyedValues<T>
      extends java.lang.Object
      implements KeyedValues<T>, java.io.Serializable

  A list of `(key, value)` pairs.
  This is the basic structure of the data required for a pie chart.
  NOTE: This class is serializable, but the serialization format is subject to change in future releases and should not be relied upon for persisting instances of this class.
  See Also:
    Serialized Form

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `DefaultKeyedValues()` Creates a new (empty) list of keyed values.
    `DefaultKeyedValues(java.util.List<java.lang.Comparable<?>> keys)` Creates a new instance with the specified keys (each associated with a `null` value).

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `clear()` Clears all the data.
    `boolean` | `equals(java.lang.Object obj)` Tests this instance for equality with an arbitrary object.
    `double` | `getDoubleValue(int item)` Returns the value for the specified item, as a double primitive, provided that the data value is an instance of `Number`.
    `int` | `getIndex(java.lang.Comparable<?> key)` Returns the index of the item with the specified key, or `-1` if there is no such item.
    `int` | `getItemCount()` Returns the number of items in the list.
    `java.lang.Comparable<?>` | `getKey(int index)` Returns the key for the item with the specified index.
    `java.util.List<java.lang.Comparable<?>>` | `getKeys()` Returns a list of all the keys.
    `T` | `getValue(java.lang.Comparable<?> key)` Returns the value with the specified key.
    `T` | `getValue(int item)` Returns the value for the specified item.
    `void` | `put(java.lang.Comparable<?> key, T value)` Adds a value or, if there is an existing value with the same key, updates an existing value.
    `void` | `remove(java.lang.Comparable<?> key)` Removes the item with the specified key, if there is one.
    `void` | `remove(int index)` Removes the item with the specified index.

    - ### 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 (empty) list of keyed values.

    - #### DefaultKeyedValues

          public DefaultKeyedValues(java.util.List<java.lang.Comparable<?>> keys)

      Creates a new instance with the specified keys (each associated with a `null` value). There is usually no need to specify any keys in advance, so you will normally use the default constructor. This constructor is provided for the convenience of some internal code.
      Parameters:
        `keys` - the keys (`null` not permitted).

  - ### Method Detail

    - #### clear

          public void clear()

      Clears all the data.

    - #### put

          public void put(java.lang.Comparable<?> key,
                          T value)

      Adds a value or, if there is an existing value with the same key, updates an existing value.
      Parameters:
        `key` - the key (`null` not permitted)
        `value` - the value.

    - #### remove

          public void remove(java.lang.Comparable<?> key)

      Removes the item with the specified key, if there is one.
      Parameters:
        `key` - the key (`null` not permitted).

    - #### remove

          public void remove(int index)

      Removes the item with the specified index.
      Parameters:
        `index` - the index.

    - #### getKey

          public java.lang.Comparable<?> getKey(int index)

      Returns the key for the item with the specified index.
      Specified by:
        `getKey` in interface `KeyedValues<T>`
      Parameters:
        `index` - the item index.
      Returns:
        The key.

    - #### getIndex

          public int getIndex(java.lang.Comparable<?> key)

      Returns the index of the item with the specified key, or `-1` if there is no such item.
      Specified by:
        `getIndex` in interface `KeyedValues<T>`
      Parameters:
        `key` - the key (`null` not permitted).
      Returns:
        The item index, or `-1`.

    - #### getKeys

          public java.util.List<java.lang.Comparable<?>> getKeys()

      Returns a list of all the keys. Note that the list will be a copy, so modifying it will not impact this data structure.
      Specified by:
        `getKeys` in interface `KeyedValues<T>`
      Returns:
        A list of keys (possibly empty, but never `null`).

    - #### getValue

          public T getValue(java.lang.Comparable<?> key)

      Returns the value with the specified key.
      Specified by:
        `getValue` in interface `KeyedValues<T>`
      Parameters:
        `key` - the key (`null` not permitted).
      Returns:
        The value (possibly `null`).

    - #### getItemCount

          public int getItemCount()

      Returns the number of items in the list.
      Specified by:
        `getItemCount` in interface `Values<T>`
      Returns:
        The number of items in the list.

    - #### getValue

          public T getValue(int item)

      Returns the value for the specified item.
      Specified by:
        `getValue` in interface `Values<T>`
      Parameters:
        `item` - the item index.
      Returns:
        The value (possibly `null`).

    - #### getDoubleValue

          public double getDoubleValue(int item)

      Returns the value for the specified item, as a double primitive, provided that the data value is an instance of `Number`.
      Specified by:
        `getDoubleValue` in interface `Values<T>`
      Parameters:
        `item` - the item index.
      Returns:
        The value.

    - #### equals

          public boolean equals(java.lang.Object obj)

      Tests this instance for equality with an arbitrary object.
      Overrides:
        `equals` in class `java.lang.Object`
      Parameters:
        `obj` - the object to test against (`null` permitted).
      Returns:
        A boolean.