# Class WeakValueMap<K,V>

java.lang.Object
java.util.AbstractMap<K,V>
org.apache.cayenne.util.WeakValueMap<K,V>

All Implemented Interfaces:
  `Serializable, Map<K,V>`

public class WeakValueMap<K,V> extends AbstractMap<K,V> implements Serializable
Map that stores values wrapped into `WeakReference`

Since:
  4.1
See Also:
  - `SoftValueMap`
  - Serialized Form

- ## Nested Class Summary

  ### Nested classes/interfaces inherited from class AbstractMap

  `AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>`

  ### Nested classes/interfaces inherited from interface Map

  `Map.Entry<K,V>`

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected Set<Map.Entry<K,V>>`
  `entrySet`
  This is a lazily created set of entries that is essentially a view to actual data
  `protected Consumer<K>`
  `keyCleanupCallback`
  `protected HashMap<K, WeakReference<V>>`
  `map`
  This is a main data storage used for most operations
  `protected ReferenceQueue<V>`
  `referenceQueue`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `WeakValueMap()`
  `WeakValueMap(int initialCapacity)`
  `WeakValueMap(Map<? extends K, ? extends V> m)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected void`
  `checkReferenceQueue()`
  Cleanup all references collected by GC so far
  `void`
  `clear()`
  `boolean`
  `containsKey(Object key)`
  `boolean`
  `containsValue(Object value)`
  `Set<Map.Entry<K,V>>`
  `entrySet()`
  `V`
  `get(Object key)`
  `boolean`
  `isEmpty()`
  `Set<K>`
  `keySet()`
  `V`
  `put(K key, V value)`
  `void`
  `putAll(Map<? extends K, ? extends V> m)`
  `V`
  `remove(Object key)`
  `void`
  `setKeyCleanupCallback(Consumer<K> keyCleanupCallback)`
  Set callback that will be notified with a key on each value removal due to the corresponding value reference cleaned up by the GC.
  `int`
  `size()`
  `Collection<V>`
  `values()`

  ### Methods inherited from class AbstractMap

  `clone, equals, hashCode, toString`

  ### Methods inherited from class Object

  `finalize, getClass, notify, notifyAll, wait, wait, wait`

  ### Methods inherited from interface Map

  `compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll`

- ## Field Details

  - ### map

    protected transient HashMap<K, WeakReference<V>> map
    This is a main data storage used for most operations

  - ### referenceQueue

    protected transient ReferenceQueue<V> referenceQueue

  - ### entrySet

    protected transient Set<Map.Entry<K,V>> entrySet
    This is a lazily created set of entries that is essentially a view to actual data

  - ### keyCleanupCallback

    protected transient Consumer<K> keyCleanupCallback
    Since:
      4.2.2

- ## Constructor Details

  - ### WeakValueMap

    public WeakValueMap()

  - ### WeakValueMap

    public WeakValueMap(int initialCapacity)

  - ### WeakValueMap

    public WeakValueMap(Map<? extends K, ? extends V> m)

- ## Method Details

  - ### size

    public int size()
    Specified by:
      `size` in interface `Map<K,V>`
    Overrides:
      `size` in class `AbstractMap<K,V>`

  - ### isEmpty

    public boolean isEmpty()
    Specified by:
      `isEmpty` in interface `Map<K,V>`
    Overrides:
      `isEmpty` in class `AbstractMap<K,V>`

  - ### containsKey

    public boolean containsKey(Object key)
    Specified by:
      `containsKey` in interface `Map<K,V>`
    Overrides:
      `containsKey` in class `AbstractMap<K,V>`

  - ### containsValue

    public boolean containsValue(Object value)
    Specified by:
      `containsValue` in interface `Map<K,V>`
    Overrides:
      `containsValue` in class `AbstractMap<K,V>`

  - ### get

    public V get(Object key)
    Specified by:
      `get` in interface `Map<K,V>`
    Overrides:
      `get` in class `AbstractMap<K,V>`

  - ### put

    public V put(K key, V value)
    Specified by:
      `put` in interface `Map<K,V>`
    Overrides:
      `put` in class `AbstractMap<K,V>`

  - ### remove

    public V remove(Object key)
    Specified by:
      `remove` in interface `Map<K,V>`
    Overrides:
      `remove` in class `AbstractMap<K,V>`

  - ### putAll

    public void putAll(Map<? extends K, ? extends V> m)
    Specified by:
      `putAll` in interface `Map<K,V>`
    Overrides:
      `putAll` in class `AbstractMap<K,V>`

  - ### clear

    public void clear()
    Specified by:
      `clear` in interface `Map<K,V>`
    Overrides:
      `clear` in class `AbstractMap<K,V>`

  - ### keySet

    public Set<K> keySet()
    Specified by:
      `keySet` in interface `Map<K,V>`
    Overrides:
      `keySet` in class `AbstractMap<K,V>`

  - ### values

    public Collection<V> values()
    Specified by:
      `values` in interface `Map<K,V>`
    Overrides:
      `values` in class `AbstractMap<K,V>`

  - ### entrySet

    public Set<Map.Entry<K,V>> entrySet()
    Specified by:
      `entrySet` in interface `Map<K,V>`
    Specified by:
      `entrySet` in class `AbstractMap<K,V>`

  - ### setKeyCleanupCallback

    public void setKeyCleanupCallback(Consumer<K> keyCleanupCallback)
    Set callback that will be notified with a key on each value removal due to the corresponding value reference cleaned up by the GC.
    Parameters:
      `keyCleanupCallback` - callback to set
    Since:
      4.2.2

  - ### checkReferenceQueue

    protected void checkReferenceQueue()
    Cleanup all references collected by GC so far