⇒ Index (Frames) |  ⇒ Index (No Frames) |  ⇒ Package |  ⇒ Package Tree |  ⇒ Full Tree 
org.apache.commons.collections.map

Class LinkedMap

java.lang.Object
|
+--org.apache.commons.collections.map.AbstractHashedMap
   |
   +--org.apache.commons.collections.map.AbstractLinkedMap
      |
      +--org.apache.commons.collections.map.LinkedMap

All Implemented Interfaces:
Cloneable, IterableMap, OrderedMap, Serializable


public class LinkedMap
extends AbstractLinkedMap
implements Serializable, Cloneable

A Map implementation that maintains the order of the entries. In this implementation order is maintained by original insertion.

This implementation improves on the JDK1.4 LinkedHashMap by adding the org.apache.commons.collections.MapIterator MapIterator functionality, additional convenience methods and allowing bidirectional iteration. It also implements OrderedMap. In addition, non-interface methods are provided to access the map by index.

The orderedMapIterator() method provides direct access to a bidirectional iterator. The iterators from the other views can also be cast to OrderedIterator if required.

All the available iterators can be reset back to the start by casting to ResettableIterator and calling reset().

The implementation is also designed to be subclassed, with lots of useful methods exposed.

Since:
Commons Collections 3.0
Author:
Stephen Colebourne

Constructor Summary

LinkedMap()

Constructs a new empty map with default size and load factor.

LinkedMap(int initialCapacity)

Constructs a new, empty map with the specified initial capacity.

LinkedMap(int initialCapacity, float loadFactor)

Constructs a new, empty map with the specified initial capacity and load factor.

LinkedMap(Map map)

Constructor copying elements from another map.

Method Summary

List

asList()

Gets an unmodifiable List view of the keys.

Object

clone()

Clones the map without cloning the keys or values.

Object

get(int index)

Gets the key at the specified index.

Object

getValue(int index)

Gets the value at the specified index.

int

indexOf(Object key)

Gets the index of the specified key.

Object

remove(int index)

Removes the element at the specified index.

Constructor Details

LinkedMap

public LinkedMap()

Constructs a new empty map with default size and load factor.


LinkedMap

public LinkedMap(int initialCapacity, float loadFactor)

Constructs a new, empty map with the specified initial capacity and load factor.

Parameters:
initialCapacity - the initial capacity
loadFactor - the load factor
Throws:
- if the initial capacity is less than one
- if the load factor is less than zero

LinkedMap

public LinkedMap(int initialCapacity)

Constructs a new, empty map with the specified initial capacity.

Parameters:
initialCapacity - the initial capacity
Throws:
- if the initial capacity is less than one

LinkedMap

public LinkedMap(Map map)

Constructor copying elements from another map.

Parameters:
map - the map to copy
Throws:
- if the map is null

Method Details

asList

public List asList()

Returns:
The ordered list of keys.
See Also:
keySet()

clone

public Object clone()

Clones the map without cloning the keys or values.

Returns:
a shallow clone

get

public Object get(int index)

Gets the key at the specified index.

Parameters:
index - the index to retrieve
Returns:
the key at the specified index
Throws:
- if the index is invalid

getValue

public Object getValue(int index)

Gets the value at the specified index.

Parameters:
index - the index to retrieve
Returns:
the key at the specified index
Throws:
- if the index is invalid

indexOf

public int indexOf(Object key)

Gets the index of the specified key.

Parameters:
key - the key to find the index of
Returns:
the index, or -1 if not found

remove

public Object remove(int index)

Removes the element at the specified index.

Parameters:
index - the index of the object to remove
Returns:
the previous value corresponding the key, or null if none existed
Throws:
- if the index is invalid