Class WeakKeyMap<K,V>

java.lang.Object
com.yourkit.probes.WeakKeyMap<K,V>

public class WeakKeyMap<K,V> extends Object
A hash map with weak keys which checks key equality by reference and uses key's identity hash code. Use this map to avoid use of equals() and hashCode() methods of the keys which may throw exceptions or be otherwise unsafe.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a new, empty WeakKeyMap with the default initial capacity (16) and load factor (0.75).
    WeakKeyMap(int initialCapacity, float loadFactor)
    Constructs a new, empty WeakKeyMap with the given initial capacity and the given load factor.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Returns TRUE if this map contains a mapping for the specified key.
    get(Object key)
    Returns the value to which the specified key is mapped, or NULL if this map contains no mapping for the key.
    boolean
    Returns TRUE if this map contains no key-value mappings.
    put(K key, V value)
    Associates the specified value with the specified key in this map.
    Removes the mapping for a key from this weak hash map if it is present.
    int
    Returns the number of key-value mappings in this map.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • WeakKeyMap

      public WeakKeyMap(int initialCapacity, float loadFactor)
      Constructs a new, empty WeakKeyMap with the given initial capacity and the given load factor.
      Parameters:
      initialCapacity - The initial capacity of the WeakKeyMap
      loadFactor - The load factor of the WeakKeyMap
      Throws:
      IllegalArgumentException - if the initial capacity is negative, or if the load factor is nonpositive.
    • WeakKeyMap

      public WeakKeyMap()
      Constructs a new, empty WeakKeyMap with the default initial capacity (16) and load factor (0.75).
  • Method Details

    • size

      public int size()
      Returns the number of key-value mappings in this map. This result is a snapshot, and may not reflect unprocessed entries that will be removed before next attempted access because they are no longer referenced.
    • isEmpty

      public boolean isEmpty()
      Returns TRUE if this map contains no key-value mappings. This result is a snapshot, and may not reflect unprocessed entries that will be removed before next attempted access because they are no longer referenced.
    • get

      public V get(Object key)

      Returns the value to which the specified key is mapped, or 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 == 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.

      See Also:
    • containsKey

      public boolean containsKey(Object key)
      Returns TRUE if this map contains a mapping for the specified key.
      Parameters:
      key - The key whose presence in this map is to be tested
      Returns:
      TRUE if there is a mapping for key; FALSE otherwise
    • put

      public V put(K key, V value)
      Associates the specified value with the specified key in this map. If the map previously contained a mapping for this key, the old value is replaced.
      Parameters:
      key - key with which the specified value is to be associated.
      value - value to be associated with the specified key.
      Returns:
      the previous value associated with key, or NULL if there was no mapping for key. (A NULL return can also indicate that the map previously associated NULL with key.)
    • remove

      public V remove(Object key)

      Removes the mapping for a key from this weak hash map if it is present. More formally, if this map contains a mapping from key k to value v such that (key==null ? k==null : key == k), that mapping is removed. (The map can contain at most one such mapping.)

      Returns the value to which this map previously associated the key, or NULL if the map contained no mapping for the key. A return value of NULL does not necessarily indicate that the map contained no mapping for the key; it's also possible that the map explicitly mapped the key to NULL.

      The map will not contain a mapping for the specified key once the call returns.

      Parameters:
      key - key whose mapping is to be removed from the map
      Returns:
      the previous value associated with key, or NULL if there was no mapping for key