java.lang.Object | |||
↳ | java.util.AbstractMap<K, V> | ||
↳ | org.apache.commons.collections.map.AbstractHashedMap | ||
↳ | org.apache.commons.collections.map.AbstractLinkedMap |
Known Direct Subclasses |
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 Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
AbstractLinkedMap.EntrySetIterator | EntrySet iterator. | ||||||||||
AbstractLinkedMap.KeySetIterator | KeySet iterator. | ||||||||||
AbstractLinkedMap.LinkEntry | LinkEntry that stores the data. | ||||||||||
AbstractLinkedMap.LinkIterator | Base Iterator that iterates in link order. | ||||||||||
AbstractLinkedMap.LinkMapIterator | MapIterator implementation. | ||||||||||
AbstractLinkedMap.ValuesIterator | Values iterator. |
[Expand]
Inherited Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
org.apache.commons.collections.map.AbstractHashedMap
|
Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
header | Header in the linked list |
[Expand]
Inherited Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
org.apache.commons.collections.map.AbstractHashedMap
|
Protected Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Constructor only used in deserialization, do not use otherwise.
| |||||||||||
Constructor which performs no validation on the passed in parameters.
| |||||||||||
Constructs a new, empty map with the specified initial capacity.
| |||||||||||
Constructs a new, empty map with the specified initial capacity and
load factor.
| |||||||||||
Constructor copying elements from another map.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Clears the map, resetting the size to zero and nullifying references
to avoid garbage collection issues.
| |||||||||||
Checks whether the map contains the specified value.
| |||||||||||
Gets the first key in the map, which is the most recently inserted.
| |||||||||||
Gets the last key in the map, which is the first inserted.
| |||||||||||
Gets an iterator over the map.
| |||||||||||
Gets the next key in sequence.
| |||||||||||
Gets a bidirectional iterator over the map.
| |||||||||||
Gets the previous key in sequence.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Adds an entry into this map, maintaining insertion order.
| |||||||||||
Creates an entry to store the data.
| |||||||||||
Creates an entry set iterator.
| |||||||||||
Creates a key set iterator.
| |||||||||||
Creates a values iterator.
| |||||||||||
Gets the
after field from a LinkEntry . | |||||||||||
Gets the
before field from a LinkEntry . | |||||||||||
Gets the key at the specified index.
| |||||||||||
Initialise this subclass during construction.
| |||||||||||
Removes an entry from the map and the linked list.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
org.apache.commons.collections.map.AbstractHashedMap
| |||||||||||
From class
java.util.AbstractMap
| |||||||||||
From class
java.lang.Object
| |||||||||||
From interface
java.util.Map
| |||||||||||
From interface
org.apache.commons.collections.IterableMap
| |||||||||||
From interface
org.apache.commons.collections.OrderedMap
|
Constructor only used in deserialization, do not use otherwise.
Constructor which performs no validation on the passed in parameters.
initialCapacity | the initial capacity, must be a power of two |
---|---|
loadFactor | the load factor, must be > 0.0f and generally < 1.0f |
threshold | the threshold, must be sensible |
Constructs a new, empty map with the specified initial capacity.
initialCapacity | the initial capacity |
---|
IllegalArgumentException | if the initial capacity is less than one |
---|
Constructs a new, empty map with the specified initial capacity and load factor.
initialCapacity | the initial capacity |
---|---|
loadFactor | the load factor |
IllegalArgumentException | if the initial capacity is less than one |
---|---|
IllegalArgumentException | if the load factor is less than zero |
Constructor copying elements from another map.
map | the map to copy |
---|
NullPointerException | if the map is null |
---|
Clears the map, resetting the size to zero and nullifying references to avoid garbage collection issues.
Checks whether the map contains the specified value.
value | the value to search for |
---|
Gets the first key in the map, which is the most recently inserted.
Gets the last key in the map, which is the first inserted.
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.
Gets the next key in sequence.
key | the key to get after |
---|
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.
Gets the previous key in sequence.
key | the key to get before |
---|
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.
entry | the entry to add |
---|---|
hashIndex | the index into the data array to store at |
Creates an entry to store the data.
This implementation creates a new LinkEntry instance.
next | the next entry in sequence |
---|---|
hashCode | the hash code to use |
key | the key to store |
value | the value to store |
Creates an entry set iterator. Subclasses can override this to return iterators with different properties.
Creates a key set iterator. Subclasses can override this to return iterators with different properties.
Creates a values iterator. Subclasses can override this to return iterators with different properties.
Gets the after
field from a LinkEntry
.
Used in subclasses that have no visibility of the field.
entry | the entry to query, must not be null |
---|
after
field of the entryNullPointerException | if the entry is null |
---|
Gets the before
field from a LinkEntry
.
Used in subclasses that have no visibility of the field.
entry | the entry to query, must not be null |
---|
before
field of the entryNullPointerException | if the entry is null |
---|
Gets the key at the specified index.
index | the index to retrieve |
---|
IndexOutOfBoundsException | if the index is invalid |
---|
Initialise this subclass during construction.
NOTE: As from v3.2 this method calls
createEntry(HashEntry, int, Object, Object)
to create
the map entry object.
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.
entry | the entry to remove |
---|---|
hashIndex | the index into the data structure |
previous | the previous entry in the chain |