public class LinkedIdentityHashMap<K,V>
extends java.util.AbstractMap<K,V>
implements java.util.Map<K,V>
Modifier and Type | Field and Description |
---|---|
protected java.util.Set<java.util.Map.Entry<K,V>> |
entrySet |
protected java.util.Set<K> |
keySet |
protected java.util.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(java.util.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.
|
java.lang.Object |
clone()
Returns a shallow copy of this MyIdentityHashMap instance: the keys and
values themselves are not cloned.
|
boolean |
containsKey(java.lang.Object key)
Returns true if this map contains a mapping for the
specified key.
|
boolean |
containsValue(java.lang.Object value)
Returns true if this map maps one or more keys to the
specified value.
|
java.util.Set<java.util.Map.Entry<K,V>> |
entrySet()
Returns a collection view of the mappings contained in this map.
|
V |
get(java.lang.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.
|
java.util.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(java.util.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(java.lang.Object key)
Removes the mapping for this key from this map if present.
|
protected boolean |
removeEldestEntry(java.util.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.
|
java.util.Collection<V> |
values()
Returns a collection view of the values contained in this map.
|
protected transient volatile java.util.Set<K> keySet
protected transient java.util.Set<java.util.Map.Entry<K,V>> entrySet
protected transient volatile java.util.Collection<V> values
public LinkedIdentityHashMap(int initialCapacity, float loadFactor)
initialCapacity
- the initial capacity.loadFactor
- the load factor.java.lang.IllegalArgumentException
- if the initial capacity is negative
or the load factor is nonpositive.public LinkedIdentityHashMap(int initialCapacity)
initialCapacity
- the initial capacity.java.lang.IllegalArgumentException
- if the initial capacity is negative.public LinkedIdentityHashMap()
public LinkedIdentityHashMap(java.util.Map<? extends K,? extends V> m)
m
- the map whose mappings are to be placed in this map.java.lang.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.java.lang.IllegalArgumentException
- if the initial capacity is negative
or the load factor is nonpositive.public boolean containsValue(java.lang.Object value)
public V get(java.lang.Object key)
get
in interface java.util.Map<K,V>
key
- key whose associated value is to be returned.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.public int size()
size
in interface java.util.Map<K,V>
size
in class java.util.AbstractMap<K,V>
public boolean isEmpty()
isEmpty
in interface java.util.Map<K,V>
isEmpty
in class java.util.AbstractMap<K,V>
public boolean containsKey(java.lang.Object key)
containsKey
in interface java.util.Map<K,V>
containsKey
in class java.util.AbstractMap<K,V>
key
- The key whose presence in this map is to be testedpublic V put(K key, V value)
put
in interface java.util.Map<K,V>
put
in class java.util.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(java.util.Map<? extends K,? extends V> m)
putAll
in interface java.util.Map<K,V>
putAll
in class java.util.AbstractMap<K,V>
m
- mappings to be stored in this map.java.lang.NullPointerException
- if the specified map is null.public V remove(java.lang.Object key)
remove
in interface java.util.Map<K,V>
remove
in class java.util.AbstractMap<K,V>
key
- key whose mapping is to be removed from the map.public java.lang.Object clone()
clone
in class java.util.AbstractMap<K,V>
public java.util.Set<K> keySet()
keySet
in interface java.util.Map<K,V>
keySet
in class java.util.AbstractMap<K,V>
public java.util.Collection<V> values()
values
in interface java.util.Map<K,V>
values
in class java.util.AbstractMap<K,V>
public java.util.Set<java.util.Map.Entry<K,V>> entrySet()
entrySet
in interface java.util.Map<K,V>
entrySet
in class java.util.AbstractMap<K,V>
Map.Entry