public class KeyComparatorLinkedHashMap<K,V> extends KeyComparatorHashMap<K,V> implements java.util.Map<K,V>
LinkedHashMap
but supports the
comparison of keys using a KeyComparator
.Constructor and Description |
---|
KeyComparatorLinkedHashMap(int initialCapacity,
float loadFactor,
boolean accessOrder,
KeyComparator<K> keyComparator)
Constructs an empty LinkedHashMap instance with the
specified initial capacity, load factor and ordering mode.
|
KeyComparatorLinkedHashMap(int initialCapacity,
float loadFactor,
KeyComparator<K> keyComparator)
Constructs an empty insertion-ordered LinkedHashMap instance
with the specified initial capacity and load factor.
|
KeyComparatorLinkedHashMap(int initialCapacity,
KeyComparator<K> keyComparator)
Constructs an empty insertion-ordered LinkedHashMap instance
with the specified initial capacity and a default load factor (0.75).
|
KeyComparatorLinkedHashMap(KeyComparator<K> keyComparator)
Constructs an empty insertion-ordered LinkedHashMap instance
with the default initial capacity (16) and load factor (0.75).
|
KeyComparatorLinkedHashMap(java.util.Map<? extends K,? extends V> m,
KeyComparator<K> keyComparator)
Constructs an insertion-ordered LinkedHashMap instance with
the same mappings as the specified map.
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Removes all of the mappings from this map.
|
boolean |
containsValue(java.lang.Object value)
Returns true if this map maps one or more keys to the
specified value.
|
V |
get(java.lang.Object key)
Returns the value to which the specified key is mapped,
or
null if this map contains no mapping for the key. |
protected boolean |
removeEldestEntry(java.util.Map.Entry<K,V> eldest)
Returns true if this map should remove its eldest entry.
|
clone, containsKey, entrySet, getDEFAULT_INITIAL_CAPACITY, getModCount, isEmpty, put, putAll, remove, size
public KeyComparatorLinkedHashMap(int initialCapacity, float loadFactor, KeyComparator<K> keyComparator)
initialCapacity
- the initial capacityloadFactor
- the load factorjava.lang.IllegalArgumentException
- if the initial capacity is negative
or the load factor is nonpositivepublic KeyComparatorLinkedHashMap(int initialCapacity, KeyComparator<K> keyComparator)
initialCapacity
- the initial capacityjava.lang.IllegalArgumentException
- if the initial capacity is negativepublic KeyComparatorLinkedHashMap(KeyComparator<K> keyComparator)
public KeyComparatorLinkedHashMap(java.util.Map<? extends K,? extends V> m, KeyComparator<K> keyComparator)
m
- the map whose mappings are to be placed in this mapjava.lang.NullPointerException
- if the specified map is nullpublic KeyComparatorLinkedHashMap(int initialCapacity, float loadFactor, boolean accessOrder, KeyComparator<K> keyComparator)
initialCapacity
- the initial capacityloadFactor
- the load factoraccessOrder
- the ordering mode - true for
access-order, false for insertion-orderjava.lang.IllegalArgumentException
- if the initial capacity is negative
or the load factor is nonpositivepublic boolean containsValue(java.lang.Object value)
containsValue
in interface java.util.Map<K,V>
containsValue
in class KeyComparatorHashMap<K,V>
value
- value whose presence in this map is to be testedpublic V get(java.lang.Object key)
null
if this map contains no mapping for the key.
More formally, if this map contains a mapping from a key
k
to a value v
such that (key==null ? k==null :
key.equals(k))
, then this method returns v
; otherwise
it returns null
. (There can be at most one such mapping.)
A return value of null
does not necessarily
indicate that the map contains no mapping for the key; it's also
possible that the map explicitly maps the key to null
.
The containsKey
operation may be used to
distinguish these two cases.
get
in interface java.util.Map<K,V>
get
in class KeyComparatorHashMap<K,V>
key
- the key whose associated value is to be returned.KeyComparatorHashMap.put(Object, Object)
public void clear()
protected boolean removeEldestEntry(java.util.Map.Entry<K,V> eldest)
Sample use: this override will allow the map to grow up to 100 entries and then delete the eldest entry each time a new entry is added, maintaining a steady state of 100 entries.
private static final int MAX_ENTRIES = 100; protected boolean removeEldestEntry(Map.Entry eldest) { return size() > MAX_ENTRIES; }
This method typically does not modify the map in any way, instead allowing the map to modify itself as directed by its return value. It is permitted for this method to modify the map directly, but if it does so, it must return false (indicating that the map should not attempt any further modification). The effects of returning true after modifying the map from within this method are unspecified.
This implementation merely returns false (so that this map acts like a normal map - the eldest element is never removed).
eldest
- The least recently inserted entry in the map, or if
this is an access-ordered map, the least recently accessed
entry. This is the entry that will be removed it this
method returns true. If the map was empty prior
to the put or putAll invocation resulting
in this invocation, this will be the entry that was just
inserted; in other words, if the map contains a single
entry, the eldest entry is also the newest.Copyright © 2016 Oracle Corporation. All Rights Reserved.