Class AbstractReferencedValueMap<K,​V>

  • Type Parameters:
    K - is the type of the keys.
    V - is the type of the values.
    All Implemented Interfaces:
    Map<K,​V>
    Direct Known Subclasses:
    AbstractPhantomValueMap, AbstractSoftValueMap, AbstractWeakValueMap

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

    This abstract implementation does not decide if the map is based on a tree or on a hashtable; it does not impose soft or weak references.

    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
    • Method Detail

      • maskNull

        @Pure
        protected static <VALUET> VALUET maskNull​(VALUET value)
        Mask the null values given by the used of this map.

        This method replaces the null value by the internal representation NULL_VALUE.

        Type Parameters:
        VALUET - is the type of the value.
        Parameters:
        value - is the value given by the user of this map.
        Returns:
        the internal representation of the value.
        See Also:
        unmaskNull(Object)
      • unmaskNull

        @Pure
        protected static <VALUET> VALUET unmaskNull​(VALUET value)
        Unmask the null values given by the used of this map.

        This method replaces the internal representation NULL_VALUE of null values by its user representation null.

        Type Parameters:
        VALUET - is the type of the value.
        Parameters:
        value - is the value given by the user of this map.
        Returns:
        the internal representation of the value.
        See Also:
        maskNull(Object)
      • finishToArray

        static <T> T[] finishToArray​(T[] array,
                                     Iterator<?> it)
        Reallocates the array being used within toArray when the iterator returned more elements than expected, and finishes filling it from the iterator.
        Type Parameters:
        T - the type of the elements in the array.
        Parameters:
        array - the array, replete with previously stored elements
        it - the in-progress iterator over this collection
        Returns:
        array containing the elements in the given array, plus any further elements returned by the iterator, trimmed to size
      • expurgeNow

        protected final void expurgeNow()
        Clean the references that was marked as released inside the queue.
      • isDeeplyExpurge

        @Pure
        public final boolean isDeeplyExpurge()
        Replies if this map expurge all the released references even if they are not enqueued by the virtual machine.
        Returns:
        true is the values are deeply expurged when they are released from the moemory, otherwise false.
      • setDeeplyExpurge

        public final boolean setDeeplyExpurge​(boolean deeplyExpurge)
        Set if this map expurge all the released references even if they are not enqueued by the virtual machine.
        Parameters:
        deeplyExpurge - must be true to expurge all the released values, otherwise false to expurge only the enqueued values.
        Returns:
        the old value of this flag
      • expurgeQueuedReferences

        public final void expurgeQueuedReferences()
        Clean the references that was marked as released inside the queue.
      • expurge

        public final void expurge()
        Clean the references that was released.
      • makeValue

        protected abstract AbstractReferencedValueMap.ReferencableValue<K,​V> makeValue​(K key,
                                                                                             V value,
                                                                                             ReferenceQueue<V> refQueue)
        Create a storage object that permits to put the specified elements inside this map.
        Parameters:
        key - is the key associated to the value
        value - is the value
        refQueue - is the reference queue to use
        Returns:
        the new storage object
      • makeValue

        protected final AbstractReferencedValueMap.ReferencableValue<K,​V> makeValue​(K key,
                                                                                          V value)
        Create a storage object that permits to put the specified elements inside this map.
        Parameters:
        key - is the key associated to the value
        value - is the value
        Returns:
        the new storage object
      • put

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