Save This Page
Home » commons-collections-3.2.1-src » org.apache.commons » collections » map » [javadoc | source]
org.apache.commons.collections.map
public class: LinkedMap [javadoc | source]
java.lang.Object
   java.util.AbstractMap
      org.apache.commons.collections.map.AbstractHashedMap
         org.apache.commons.collections.map.AbstractLinkedMap
            org.apache.commons.collections.map.LinkedMap

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

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.

Note that LinkedMap is not synchronized and is not thread-safe. If you wish to use this map from multiple threads concurrently, you must use appropriate synchronization. The simplest approach is to wrap this map using java.util.Collections#synchronizedMap(Map) . This class may throw exceptions when accessed by concurrent threads without synchronization.

Nested Class Summary:
static class  LinkedMap.LinkedMapList  List view of map. 
Fields inherited from org.apache.commons.collections.map.AbstractLinkedMap:
header
Fields inherited from org.apache.commons.collections.map.AbstractHashedMap:
NO_NEXT_ENTRY,  NO_PREVIOUS_ENTRY,  REMOVE_INVALID,  GETKEY_INVALID,  GETVALUE_INVALID,  SETVALUE_INVALID,  DEFAULT_CAPACITY,  DEFAULT_THRESHOLD,  DEFAULT_LOAD_FACTOR,  MAXIMUM_CAPACITY,  NULL,  loadFactor,  size,  data,  threshold,  modCount,  entrySet,  keySet,  values
Constructor:
 public LinkedMap() 
 public LinkedMap(int initialCapacity) 
 public LinkedMap(Map map) 
    Constructor copying elements from another map.
    Parameters:
    map - the map to copy
    Throws:
    NullPointerException - if the map is null
 public LinkedMap(int initialCapacity,
    float loadFactor) 
Method from org.apache.commons.collections.map.LinkedMap Summary:
asList,   clone,   get,   getValue,   indexOf,   remove
Methods from 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 from 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
Methods from java.util.AbstractMap:
clear,   containsKey,   containsValue,   entrySet,   equals,   get,   hashCode,   isEmpty,   keySet,   put,   putAll,   remove,   size,   toString,   values
Methods from java.lang.Object:
equals,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.apache.commons.collections.map.LinkedMap Detail:
 public List asList() 
    Gets an unmodifiable List view of the keys.

    The returned list is unmodifiable because changes to the values of the list (using java.util.ListIterator#set(Object) ) will effectively remove the value from the list and reinsert that value at the end of the list, which is an unexpected side effect of changing the value of a list. This occurs because changing the key, changes when the mapping is added to the map and thus where it appears in the list.

    An alternative to this method is to use #keySet() .

 public Object clone() 
    Clones the map without cloning the keys or values.
 public Object get(int index) 
    Gets the key at the specified index.
 public Object getValue(int index) 
    Gets the value at the specified index.
 public int indexOf(Object key) 
    Gets the index of the specified key.
 public Object remove(int index) 
    Removes the element at the specified index.