Top Description Inners Fields Constructors Methods
org.apache.commons.collections4.map

public abstract Class AbstractLinkedMap<K, V>

extends AbstractHashedMap<K, V>
implements OrderedMap<K, V>
Class Inheritance
All Implemented Interfaces
org.apache.commons.collections4.OrderedMap, org.apache.commons.collections4.IterableMap, org.apache.commons.collections4.IterableGet, org.apache.commons.collections4.Get, org.apache.commons.collections4.Put, java.util.Map
Known Direct Subclasses
org.apache.commons.collections4.map.LinkedMap, org.apache.commons.collections4.map.LRUMap
Type Parameters
<K>
the type of the keys in this map
<V>
the type of the values in this map
Imports
java.util.ConcurrentModificationException, .Iterator, .Map, .NoSuchElementException, org.apache.commons.collections4.OrderedIterator, .OrderedMap, .OrderedMapIterator, .ResettableIterator, org.apache.commons.collections4.iterators.EmptyOrderedIterator, .EmptyOrderedMapIterator

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.

Since
3.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected static class
AbstractLinkedMap.EntrySetIterator<K, V>

EntrySet iterator.

protected static class
protected static class
AbstractLinkedMap.LinkEntry<K, V>

LinkEntry that stores the data.

protected abstract static class
AbstractLinkedMap.LinkIterator<K, V>

Base Iterator that iterates in link order.

protected static class
AbstractLinkedMap.LinkMapIterator<K, V>

MapIterator implementation.

protected static class

Field Summary

Modifier and TypeField and Description
pack-priv transient AbstractLinkedMap.LinkEntry<K, V>
header

Header in the linked list

Inherited from org.apache.commons.collections4.map.AbstractHashedMap:
dataDEFAULT_CAPACITYDEFAULT_LOAD_FACTORDEFAULT_THRESHOLDentrySetGETKEY_INVALIDGETVALUE_INVALIDkeySetloadFactorMAXIMUM_CAPACITYmodCountNO_NEXT_ENTRYNO_PREVIOUS_ENTRYNULLREMOVE_INVALIDSETVALUE_INVALIDsizethresholdvalues

Constructor Summary

AccessConstructor and Description
protected
AbstractLinkedMap()

Constructor only used in deserialization, do not use otherwise.

protected
AbstractLinkedMap(final int
the initial capacity, must be a power of two
initialCapacity
,
final float
the load factor, must be > 0.0f and generally < 1.0f
loadFactor
,
final int
the threshold, must be sensible
threshold
)

Constructor which performs no validation on the passed in parameters.

protected
AbstractLinkedMap(final int
the initial capacity
initialCapacity
)

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

protected
AbstractLinkedMap(final int
the initial capacity
initialCapacity
,
final float
the load factor
loadFactor
)

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

protected
AbstractLinkedMap(final Map<? extends K, ? extends V>
the map to copy
map
)

Constructor copying elements from another map.

Method Summary

Modifier and TypeMethod and Description
protected void
addEntry(final AbstractHashedMap.HashEntry<K, V>
the entry to add
entry
,
final int
the index into the data array to store at
hashIndex
)

Overrides org.apache.commons.collections4.map.AbstractHashedMap.addEntry.

Adds an entry into this map, maintaining insertion order.
public void
clear()

Overrides org.apache.commons.collections4.map.AbstractHashedMap.clear.

Implements java.util.Map.clear, org.apache.commons.collections4.Put.clear.

Clears the map, resetting the size to zero and nullifying references to avoid garbage collection issues.
public boolean

Returns:

true if the map contains the value
containsValue
(final Object
the value to search for
value
)

Overrides org.apache.commons.collections4.map.AbstractHashedMap.containsValue.

Implements java.util.Map.containsValue, org.apache.commons.collections4.Get.containsValue.

Checks whether the map contains the specified value.
protected AbstractLinkedMap.LinkEntry<K, V>

Returns:

the newly created entry
createEntry
(final AbstractHashedMap.HashEntry<K, V>
the next entry in sequence
next
,
final int
the hash code to use
hashCode
,
final K
the key to store
key
,
final V
the value to store
value
)

Overrides org.apache.commons.collections4.map.AbstractHashedMap.createEntry.

Creates an entry to store the data.
protected Iterator<Map.Entry<K, V>>

Returns:

the entrySet iterator
createEntrySetIterator
()

Overrides org.apache.commons.collections4.map.AbstractHashedMap.createEntrySetIterator.

Creates an entry set iterator.
protected Iterator<K>

Returns:

the keySet iterator
createKeySetIterator
()

Overrides org.apache.commons.collections4.map.AbstractHashedMap.createKeySetIterator.

Creates a key set iterator.
protected Iterator<V>

Returns:

the values iterator
createValuesIterator
()

Overrides org.apache.commons.collections4.map.AbstractHashedMap.createValuesIterator.

Creates a values iterator.
protected AbstractLinkedMap.LinkEntry<K, V>

Returns:

the after field of the entry
entryAfter
(final AbstractLinkedMap.LinkEntry<K, V>
the entry to query, must not be null
entry
)

Gets the after field from a LinkEntry.

protected AbstractLinkedMap.LinkEntry<K, V>

Returns:

the before field of the entry
entryBefore
(final AbstractLinkedMap.LinkEntry<K, V>
the entry to query, must not be null
entry
)

Gets the before field from a LinkEntry.

public K

Returns:

the eldest key
firstKey
()

Implements org.apache.commons.collections4.OrderedMap.firstKey.

Gets the first key in the map, which is the first inserted.
protected AbstractLinkedMap.LinkEntry<K, V>
getEntry(final Object
the key
key
)

Overrides org.apache.commons.collections4.map.AbstractHashedMap.getEntry.

Gets the entry mapped to the key specified.
protected AbstractLinkedMap.LinkEntry<K, V>

Returns:

the key at the specified index
getEntry
(final int
the index to retrieve
index
)

Gets the key at the specified index.

protected void
init()

Overrides org.apache.commons.collections4.map.AbstractHashedMap.init.

Initialise this subclass during construction.
public K

Returns:

the most recently inserted key
lastKey
()

Implements org.apache.commons.collections4.OrderedMap.lastKey.

Gets the last key in the map, which is the most recently inserted.
public OrderedMapIterator<K, V>
public K

Returns:

the next key
nextKey
(final Object
the key to get after
key
)

Implements org.apache.commons.collections4.OrderedMap.nextKey.

Gets the next key in sequence.
public K

Returns:

the previous key
previousKey
(final Object
the key to get before
key
)

Implements org.apache.commons.collections4.OrderedMap.previousKey.

Gets the previous key in sequence.
protected void
removeEntry(final AbstractHashedMap.HashEntry<K, V>
the entry to remove
entry
,
final int
the index into the data structure
hashIndex
,
final AbstractHashedMap.HashEntry<K, V>
the previous entry in the chain
previous
)

Overrides org.apache.commons.collections4.map.AbstractHashedMap.removeEntry.

Removes an entry from the map and the linked list.
Inherited from org.apache.commons.collections4.map.AbstractHashedMap:
addMappingcalculateNewCapacitycalculateThresholdcheckCapacityclonecontainsKeyconvertKeydestroyEntrydoReadObjectdoWriteObjectensureCapacityentryHashCodeentryKeyentryNextentrySetentryValueequalsgethashhashCodehashIndexisEmptyisEqualKeyisEqualValuekeySetputputAllremoveremoveMappingreuseEntrysizetoStringupdateEntryvalues