org.pentaho.reporting.libraries.base.util

Class LinkedMap

public class LinkedMap extends Object implements Cloneable, Serializable

A fast linked-hashmap that avoids any unneccessay work. It is slightly slower than an ordinary hashmap but faster than a combined hashmap and list-index that would be needed to get this functionality on JDK 1.2. The map is as fast as the LinkedHashMap of JDK 1.4+.

Author: Thomas Morgner

UNKNOWN: ProtectedField

Nested Class Summary
protected static classLinkedMap.MapEntry
A cache map entry class holding both the key and value and acting as member of a linked list.
Constructor Summary
LinkedMap()
Default constructor.
LinkedMap(int initialCapacity, float loadFactor)
Creates a new map with the given initial number of buckets and the given loadfactor.
Method Summary
voidclear()
Clears the map and removes all map records.
Objectclone()
Clones this map.
booleancontainsKey(Object key)
Checks, whether the map contains an entry for the key.
Objectget(Object key)
Retrieves the object stored under the given key from the map.
booleanisEmpty()
Checks whether this collection is empty.
Object[]keys(Object[] data)
Returns the keys used in this map as array.
Object[]keys()
Returns the keys used in this map as array.
Objectput(Object key, Object value)
Stores the given value in the map using the provided key.
Objectremove(Object key)
Removes the object stored under the given key from the map.
intsize()
Returns the number of entries in the map.
Object[]values()
Returns the values used in this map as array.
Object[]values(Object[] data)
Returns the values used in this map as array.

Constructor Detail

LinkedMap

public LinkedMap()
Default constructor. Creates a map for 16 entries with a default load-factor of 0.75.

LinkedMap

public LinkedMap(int initialCapacity, float loadFactor)
Creates a new map with the given initial number of buckets and the given loadfactor. A load factor greater 1 will always cause hash-collisions, while lower loadfactors reduce the likelyhood of collisions.

Parameters: initialCapacity the initial capacity. loadFactor the load factor of the bucket-array.

Method Detail

clear

public void clear()
Clears the map and removes all map records.

clone

public Object clone()
Clones this map.

Returns: the cloned map.

Throws: CloneNotSupportedException

containsKey

public boolean containsKey(Object key)
Checks, whether the map contains an entry for the key.

Parameters: key the key for which a value should be located.

Returns: true if the map contains a value for the key, false otherwise.

get

public Object get(Object key)
Retrieves the object stored under the given key from the map.

Parameters: key the key for which a value should be located.

Returns: the value or null, if the map did not contain a value for the key.

isEmpty

public boolean isEmpty()
Checks whether this collection is empty.

Returns: true, if the collection is empty, false otherwise.

keys

public Object[] keys(Object[] data)
Returns the keys used in this map as array. The keys are returned in the insertation order.

Parameters: data the object array that should receive the keys.

Returns: the array filled with the keys.

keys

public Object[] keys()
Returns the keys used in this map as array. The keys are returned in the insertation order.

Returns: the array filled with the keys.

put

public Object put(Object key, Object value)
Stores the given value in the map using the provided key. Both key and value can be null.

Parameters: key the key. value the value to be stored under the key.

Returns: the previous value stored under this key or null of the entry is new.

remove

public Object remove(Object key)
Removes the object stored under the given key from the map.

Parameters: key the key for which a value should be located.

Returns: the value or null, if the map did not contain a value for the key.

size

public int size()
Returns the number of entries in the map.

Returns: the number of entries.

values

public Object[] values()
Returns the values used in this map as array. The values are returned in the insertation order.

Returns: the array filled with the values.

values

public Object[] values(Object[] data)
Returns the values used in this map as array. The values are returned in the insertation order.

Parameters: data the object array that should receive the values.

Returns: the array filled with the values.