K - the key type (must implement Comparable).T - the value type.public final class DefaultKeyedValues<K extends java.lang.Comparable<K>,T> extends java.lang.Object implements KeyedValues<K,T>, java.io.Serializable
(key, value) pairs.
| Constructor and Description |
|---|
DefaultKeyedValues()
Creates a new (empty) list of keyed values.
|
DefaultKeyedValues(java.util.List<K> keys)
Creates a new instance with the specified keys (each associated with
a
null value). |
| 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(K 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.
|
K |
getKey(int index)
Returns the key for the item with the specified index.
|
java.util.List<K> |
getKeys()
Returns a list of all the keys.
|
T |
getValue(int item)
Returns the value for the specified item.
|
T |
getValue(K key)
Returns the value with the specified key.
|
void |
put(K key,
T value)
Adds a value or, if there is an existing value with the same key, updates
an existing value.
|
void |
remove(int index)
Removes the item with the specified index.
|
void |
remove(K key)
Removes the item with the specified key, if there is one.
|
public DefaultKeyedValues()
public DefaultKeyedValues(java.util.List<K> keys)
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.keys - the keys (null not permitted).public void clear()
public void put(K key, T value)
key - the key (null not permitted)value - the value.public void remove(K key)
key - the key (null not permitted).public void remove(int index)
index - the index.public K getKey(int index)
getKey in interface KeyedValues<K extends java.lang.Comparable<K>,T>index - the item index.public int getIndex(K key)
-1
if there is no such item.getIndex in interface KeyedValues<K extends java.lang.Comparable<K>,T>key - the key (null not permitted).-1.public java.util.List<K> getKeys()
getKeys in interface KeyedValues<K extends java.lang.Comparable<K>,T>null).public T getValue(K key)
getValue in interface KeyedValues<K extends java.lang.Comparable<K>,T>key - the key (null not permitted).null).public int getItemCount()
getItemCount in interface Values<T>public double getDoubleValue(int item)
Number.getDoubleValue in interface Values<T>item - the item index.public boolean equals(java.lang.Object obj)
equals in class java.lang.Objectobj - the object to test against (null permitted).