public abstract static class Maps.AbstractLinkedHashMap<K,V,E extends Maps.LinkedEntry<K,V>> extends Maps.AbstractHashMap<K,V,E>
Map
interface that is functionally equivalent to LinkedHashMap
but is based on Maps.AbstractHashMap
and allows subclasses the same
customization options. Maps.AbstractLinkedHashMap
adds a predictable
iteration order to Maps.AbstractHashMap
by maintaining a doubly linked
list, defining the iteration order, of all the entries in the map. To
support this, the entries are required to implement the Maps.LinkedEntry
interface (which extends the Maps.BaseEntry
interface required by Maps.AbstractHashMap
).
The only method that a concrete subclass must override is
Maps.AbstractHashMap.createEntry(int, K, V, E)
.
DEFAULT_INITIAL_CAPACITY, DEFAULT_LOAD_FACTOR, MAXIMUM_CAPACITY
Modifier | Constructor and Description |
---|---|
protected |
Maps.AbstractLinkedHashMap(int initialCapacity,
float loadFactor,
boolean accessOrder,
java.util.Map<? extends K,? extends V> map)
Constructs a map.
|
protected |
Maps.AbstractLinkedHashMap(java.util.Map<? extends K,? extends V> map)
Constructs an insertion-ordered map with specified initial mappings,
initial capacity based on the number of initial mappings, and default
load factor.
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Removes all mappings from this map.
|
protected java.util.Iterator<E> |
createEntryIterator()
Gets an iterator through all the entries of the map.
|
protected java.util.Iterator<java.util.Map.Entry<K,V>> |
createEntrySetIterator()
Gets an iterator through all the entries of the map.
|
protected java.util.Iterator<K> |
createKeySetIterator()
Gets an iterator through all the keys of all the entries of the map.
|
protected java.util.Iterator<V> |
createValuesIterator()
Gets an iterator through all the values of all the entries of the map.
|
protected void |
entryEvicted(E entry)
Invoked when an existing entry is evicted by
evictEntry(E) ,
e.g., because removeEldestEntry(E) returned true. |
boolean |
evict(K key)
Evict the entry mapped to the given key, if it exists in the map.
|
protected boolean |
evictEntry(E entry)
Evicts an existing entry from this map.
|
protected E |
getEldestEntry()
Gets the eldest entry in this map, or null if the map is empty.
|
protected void |
mapChanged()
Invoked when the map has changed.
|
protected boolean |
removeEldestEntry(E eldest)
Gets whether to evict the eldest entry from this map.
|
protected void |
transfer(E[] newTable) |
addEntry, capacity, change, clone, containsKey, containsValue, createEntry, entryAccessed, entryAdded, entryChanged, entryPurged, entryRemoved, entrySet, equals, get, getChangeCount, getEntry, getQueue, hashCode, isEmpty, keyEquals, keyHashCode, keySet, loadFactor, mapConstructed, mapInitialized, purge, purgeEntry, put, putAll, remove, removeExistingEntry, removeKey, size, toString, valueEquals, valueHashCode, values
protected Maps.AbstractLinkedHashMap(int initialCapacity, float loadFactor, boolean accessOrder, java.util.Map<? extends K,? extends V> map)
initialCapacity
- the initial capacity.loadFactor
- The load factor.accessOrder
- The iteration order for this map: insertion-order
false, access-order if true.map
- A map providing initial mappings, or null if none.java.lang.IllegalArgumentException
- if the initial capacity is negative
or the load factor is nonpositive.protected Maps.AbstractLinkedHashMap(java.util.Map<? extends K,? extends V> map)
map
- A map providing initial mappings.java.lang.NullPointerException
- if the specified map is null.Maps.AbstractHashMap.DEFAULT_LOAD_FACTOR
protected void transfer(E[] newTable)
public boolean evict(K key)
key
- the key to evictprotected void mapChanged()
Maps.AbstractHashMap.mapInitialized()
), it only changes when the map is cleared or
when entries are added, removed, or purged. In the latter cases, this
method is invoked before the corresponding Maps.AbstractHashMap.entryAdded(E)
,
Maps.AbstractHashMap.entryRemoved(E)
or Maps.AbstractHashMap.entryPurged(E)
method.
The Maps.AbstractHashMap
implementation does nothing.
For subclasses of Maps.AbstractLinkedHashMap
, this method is also
invoked when iteration order is by access and an entry is
accessed. This method is invoked before the associated
Maps.AbstractHashMap.entryAccessed(E)
method is invoked.
Maps.AbstractLinkedHashMap
implementation does nothing.mapChanged
in class Maps.AbstractHashMap<K,V,E extends Maps.LinkedEntry<K,V>>
protected void entryEvicted(E entry)
evictEntry(E)
,
e.g., because removeEldestEntry(E)
returned true.
The Maps.AbstractLinkedHashMap
implementation does nothing.protected E getEldestEntry()
In an insertion-ordered map, the eldest entry is the least recently inserted one; in an access-ordered map, it is the least recently accessed entry.
TheMaps.AbstractLinkedHashMap
implementation does nothing.protected boolean removeEldestEntry(E eldest)
Maps.AbstractHashMap.entryAdded(E)
is invoked. If
Maps.AbstractHashMap.entryAdded(E)
modifies the map, however, this method is not
invoked. The removal of the entry, if requested, causes the entryEvicted(E)
method to be invoked, rather than the Maps.AbstractHashMap.entryRemoved(E)
method.
The Maps.AbstractLinkedHashMap
implementation returns false.
In an insertion-ordered map, the eldest entry is the least recently inserted one; in an access-ordered map, it is the least recently accessed entry.
This method is provided for compatibility with LinkedHashMap.removeEldestEntry(java.util.Map.Entry<K, V>)
.
eldest
- The eldest entry in the map.protected boolean evictEntry(E entry)
entry
- The entry to evict.public void clear()
clear
in interface java.util.Map<K,V>
clear
in class Maps.AbstractHashMap<K,V,E extends Maps.LinkedEntry<K,V>>
protected java.util.Iterator<E> createEntryIterator()
Maps.AbstractHashMap
Maps.AbstractHashMap
implementation returns an instance of
AbstractEntryIterator
. A subclass would typically override this
only if it had access to a more efficient iterator implementation.createEntryIterator
in class Maps.AbstractHashMap<K,V,E extends Maps.LinkedEntry<K,V>>
protected java.util.Iterator<java.util.Map.Entry<K,V>> createEntrySetIterator()
Maps.AbstractHashMap
Maps.AbstractHashMap
implementation returns an instance of
AbstractEntryIterator
. A subclass would typically override this
only if it had access to a more efficient iterator implementation.createEntrySetIterator
in class Maps.AbstractHashMap<K,V,E extends Maps.LinkedEntry<K,V>>
protected java.util.Iterator<K> createKeySetIterator()
Maps.AbstractHashMap
Maps.AbstractHashMap
implementation returns an instance of
AbstractEntryIterator
. A subclass would typically override this
only if it had access to a more efficient iterator implementation.createKeySetIterator
in class Maps.AbstractHashMap<K,V,E extends Maps.LinkedEntry<K,V>>
protected java.util.Iterator<V> createValuesIterator()
Maps.AbstractHashMap
Maps.AbstractHashMap
implementation returns an instance of
AbstractEntryIterator
. A subclass would typically override this
only if it had access to a more efficient iterator implementation.createValuesIterator
in class Maps.AbstractHashMap<K,V,E extends Maps.LinkedEntry<K,V>>