java.lang.Object
org.jfree.data.KeyedObjects
- All Implemented Interfaces:
Serializable
,Cloneable
,PublicCloneable
A collection of (key, object) pairs.
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addObject
(Comparable key, Object object) Adds a new object to the collection, or overwrites an existing object.void
clear()
Clears all values from the collection.clone()
Returns a clone of this object.boolean
Tests this object for equality with an arbitrary object.int
getIndex
(Comparable key) Returns the index for a given key, or-1
.int
Returns the number of items (values) in the collection.getKey
(int index) Returns the key at the specified position in the list.getKeys()
Returns a list containing all the keys in the list.getObject
(int item) Returns an object from the list.getObject
(Comparable key) Returns the object for a given key.int
hashCode()
Returns a hash code.void
insertValue
(int position, Comparable key, 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.void
removeValue
(int index) Removes a value from the collection.void
removeValue
(Comparable key) Removes a value from the collection.void
setObject
(Comparable key, Object object) Replaces an existing object, or adds a new object to the collection.
-
Constructor Details
-
KeyedObjects
public KeyedObjects()Creates a new collection (initially empty).
-
-
Method Details
-
getItemCount
public int getItemCount()Returns the number of items (values) in the collection.- Returns:
- The item count.
-
getObject
Returns an object from the list.- Parameters:
item
- the item index (zero-based).- Returns:
- The object (possibly
null
). - Throws:
IndexOutOfBoundsException
- ifitem
is out of bounds.
-
getKey
Returns the key at the specified position in the list.- Parameters:
index
- the item index (zero-based).- Returns:
- The row key.
- Throws:
IndexOutOfBoundsException
- ifitem
is out of bounds.- See Also:
-
getIndex
Returns the index for a given key, or-1
.- Parameters:
key
- the key (null
not permitted).- Returns:
- The index, or
-1
if the key is unrecognised. - See Also:
-
getKeys
Returns a list containing all the keys in the list.- Returns:
- The keys (never
null
).
-
getObject
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
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:
-
setObject
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 (null
not permitted).object
- the object.- See Also:
-
insertValue
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 range0
togetItemCount()
).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.- See Also:
-
removeValue
Removes a value from the collection.- Parameters:
key
- the key (null
not permitted).- Throws:
UnknownKeyException
- if the key is not recognised.- See Also:
-
clear
public void clear()Clears all values from the collection. -
clone
Returns 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:
clone
in interfacePublicCloneable
- Overrides:
clone
in classObject
- Returns:
- A clone.
- Throws:
CloneNotSupportedException
- if there is a problem cloning.
-
equals
Tests this object for equality with an arbitrary object. -
hashCode
public int hashCode()Returns a hash code.
-