org.apache.commons.collections.map

Class LinkedMap

Implemented Interfaces:
Cloneable, Map, Serializable, IterableMap, OrderedMap

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

Version:
$Revision: 1.9 $ $Date: 2004/02/18 01:13:19 $
Author:
Stephen Colebourne
Since:
Commons Collections 3.0

Nested Class Summary

Nested classes/interfaces inherited from class org.apache.commons.collections.map.AbstractLinkedMap

AbstractLinkedMap.EntrySetIterator, AbstractLinkedMap.KeySetIterator, AbstractLinkedMap.LinkEntry, AbstractLinkedMap.LinkIterator, AbstractLinkedMap.LinkMapIterator, AbstractLinkedMap.ValuesIterator

Nested classes/interfaces inherited from class org.apache.commons.collections.map.AbstractHashedMap

AbstractHashedMap.EntrySet, AbstractHashedMap.EntrySetIterator, AbstractHashedMap.HashEntry, AbstractHashedMap.HashIterator, AbstractHashedMap.HashMapIterator, AbstractHashedMap.KeySet, AbstractHashedMap.KeySetIterator, AbstractHashedMap.Values, AbstractHashedMap.ValuesIterator

Field Summary

Fields inherited from class org.apache.commons.collections.map.AbstractLinkedMap

header

Fields inherited from class org.apache.commons.collections.map.AbstractHashedMap

DEFAULT_CAPACITY, DEFAULT_LOAD_FACTOR, DEFAULT_THRESHOLD, GETKEY_INVALID, GETVALUE_INVALID, MAXIMUM_CAPACITY, NO_NEXT_ENTRY, NO_PREVIOUS_ENTRY, NULL, REMOVE_INVALID, SETVALUE_INVALID, data, entrySet, keySet, loadFactor, modCount, size, threshold, values

Constructor Summary

LinkedMap()
Constructs a new empty map with default size and load factor.
LinkedMap(Map map)
Constructor copying elements from another map.
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.

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.

Methods inherited from class org.apache.commons.collections.map.AbstractLinkedMap

addEntry, clear, containsValue, createEntry, createEntrySetIterator, createKeySetIterator, createValuesIterator, entryAfter, entryBefore, firstKey, getEntry, init, lastKey, mapIterator, nextKey, orderedMapIterator, previousKey, removeEntry

Methods inherited from class org.apache.commons.collections.map.AbstractHashedMap

addEntry, addMapping, calculateNewCapacity, calculateThreshold, checkCapacity, clear, clone, containsKey, containsValue, convertKey, createEntry, createEntrySetIterator, createKeySetIterator, createValuesIterator, destroyEntry, doReadObject, doWriteObject, ensureCapacity, entryHashCode, entryKey, entryNext, entrySet, entryValue, equals, get, getEntry, hash, hashCode, hashIndex, init, isEmpty, isEqualKey, isEqualValue, keySet, mapIterator, put, putAll, remove, removeEntry, removeMapping, reuseEntry, size, toString, updateEntry, values

Constructor Details

LinkedMap

public LinkedMap()
Constructs a new empty map with default size and load factor.

LinkedMap

public LinkedMap(Map map)
Constructor copying elements from another map.
Parameters:
map - the map to copy

LinkedMap

public LinkedMap(int initialCapacity)
Constructs a new, empty map with the specified initial capacity.
Parameters:
initialCapacity - the initial capacity

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

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.
Overrides:
clone in interface AbstractHashedMap
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

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

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

Copyright © 2001-2006 Apache Software Foundation. All Rights Reserved.