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

All Implemented Interfaces:
    OrderedMap, IterableMap, Map

Direct Known Subclasses:
    LRUMap, MockLRUMapSubclass, MockLRUMapSubclassFirstBlocksRemove, MockLRUMapSubclassBlocksRemove, LinkedMap

An abstract implementation of a hash-based map that links entries to create an ordered map and which provides numerous points for subclasses to override.

This class implements all the features necessary for a subclass linked hash-based map. Key-value entries are stored in instances of the LinkEntry class which can be overridden and replaced. The iterators can similarly be replaced, without the need to replace the KeySet, EntrySet and Values view classes.

Overridable methods are provided to change the default hashing behaviour, and to change how entries are added to and removed from the map. Hopefully, all you need for unusual subclasses is here.

This implementation maintains order by original insertion, but subclasses may work differently. The OrderedMap interface is implemented to provide access to bidirectional iteration and extra convenience methods.

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.

Nested Class Summary:
protected static class  AbstractLinkedMap.LinkMapIterator  MapIterator implementation. 
protected static class  AbstractLinkedMap.EntrySetIterator  EntrySet iterator. 
protected static class  AbstractLinkedMap.KeySetIterator  KeySet iterator. 
protected static class  AbstractLinkedMap.ValuesIterator  Values iterator. 
protected static class  AbstractLinkedMap.LinkEntry  LinkEntry that stores the data.

If you subclass AbstractLinkedMap but not LinkEntry then you will not be able to access the protected fields. The entryXxx() methods on AbstractLinkedMap exist to provide the necessary access. 

abstract protected static class  AbstractLinkedMap.LinkIterator  Base Iterator that iterates in link order. 
Field Summary
protected transient  AbstractLinkedMap.LinkEntry header    Header in the linked list 
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:
 protected AbstractLinkedMap() 
 protected AbstractLinkedMap(int initialCapacity) 
 protected AbstractLinkedMap(Map map) 
    Constructor copying elements from another map.
    Parameters:
    map - the map to copy
    Throws:
    NullPointerException - if the map is null
 protected AbstractLinkedMap(int initialCapacity,
    float loadFactor) 
 protected AbstractLinkedMap(int initialCapacity,
    float loadFactor,
    int threshold) 
Method from org.apache.commons.collections.map.AbstractLinkedMap Summary:
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.AbstractLinkedMap Detail:
 protected  void addEntry(HashEntry entry,
    int hashIndex) 
    Adds an entry into this map, maintaining insertion order.

    This implementation adds the entry to the data storage table and to the end of the linked list.

 public  void clear() 
    Clears the map, resetting the size to zero and nullifying references to avoid garbage collection issues.
 public boolean containsValue(Object value) 
    Checks whether the map contains the specified value.
 protected HashEntry createEntry(HashEntry next,
    int hashCode,
    Object key,
    Object value) 
    Creates an entry to store the data.

    This implementation creates a new LinkEntry instance.

 protected Iterator createEntrySetIterator() 
    Creates an entry set iterator. Subclasses can override this to return iterators with different properties.
 protected Iterator createKeySetIterator() 
    Creates a key set iterator. Subclasses can override this to return iterators with different properties.
 protected Iterator createValuesIterator() 
    Creates a values iterator. Subclasses can override this to return iterators with different properties.
 protected AbstractLinkedMap.LinkEntry entryAfter(AbstractLinkedMap.LinkEntry entry) 
    Gets the after field from a LinkEntry. Used in subclasses that have no visibility of the field.
 protected AbstractLinkedMap.LinkEntry entryBefore(AbstractLinkedMap.LinkEntry entry) 
    Gets the before field from a LinkEntry. Used in subclasses that have no visibility of the field.
 public Object firstKey() 
    Gets the first key in the map, which is the most recently inserted.
 protected AbstractLinkedMap.LinkEntry getEntry(int index) 
    Gets the key at the specified index.
 protected  void init() 
 public Object lastKey() 
    Gets the last key in the map, which is the first inserted.
 public MapIterator mapIterator() 
    Gets an iterator over the map. Changes made to the iterator affect this map.

    A MapIterator returns the keys in the map. It also provides convenient methods to get the key and value, and set the value. It avoids the need to create an entrySet/keySet/values object.

 public Object nextKey(Object key) 
    Gets the next key in sequence.
 public OrderedMapIterator orderedMapIterator() 
    Gets a bidirectional iterator over the map. Changes made to the iterator affect this map.

    A MapIterator returns the keys in the map. It also provides convenient methods to get the key and value, and set the value. It avoids the need to create an entrySet/keySet/values object.

 public Object previousKey(Object key) 
    Gets the previous key in sequence.
 protected  void removeEntry(HashEntry entry,
    int hashIndex,
    HashEntry previous) 
    Removes an entry from the map and the linked list.

    This implementation removes the entry from the linked list chain, then calls the superclass implementation.