public class WeakIdentityHashMap
extends java.lang.Object
implements java.util.Map
Based on java.util.WeakHashMap
IdentityHashMap,
WeakHashMap| Modifier and Type | Class and Description |
|---|---|
private static class |
WeakIdentityHashMap.Entry
The entries in this hash table extend WeakReference, using its main ref
field as the key.
|
private class |
WeakIdentityHashMap.EntryIterator |
private class |
WeakIdentityHashMap.EntrySet |
private class |
WeakIdentityHashMap.HashIterator |
private class |
WeakIdentityHashMap.KeyIterator |
private class |
WeakIdentityHashMap.KeySet |
(package private) static class |
WeakIdentityHashMap.SimpleEntry |
private class |
WeakIdentityHashMap.ValueIterator |
private class |
WeakIdentityHashMap.Values |
| Modifier and Type | Field and Description |
|---|---|
private static int |
DEFAULT_INITIAL_CAPACITY
The default initial capacity -- MUST be a power of two.
|
private static float |
DEFAULT_LOAD_FACTOR
The load fast used when none specified in constructor.
|
private java.util.Set |
entrySet |
(package private) java.util.Set |
keySet
Each of these fields are initialized to contain an instance of the
appropriate view the first time this view is requested.
|
private float |
loadFactor
The load factor for the hash table.
|
private static int |
MAXIMUM_CAPACITY
The maximum capacity, used if a higher value is implicitly specified
by either of the constructors with arguments.
|
private int |
modCount
The number of times this HashMap has been structurally modified
Structural modifications are those that change the number of mappings in
the HashMap or otherwise modify its internal structure (e.g.,
rehash).
|
private static java.lang.Object |
NULL_KEY
Value representing null keys inside tables.
|
private java.lang.ref.ReferenceQueue |
queue
Reference queue for cleared WeakEntries
|
private int |
size
The number of key-value mappings contained in this weak hash map.
|
private WeakIdentityHashMap.Entry[] |
table
The table, resized as necessary.
|
private int |
threshold
The next size value at which to resize (capacity * load factor).
|
(package private) java.util.Collection |
values |
| Constructor and Description |
|---|
WeakIdentityHashMap()
Constructs a new, empty WeakIdentityHashMap with the default
initial capacity (16) and the default load factor (0.75).
|
WeakIdentityHashMap(int initialCapacity)
Constructs a new, empty WeakIdentityHashMap with the given
initial capacity and the default load factor, which is 0.75.
|
WeakIdentityHashMap(int initialCapacity,
float loadFactor)
Constructs a new, empty WeakIdentityHashMap with the given
initial capacity and the given load factor.
|
WeakIdentityHashMap(java.util.Map t)
Constructs a new WeakIdentityHashMap with the same mappings as
the specified Map.
|
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Removes all mappings from this map.
|
boolean |
containsKey(java.lang.Object key)
Returns true if this map contains a mapping for the
specified key.
|
private boolean |
containsNullValue()
Special-case code for containsValue with null argument
|
boolean |
containsValue(java.lang.Object value)
Returns true if this map maps one or more keys to the
specified value.
|
java.util.Set |
entrySet()
Returns a collection view of the mappings contained in this map.
|
private void |
expungeStaleEntries()
Expunge stale entries from the table.
|
java.lang.Object |
get(java.lang.Object key)
Returns the value to which the specified key is mapped in this weak
hash map, or null if the map contains no mapping for
this key.
|
(package private) WeakIdentityHashMap.Entry |
getEntry(java.lang.Object key)
Returns the entry associated with the specified key in the HashMap.
|
private WeakIdentityHashMap.Entry[] |
getTable()
Return the table after first expunging stale entries
|
(package private) int |
hash(java.lang.Object x)
Return a hash code for non-null Object x.
|
(package private) static int |
indexFor(int h,
int length)
Return index for hash code h.
|
boolean |
isEmpty()
Returns true if this map contains no key-value mappings.
|
java.util.Set |
keySet()
Returns a set view of the keys contained in this map.
|
private static java.lang.Object |
maskNull(java.lang.Object key)
Use NULL_KEY for key if it is null.
|
java.lang.Object |
put(java.lang.Object key,
java.lang.Object value)
Associates the specified value with the specified key in this map.
|
void |
putAll(java.util.Map t)
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.
|
java.lang.Object |
remove(java.lang.Object key)
Removes the mapping for this key from this map if present.
|
(package private) WeakIdentityHashMap.Entry |
removeMapping(java.lang.Object o)
Special version of remove needed by Entry set
|
(package private) void |
resize(int newCapacity)
Rehashes the contents of this map into a new HashMap instance
with a larger capacity.
|
int |
size()
Returns the number of key-value mappings in this map.
|
private void |
transfer(WeakIdentityHashMap.Entry[] src,
WeakIdentityHashMap.Entry[] dest)
Transfer all entries from src to dest tables
|
private static java.lang.Object |
unmaskNull(java.lang.Object key)
Return internal representation of null key back to caller as null
|
java.util.Collection |
values()
Returns a collection view of the values contained in this map.
|
private static final int DEFAULT_INITIAL_CAPACITY
private static final int MAXIMUM_CAPACITY
private static final float DEFAULT_LOAD_FACTOR
private WeakIdentityHashMap.Entry[] table
private int size
private int threshold
private final float loadFactor
private final java.lang.ref.ReferenceQueue queue
private volatile int modCount
transient volatile java.util.Set keySet
transient volatile java.util.Collection values
private static final java.lang.Object NULL_KEY
private transient java.util.Set entrySet
public WeakIdentityHashMap(int initialCapacity,
float loadFactor)
initialCapacity - The initial capacity of the
WeakIdentityHashMaploadFactor - The load factor of the
WeakIdentityHashMapjava.lang.IllegalArgumentException - If the initial capacity is negative,
or if the load factor is nonpositive.public WeakIdentityHashMap(int initialCapacity)
initialCapacity - The initial capacity of the
WeakIdentityHashMapjava.lang.IllegalArgumentException - If the initial capacity is negative.public WeakIdentityHashMap()
public WeakIdentityHashMap(java.util.Map t)
t - the map whose mappings are to be placed in this map.java.lang.NullPointerException - if the specified map is null.private static java.lang.Object maskNull(java.lang.Object key)
private static java.lang.Object unmaskNull(java.lang.Object key)
int hash(java.lang.Object x)
static int indexFor(int h,
int length)
private void expungeStaleEntries()
private WeakIdentityHashMap.Entry[] getTable()
public int size()
size in interface java.util.Mappublic boolean isEmpty()
isEmpty in interface java.util.Mappublic java.lang.Object get(java.lang.Object key)
get in interface java.util.Mapkey - the key whose associated value is to be returned.put(Object, Object)public boolean containsKey(java.lang.Object key)
containsKey in interface java.util.Mapkey - The key whose presence in this map is to be testedWeakIdentityHashMap.Entry getEntry(java.lang.Object key)
public java.lang.Object put(java.lang.Object key,
java.lang.Object value)
put in interface java.util.Mapkey - key with which the specified value is to be associated.value - value to be associated with the specified key.void resize(int newCapacity)
newCapacity - the new capacity, MUST be a power of two.private void transfer(WeakIdentityHashMap.Entry[] src, WeakIdentityHashMap.Entry[] dest)
public void putAll(java.util.Map t)
putAll in interface java.util.Mapt - mappings to be stored in this map.java.lang.NullPointerException - if the specified map is null.public java.lang.Object remove(java.lang.Object key)
remove in interface java.util.Mapkey - key whose mapping is to be removed from the map.WeakIdentityHashMap.Entry removeMapping(java.lang.Object o)
public void clear()
clear in interface java.util.Mappublic boolean containsValue(java.lang.Object value)
containsValue in interface java.util.Mapvalue - value whose presence in this map is to be tested.private boolean containsNullValue()
public java.util.Set keySet()
keySet in interface java.util.Mappublic java.util.Collection values()
values in interface java.util.Mappublic java.util.Set entrySet()
entrySet in interface java.util.MapMap.Entry