|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.util.AbstractMap<K,V> org.apache.commons.collections.map.AbstractHashedMap<K,V> org.apache.commons.collections.map.AbstractLinkedMap<K,V>
public class AbstractLinkedMap<K,V>
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 theLinkEntry
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.EntrySetIterator<K,V>
EntrySet iterator. |
protected static class |
AbstractLinkedMap.KeySetIterator<K,V>
KeySet iterator. |
protected static class |
AbstractLinkedMap.LinkEntry<K,V>
LinkEntry that stores the data. |
protected 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 |
AbstractLinkedMap.ValuesIterator<K,V>
Values iterator. |
Nested classes/interfaces inherited from class org.apache.commons.collections.map.AbstractHashedMap |
---|
AbstractHashedMap.EntrySet<K,V>, AbstractHashedMap.HashEntry<K,V>, AbstractHashedMap.HashIterator<K,V>, AbstractHashedMap.HashMapIterator<K,V>, AbstractHashedMap.KeySet<K,V>, AbstractHashedMap.Values<K,V> |
Nested classes/interfaces inherited from interface java.util.Map |
---|
Map.Entry<K,V> |
Field Summary | |
---|---|
protected AbstractLinkedMap.LinkEntry<K,V> |
header
Header in the linked list |
Fields inherited from class org.apache.commons.collections.map.AbstractHashedMap |
---|
data, DEFAULT_CAPACITY, DEFAULT_LOAD_FACTOR, DEFAULT_THRESHOLD, entrySet, GETKEY_INVALID, GETVALUE_INVALID, keySet, loadFactor, MAXIMUM_CAPACITY, modCount, NO_NEXT_ENTRY, NO_PREVIOUS_ENTRY, NULL, REMOVE_INVALID, SETVALUE_INVALID, size, threshold, values |
Constructor Summary | |
---|---|
protected |
AbstractLinkedMap()
Constructor only used in deserialization, do not use otherwise. |
protected |
AbstractLinkedMap(int initialCapacity)
Constructs a new, empty map with the specified initial capacity. |
protected |
AbstractLinkedMap(int initialCapacity,
float loadFactor)
Constructs a new, empty map with the specified initial capacity and load factor. |
protected |
AbstractLinkedMap(int initialCapacity,
float loadFactor,
int threshold)
Constructor which performs no validation on the passed in parameters. |
protected |
AbstractLinkedMap(Map<? extends K,? extends V> map)
Constructor copying elements from another map. |
Method Summary | |
---|---|
protected void |
addEntry(AbstractHashedMap.HashEntry<K,V> entry,
int hashIndex)
Adds an entry into this map, maintaining insertion order. |
void |
clear()
Clears the map, resetting the size to zero and nullifying references to avoid garbage collection issues. |
boolean |
containsValue(Object value)
Checks whether the map contains the specified value. |
protected AbstractHashedMap.HashEntry<K,V> |
createEntry(AbstractHashedMap.HashEntry<K,V> next,
int hashCode,
K key,
V value)
Creates an entry to store the data. |
protected Iterator<Map.Entry<K,V>> |
createEntrySetIterator()
Creates an entry set iterator. |
protected Iterator |
createKeySetIterator()
Creates a key set iterator. |
protected Iterator<V> |
createValuesIterator()
Creates a values iterator. |
protected AbstractLinkedMap.LinkEntry<K,V> |
entryAfter(AbstractLinkedMap.LinkEntry<K,V> entry)
Gets the after field from a LinkEntry . |
protected AbstractLinkedMap.LinkEntry<K,V> |
entryBefore(AbstractLinkedMap.LinkEntry<K,V> entry)
Gets the before field from a LinkEntry . |
K |
firstKey()
Gets the first key in the map, which is the most recently inserted. |
protected AbstractLinkedMap.LinkEntry<K,V> |
getEntry(int index)
Gets the key at the specified index. |
protected void |
init()
Initialise this subclass during construction. |
K |
lastKey()
Gets the last key in the map, which is the first inserted. |
MapIterator<K,V> |
mapIterator()
Gets an iterator over the map. |
K |
nextKey(K key)
Gets the next key in sequence. |
OrderedMapIterator<K,V> |
orderedMapIterator()
Gets a bidirectional iterator over the map. |
K |
previousKey(K key)
Gets the previous key in sequence. |
protected void |
removeEntry(AbstractHashedMap.HashEntry<K,V> entry,
int hashIndex,
AbstractHashedMap.HashEntry<K,V> previous)
Removes an entry from the map and the linked list. |
Methods inherited from class org.apache.commons.collections.map.AbstractHashedMap |
---|
addMapping, calculateNewCapacity, calculateThreshold, checkCapacity, clone, containsKey, destroyEntry, doReadObject, doWriteObject, ensureCapacity, entryHashCode, entryKey, entryNext, entrySet, entryValue, equals, get, getEntry, hash, hashCode, hashIndex, isEmpty, isEqualKey, isEqualValue, keySet, put, putAll, remove, removeMapping, reuseEntry, size, toString, updateEntry, values |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.Map |
---|
containsKey, entrySet, equals, get, hashCode, isEmpty, keySet, put, putAll, remove, size, values |
Field Detail |
---|
protected transient AbstractLinkedMap.LinkEntry<K,V> header
Constructor Detail |
---|
protected AbstractLinkedMap()
protected AbstractLinkedMap(int initialCapacity, float loadFactor, int threshold)
initialCapacity
- the initial capacity, must be a power of twoloadFactor
- the load factor, must be > 0.0f and generally < 1.0fthreshold
- the threshold, must be sensibleprotected AbstractLinkedMap(int initialCapacity)
initialCapacity
- the initial capacity
IllegalArgumentException
- if the initial capacity is less than oneprotected AbstractLinkedMap(int initialCapacity, float loadFactor)
initialCapacity
- the initial capacityloadFactor
- the load factor
IllegalArgumentException
- if the initial capacity is less than one
IllegalArgumentException
- if the load factor is less than zeroprotected AbstractLinkedMap(Map<? extends K,? extends V> map)
map
- the map to copy
NullPointerException
- if the map is nullMethod Detail |
---|
protected void init()
init
in class AbstractHashedMap<K,V>
public boolean containsValue(Object value)
containsValue
in interface Map<K,V>
containsValue
in class AbstractHashedMap<K,V>
value
- the value to search for
public void clear()
clear
in interface Map<K,V>
clear
in class AbstractHashedMap<K,V>
public K firstKey()
firstKey
in interface OrderedMap<K,V>
public K lastKey()
lastKey
in interface OrderedMap<K,V>
public K nextKey(K key)
nextKey
in interface OrderedMap<K,V>
key
- the key to get after
public K previousKey(K key)
previousKey
in interface OrderedMap<K,V>
key
- the key to get before
protected AbstractLinkedMap.LinkEntry<K,V> getEntry(int index)
index
- the index to retrieve
IndexOutOfBoundsException
- if the index is invalidprotected void addEntry(AbstractHashedMap.HashEntry<K,V> entry, int hashIndex)
addEntry
in class AbstractHashedMap<K,V>
entry
- the entry to addhashIndex
- the index into the data array to store atprotected AbstractHashedMap.HashEntry<K,V> createEntry(AbstractHashedMap.HashEntry<K,V> next, int hashCode, K key, V value)
createEntry
in class AbstractHashedMap<K,V>
next
- the next entry in sequencehashCode
- the hash code to usekey
- the key to storevalue
- the value to store
protected void removeEntry(AbstractHashedMap.HashEntry<K,V> entry, int hashIndex, AbstractHashedMap.HashEntry<K,V> previous)
removeEntry
in class AbstractHashedMap<K,V>
entry
- the entry to removehashIndex
- the index into the data structureprevious
- the previous entry in the chainprotected AbstractLinkedMap.LinkEntry<K,V> entryBefore(AbstractLinkedMap.LinkEntry<K,V> entry)
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 entry
NullPointerException
- if the entry is nullprotected AbstractLinkedMap.LinkEntry<K,V> entryAfter(AbstractLinkedMap.LinkEntry<K,V> entry)
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 entry
NullPointerException
- if the entry is nullpublic MapIterator<K,V> mapIterator()
mapIterator
in interface IterableMap<K,V>
mapIterator
in class AbstractHashedMap<K,V>
public OrderedMapIterator<K,V> orderedMapIterator()
orderedMapIterator
in interface OrderedMap<K,V>
protected Iterator<Map.Entry<K,V>> createEntrySetIterator()
createEntrySetIterator
in class AbstractHashedMap<K,V>
protected Iterator createKeySetIterator()
createKeySetIterator
in class AbstractHashedMap<K,V>
protected Iterator<V> createValuesIterator()
createValuesIterator
in class AbstractHashedMap<K,V>
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |