Class WeakValueHashMap<K,​V>

  • Type Parameters:
    K - is the type of the keys.
    V - is the type of the values.
    All Implemented Interfaces:
    Map<K,​V>

    public class WeakValueHashMap<K,​V>
    extends AbstractWeakValueMap<K,​V>
    A Map implementation with weak values. An entry in a WeakValueHashMap will automatically be removed when its value is no longer in ordinary use or null.

    This class was inspirated from WeakHashMap and uses a HashMap as its internal data structure.

    This class has a special flag which permits to control the way how the released references are expurged: AbstractReferencedValueMap.isDeeplyExpurge(), AbstractReferencedValueMap.setDeeplyExpurge(boolean). If this flag is true, all the released references will be immediately removed from the map even if they are not enqueued by the virtual machine (see AbstractReferencedValueMap.expurge(). If this flag is false, only the enqueued references will be removed from the map (see AbstractReferencedValueMap.expurgeQueuedReferences().

    If this map does not use a "deep expurge" of the released references, it could contains null values that corresponds to values that are released by the garbage collector. If a "deep expurge" is used, all the values released by the garbage collector will be removed from the map.

    "Deep expurge" consumes much more time that "No deep expurge". This is the reason why this feature is not activated by default.

    The "deep expurge" feature was added to fix the uncoherent behavior of the garbage collector which seems to not always enqueued the released values (sometimes the queue is empty even if a value was released).

    Since:
    5.8
    Version:
    17.0 2020-01-04 14:41:38
    Author:
    Stéphane GALLAND
    Maven Group Id:
    org.arakhne.afc.core
    Maven Artifact Id:
    references
    • Constructor Detail

      • WeakValueHashMap

        public WeakValueHashMap​(int initialCapacity,
                                float loadFactor)
        Constructs an empty HashMap with the specified initial capacity and load factor.
        Parameters:
        initialCapacity - the initial capacity
        loadFactor - the load factor
        Throws:
        IllegalArgumentException - if the initial capacity is negative or the load factor is nonpositive
      • WeakValueHashMap

        public WeakValueHashMap​(int initialCapacity)
        Constructs an empty HashMap with the specified initial capacity and the default load factor (0.75).
        Parameters:
        initialCapacity - the initial capacity.
        Throws:
        IllegalArgumentException - if the initial capacity is negative.
      • WeakValueHashMap

        public WeakValueHashMap()
        Constructs an empty HashMap with the default initial capacity (16) and the default load factor (0.75).
      • WeakValueHashMap

        public WeakValueHashMap​(Map<? extends K,​? extends V> map)
        Constructs a new HashMap with the same mappings as the specified Map. The HashMap is created with default load factor (0.75) and an initial capacity sufficient to hold the mappings in the specified Map.
        Parameters:
        map - the map whose mappings are to be placed in this map
        Throws:
        NullPointerException - if the specified map is null