public class DefaultKeyedValues extends java.lang.Object implements KeyedValues, java.lang.Cloneable, org.jfree.util.PublicCloneable, java.io.Serializable
KeyedValues interface.| Modifier and Type | Field and Description |
|---|---|
private java.util.HashMap |
indexMap
Contains (key, Integer) mappings, where the Integer is the index for
the key in the list.
|
private java.util.ArrayList |
keys
Storage for the keys.
|
private static long |
serialVersionUID
For serialization.
|
private java.util.ArrayList |
values
Storage for the values.
|
| Constructor and Description |
|---|
DefaultKeyedValues()
Creates a new collection (initially empty).
|
| Modifier and Type | Method and Description |
|---|---|
void |
addValue(java.lang.Comparable key,
double value)
Updates an existing value, or adds a new value to the collection.
|
void |
addValue(java.lang.Comparable key,
java.lang.Number value)
Adds a new value to the collection, or updates an existing value.
|
void |
clear()
Clears all values from the collection.
|
java.lang.Object |
clone()
Returns a clone.
|
boolean |
equals(java.lang.Object obj)
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 for the values in the collection.
|
java.lang.Number |
getValue(java.lang.Comparable key)
Returns the value for a given key.
|
java.lang.Number |
getValue(int item)
Returns a value.
|
int |
hashCode()
Returns a hash code.
|
void |
insertValue(int position,
java.lang.Comparable 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,
java.lang.Comparable key,
java.lang.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.
|
private void |
rebuildIndex()
Rebuilds the key to indexed-position mapping after an positioned insert
or a remove operation.
|
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,
double value)
Updates an existing value, or adds a new value to 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(org.jfree.util.SortOrder order)
Sorts the items in the list by key.
|
void |
sortByValues(org.jfree.util.SortOrder order)
Sorts the items in the list by value.
|
private static final long serialVersionUID
private java.util.ArrayList keys
private java.util.ArrayList values
private java.util.HashMap indexMap
public DefaultKeyedValues()
public int getItemCount()
getItemCount in interface Valuespublic java.lang.Number getValue(int item)
public java.lang.Comparable getKey(int index)
getKey in interface KeyedValuesindex - the item index (zero-based).java.lang.IndexOutOfBoundsException - if item is out of bounds.public int getIndex(java.lang.Comparable key)
getIndex in interface KeyedValueskey - the key (null not permitted).-1 if the key is not recognised.java.lang.IllegalArgumentException - if key is
null.public java.util.List getKeys()
getKeys in interface KeyedValuesnull).public java.lang.Number getValue(java.lang.Comparable key)
getValue in interface KeyedValueskey - the key (null not permitted).null).UnknownKeyException - if the key is not recognised.getValue(int)public void addValue(java.lang.Comparable key,
double value)
key - the key (null not permitted).value - the value.addValue(Comparable, Number)public void addValue(java.lang.Comparable key,
java.lang.Number value)
setValue(Comparable, Number) method.key - the key (null not permitted).value - the value (null permitted).public void setValue(java.lang.Comparable key,
double value)
key - the key (null not permitted).value - the value.public void setValue(java.lang.Comparable key,
java.lang.Number value)
key - the key (null not permitted).value - the value (null permitted).public void insertValue(int position,
java.lang.Comparable key,
double value)
position - the position (in the range 0 to getItemCount()).key - the key (null not permitted).value - the value.public void insertValue(int position,
java.lang.Comparable key,
java.lang.Number value)
position - the position (in the range 0 to getItemCount()).key - the key (null not permitted).value - the value (null permitted).private void rebuildIndex()
public void removeValue(int index)
index - the index of the item to remove (in the range
0 to getItemCount() - 1).java.lang.IndexOutOfBoundsException - if index is not within
the specified range.public void removeValue(java.lang.Comparable key)
key - the item key (null not permitted).java.lang.IllegalArgumentException - if key is
null.UnknownKeyException - if key is not recognised.public void clear()
public void sortByKeys(org.jfree.util.SortOrder order)
order - the sort order (null not permitted).public void sortByValues(org.jfree.util.SortOrder order)
null values, they will sort to the end of the list,
irrespective of the sort order.order - the sort order (null not permitted).public boolean equals(java.lang.Object obj)
equals in class java.lang.Objectobj - the object (null permitted).public int hashCode()
hashCode in class java.lang.Objectpublic java.lang.Object clone()
throws java.lang.CloneNotSupportedException
clone in interface org.jfree.util.PublicCloneableclone in class java.lang.Objectjava.lang.CloneNotSupportedException - this class will not throw this
exception, but subclasses might.