public class LinkedIdentityHashMap<K,V> extends AbstractMap<K,V> implements Map<K,V>
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
Modifier and Type | Field and Description |
---|---|
protected Set<Map.Entry<K,V>> |
entrySet |
protected Set<K> |
keySet |
protected Collection<V> |
values |
Constructor and Description |
---|
LinkedIdentityHashMap()
Constructs an empty insertion-ordered LinkedIdentityHashMap instance
with a default capacity (16) and load factor (0.75).
|
LinkedIdentityHashMap(int initialCapacity)
Constructs an empty insertion-ordered LinkedIdentityHashMap instance
with the specified initial capacity and a default load factor (0.75).
|
LinkedIdentityHashMap(int initialCapacity,
float loadFactor)
Constructs an empty insertion-ordered LinkedIdentityHashMap instance
with the specified initial capacity and load factor.
|
LinkedIdentityHashMap(int initialCapacity,
float loadFactor,
boolean accessOrder)
Constructs an empty LinkedIdentityHashMap instance with the
specified initial capacity, load factor and ordering mode.
|
LinkedIdentityHashMap(Map<? extends K,? extends V> m)
Constructs an insertion-ordered LinkedIdentityHashMap instance with
the same mappings as the specified map.
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Removes all mappings from this map.
|
Object |
clone()
Returns a shallow copy of this MyIdentityHashMap instance: the keys and
values themselves are not cloned.
|
boolean |
containsKey(Object key)
Returns true if this map contains a mapping for the
specified key.
|
boolean |
containsValue(Object value)
Returns true if this map maps one or more keys to the
specified value.
|
Set<Map.Entry<K,V>> |
entrySet()
Returns a collection view of the mappings contained in this map.
|
V |
get(Object key)
Returns the value to which this map maps the specified key.
|
boolean |
isEmpty()
Returns true if this map contains no key-value mappings.
|
Set<K> |
keySet()
Returns a set view of the keys contained in this map.
|
V |
put(K key,
V value)
Associates the specified value with the specified key in this map.
|
void |
putAll(Map<? extends K,? extends V> m)
Copies all of the mappings from the specified map to this map
These mappings will replace any mappings that
this map had for any of the keys currently in the specified map.
|
V |
remove(Object key)
Removes the mapping for this key from this map if present.
|
protected boolean |
removeEldestEntry(Map.Entry<K,V> eldest)
Returns true if this map should remove its eldest entry.
|
int |
size()
Returns the number of key-value mappings in this map.
|
Collection<V> |
values()
Returns a collection view of the values contained in this map.
|
equals, hashCode, toString
protected transient volatile Set<K> keySet
protected transient volatile Collection<V> values
public LinkedIdentityHashMap(int initialCapacity, float loadFactor)
initialCapacity
- the initial capacity.loadFactor
- the load factor.IllegalArgumentException
- if the initial capacity is negative
or the load factor is nonpositive.public LinkedIdentityHashMap(int initialCapacity)
initialCapacity
- the initial capacity.IllegalArgumentException
- if the initial capacity is negative.public LinkedIdentityHashMap()
public LinkedIdentityHashMap(Map<? extends K,? extends V> m)
m
- the map whose mappings are to be placed in this map.NullPointerException
- if the specified map is null.public LinkedIdentityHashMap(int initialCapacity, float loadFactor, boolean accessOrder)
initialCapacity
- the initial capacity.loadFactor
- the load factor.accessOrder
- the ordering mode - true for
access-order, false for insertion-order.IllegalArgumentException
- if the initial capacity is negative
or the load factor is nonpositive.public boolean containsValue(Object value)
containsValue
in interface Map<K,V>
value
- value whose presence in this map is to be tested.public V get(Object key)
get
in interface Map<K,V>
key
- key whose associated value is to be returned.put(Object, Object)
public void clear()
protected boolean removeEldestEntry(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.public int size()
size
in interface Map<K,V>
size
in class AbstractMap<K,V>
public boolean isEmpty()
isEmpty
in interface Map<K,V>
isEmpty
in class AbstractMap<K,V>
public boolean containsKey(Object key)
containsKey
in interface Map<K,V>
containsKey
in class AbstractMap<K,V>
key
- The key whose presence in this map is to be testedpublic V put(K key, V value)
put
in interface Map<K,V>
put
in class AbstractMap<K,V>
key
- key with which the specified value is to be associated.value
- value to be associated with the specified key.public void putAll(Map<? extends K,? extends V> m)
putAll
in interface Map<K,V>
putAll
in class AbstractMap<K,V>
m
- mappings to be stored in this map.NullPointerException
- if the specified map is null.public V remove(Object key)
remove
in interface Map<K,V>
remove
in class AbstractMap<K,V>
key
- key whose mapping is to be removed from the map.public Object clone()
clone
in class AbstractMap<K,V>
public Set<K> keySet()
keySet
in interface Map<K,V>
keySet
in class AbstractMap<K,V>
public Collection<V> values()
values
in interface Map<K,V>
values
in class AbstractMap<K,V>
public Set<Map.Entry<K,V>> entrySet()
entrySet
in interface Map<K,V>
entrySet
in class AbstractMap<K,V>
Map.Entry
Copyright © 2015. All rights reserved.