Package org.jfree.data
Class KeyedObjects
- java.lang.Object
-
- org.jfree.data.KeyedObjects
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable,PublicCloneable
public class KeyedObjects extends java.lang.Object implements java.lang.Cloneable, PublicCloneable, java.io.Serializable
A collection of (key, object) pairs.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.ListdataStorage for the data.private static longserialVersionUIDFor serialization.
-
Constructor Summary
Constructors Constructor Description KeyedObjects()Creates a new collection (initially empty).
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddObject(java.lang.Comparable key, java.lang.Object object)Adds a new object to the collection, or overwrites an existing object.voidclear()Clears all values from the collection.java.lang.Objectclone()Returns a clone of this object.booleanequals(java.lang.Object obj)Tests this object for equality with an arbitrary object.intgetIndex(java.lang.Comparable key)Returns the index for a given key, or-1.intgetItemCount()Returns the number of items (values) in the collection.java.lang.ComparablegetKey(int index)Returns the key at the specified position in the list.java.util.ListgetKeys()Returns a list containing all the keys in the list.java.lang.ObjectgetObject(int item)Returns an object from the list.java.lang.ObjectgetObject(java.lang.Comparable key)Returns the object for a given key.inthashCode()Returns a hash code.voidinsertValue(int position, java.lang.Comparable key, java.lang.Object 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.voidremoveValue(int index)Removes a value from the collection.voidremoveValue(java.lang.Comparable key)Removes a value from the collection.voidsetObject(java.lang.Comparable key, java.lang.Object object)Replaces an existing object, or adds a new object to the collection.
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
For serialization.- See Also:
- Constant Field Values
-
data
private java.util.List data
Storage for the data.
-
-
Method Detail
-
getItemCount
public int getItemCount()
Returns the number of items (values) in the collection.- Returns:
- The item count.
-
getObject
public java.lang.Object getObject(int item)
Returns an object from the list.- Parameters:
item- the item index (zero-based).- Returns:
- The object (possibly
null). - Throws:
java.lang.IndexOutOfBoundsException- ifitemis out of bounds.
-
getKey
public java.lang.Comparable getKey(int index)
Returns the key at the specified position in the list.- Parameters:
index- the item index (zero-based).- Returns:
- The row key.
- Throws:
java.lang.IndexOutOfBoundsException- ifitemis out of bounds.- See Also:
getIndex(Comparable)
-
getIndex
public int getIndex(java.lang.Comparable key)
Returns the index for a given key, or-1.- Parameters:
key- the key (nullnot permitted).- Returns:
- The index, or
-1if the key is unrecognised. - See Also:
getKey(int)
-
getKeys
public java.util.List getKeys()
Returns a list containing all the keys in the list.- Returns:
- The keys (never
null).
-
getObject
public java.lang.Object getObject(java.lang.Comparable key)
Returns the object for a given key. If the key is not recognised, the method should returnnull.- Parameters:
key- the key.- Returns:
- The object (possibly
null). - See Also:
addObject(Comparable, Object)
-
addObject
public void addObject(java.lang.Comparable key, java.lang.Object object)Adds a new object to the collection, or overwrites an existing object. This is the same as thesetObject(Comparable, Object)method.- Parameters:
key- the key.object- the object.- See Also:
getObject(Comparable)
-
setObject
public void setObject(java.lang.Comparable key, java.lang.Object object)Replaces an existing object, or adds a new object to the collection. This is the same as theaddObject(Comparable, Object)method.- Parameters:
key- the key (nullnot permitted).object- the object.- See Also:
getObject(Comparable)
-
insertValue
public void insertValue(int position, java.lang.Comparable key, java.lang.Object 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 range0togetItemCount()).key- the key (nullnot permitted).value- the value (nullpermitted).
-
removeValue
public void removeValue(int index)
Removes a value from the collection.- Parameters:
index- the index of the item to remove.- See Also:
removeValue(Comparable)
-
removeValue
public void removeValue(java.lang.Comparable key)
Removes a value from the collection.- Parameters:
key- the key (nullnot permitted).- Throws:
UnknownKeyException- if the key is not recognised.- See Also:
removeValue(int)
-
clear
public void clear()
Clears all values from the collection.
-
clone
public java.lang.Object clone() throws java.lang.CloneNotSupportedExceptionReturns a clone of this object. Keys in the list should be immutable and are not cloned. Objects in the list are cloned only if they implementPublicCloneable.- Specified by:
clonein interfacePublicCloneable- Overrides:
clonein classjava.lang.Object- Returns:
- A clone.
- Throws:
java.lang.CloneNotSupportedException- if there is a problem cloning.
-
equals
public boolean equals(java.lang.Object obj)
Tests this object for equality with an arbitrary object.- Overrides:
equalsin classjava.lang.Object- Parameters:
obj- the object (nullpermitted).- Returns:
- A boolean.
-
hashCode
public int hashCode()
Returns a hash code.- Overrides:
hashCodein classjava.lang.Object- Returns:
- A hash code.
-
-