org.jfree.data

Class KeyedObjects

public class KeyedObjects extends Object implements Cloneable, PublicCloneable, Serializable

A collection of (key, object) pairs.
Constructor Summary
KeyedObjects()
Creates a new collection (initially empty).
Method Summary
voidaddObject(Comparable key, Object object)
Adds a new object to the collection, or overwrites an existing object.
voidclear()
Clears all values from the collection.
Objectclone()
Returns a clone of this object.
booleanequals(Object obj)
Tests this object for equality with an arbitrary object.
intgetIndex(Comparable key)
Returns the index for a given key, or -1.
intgetItemCount()
Returns the number of items (values) in the collection.
ComparablegetKey(int index)
Returns the key at the specified position in the list.
ListgetKeys()
Returns a list containing all the keys in the list.
ObjectgetObject(int item)
Returns an object from the list.
ObjectgetObject(Comparable key)
Returns the object for a given key.
inthashCode()
Returns a hash code.
voidinsertValue(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.
voidremoveValue(int index)
Removes a value from the collection.
voidremoveValue(Comparable key)
Removes a value from the collection.
voidsetObject(Comparable key, Object object)
Replaces an existing object, or adds a new object to the collection.

Constructor Detail

KeyedObjects

public KeyedObjects()
Creates a new collection (initially empty).

Method Detail

addObject

public void addObject(Comparable key, Object object)
Adds a new object to the collection, or overwrites an existing object. This is the same as the KeyedObjects method.

Parameters: key the key. object the object.

See Also: getObject

clear

public void clear()
Clears all values from the collection.

Since: 1.0.7

clone

public Object 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 implement PublicCloneable.

Returns: A clone.

Throws: CloneNotSupportedException if there is a problem cloning.

equals

public boolean equals(Object obj)
Tests this object for equality with an arbitrary object.

Parameters: obj the object (null permitted).

Returns: A boolean.

getIndex

public int getIndex(Comparable key)
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: KeyedObjects

getItemCount

public int getItemCount()
Returns the number of items (values) in the collection.

Returns: The item count.

getKey

public 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: IndexOutOfBoundsException if item is out of bounds.

See Also: getIndex

getKeys

public List getKeys()
Returns a list containing all the keys in the list.

Returns: The keys (never null).

getObject

public Object getObject(int item)
Returns an object from the list.

Parameters: item the item index (zero-based).

Returns: The object (possibly null).

Throws: IndexOutOfBoundsException if item is out of bounds.

getObject

public Object getObject(Comparable key)
Returns the object for a given key. If the key is not recognised, the method should return null.

Parameters: key the key.

Returns: The object (possibly null).

See Also: KeyedObjects

hashCode

public int hashCode()
Returns a hash code.

Returns: A hash code.

insertValue

public 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.

Parameters: position the position (in the range 0 to getItemCount()). key the key (null not permitted). value the value (null permitted).

Since: 1.0.7

removeValue

public void removeValue(int index)
Removes a value from the collection.

Parameters: index the index of the item to remove.

See Also: removeValue

removeValue

public void removeValue(Comparable key)
Removes a value from the collection.

Parameters: key the key (null not permitted).

Throws: UnknownKeyException if the key is not recognised.

See Also:

setObject

public void setObject(Comparable key, Object object)
Replaces an existing object, or adds a new object to the collection. This is the same as the KeyedObjects method.

Parameters: key the key (null not permitted). object the object.

See Also: getObject

Copyright © 2000-2009 by Object Refinery Limited. All Rights Reserved.