Class ReferenceValueMap<K,​V>

  • Type Parameters:
    K - the key type
    V - the value type
    All Implemented Interfaces:
    java.util.Map<K,​V>
    Direct Known Subclasses:
    ReferenceValueHashMap, ReferenceValueTreeMap

    public abstract class ReferenceValueMap<K,​V>
    extends java.util.AbstractMap<K,​V>
    This Map will remove entries when the value in the map has been cleaned from garbage collection
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private class  ReferenceValueMap.EntrySet
      EntrySet.
      private class  ReferenceValueMap.EntrySetIterator
      EntrySet iterator
      • Nested classes/interfaces inherited from class java.util.AbstractMap

        java.util.AbstractMap.SimpleEntry<K extends java.lang.Object,​V extends java.lang.Object>, java.util.AbstractMap.SimpleImmutableEntry<K extends java.lang.Object,​V extends java.lang.Object>
      • Nested classes/interfaces inherited from interface java.util.Map

        java.util.Map.Entry<K extends java.lang.Object,​V extends java.lang.Object>
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.Map<K,​ValueRef<K,​V>> map
      Hash table mapping keys to ref values
      private java.lang.ref.ReferenceQueue<V> queue
      Reference queue for cleared RefKeys
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()  
      boolean containsKey​(java.lang.Object key)  
      protected abstract ValueRef<K,​V> create​(K key, V value, java.lang.ref.ReferenceQueue<V> q)
      Create new value ref instance.
      protected abstract java.util.Map<K,​ValueRef<K,​V>> createMap()
      Create map.
      protected abstract java.util.Map<K,​ValueRef<K,​V>> createMap​(int initialCapacity)
      Create map.
      protected abstract java.util.Map<K,​ValueRef<K,​V>> createMap​(int initialCapacity, float loadFactor)
      Create map.
      protected abstract java.util.Map<K,​ValueRef<K,​V>> createMap​(java.util.Comparator<K> comparator)
      Create map.
      protected abstract java.util.Map<K,​ValueRef<K,​V>> createMap​(java.util.SortedMap<K,​ValueRef<K,​V>> map)
      Create map.
      java.util.Set<java.util.Map.Entry<K,​V>> entrySet()  
      V get​(java.lang.Object key)  
      private void processQueue()
      Remove all entries whose values have been discarded.
      V put​(K key, V value)  
      V remove​(java.lang.Object key)  
      int size()  
      java.lang.String toString()  
      • Methods inherited from class java.util.AbstractMap

        clone, containsValue, equals, hashCode, isEmpty, keySet, putAll, values
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Map

        compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
    • Field Detail

      • map

        private java.util.Map<K,​ValueRef<K,​V>> map
        Hash table mapping keys to ref values
      • queue

        private java.lang.ref.ReferenceQueue<V> queue
        Reference queue for cleared RefKeys
    • Constructor Detail

      • ReferenceValueMap

        protected ReferenceValueMap()
      • ReferenceValueMap

        protected ReferenceValueMap​(int initialCapacity)
      • ReferenceValueMap

        protected ReferenceValueMap​(int initialCapacity,
                                    float loadFactor)
      • ReferenceValueMap

        protected ReferenceValueMap​(java.util.Map<K,​V> t)
      • ReferenceValueMap

        protected ReferenceValueMap​(java.util.Comparator<K> comparator)
      • ReferenceValueMap

        protected ReferenceValueMap​(java.util.SortedMap<K,​ValueRef<K,​V>> sorted)
    • Method Detail

      • createMap

        protected abstract java.util.Map<K,​ValueRef<K,​V>> createMap()
        Create map.
        Returns:
        new map instance
      • createMap

        protected abstract java.util.Map<K,​ValueRef<K,​V>> createMap​(int initialCapacity)
        Create map.
        Parameters:
        initialCapacity - the initial capacity
        Returns:
        new map instance
      • createMap

        protected abstract java.util.Map<K,​ValueRef<K,​V>> createMap​(int initialCapacity,
                                                                                float loadFactor)
        Create map.
        Parameters:
        initialCapacity - the initial capacity
        loadFactor - the load factor
        Returns:
        new map instance
      • createMap

        protected abstract java.util.Map<K,​ValueRef<K,​V>> createMap​(java.util.Comparator<K> comparator)
        Create map.
        Parameters:
        comparator - the comparator
        Returns:
        new map instance
      • createMap

        protected abstract java.util.Map<K,​ValueRef<K,​V>> createMap​(java.util.SortedMap<K,​ValueRef<K,​V>> map)
        Create map.
        Parameters:
        map - the sorted map
        Returns:
        new map instance
      • size

        public int size()
        Specified by:
        size in interface java.util.Map<K,​V>
        Overrides:
        size in class java.util.AbstractMap<K,​V>
      • containsKey

        public boolean containsKey​(java.lang.Object key)
        Specified by:
        containsKey in interface java.util.Map<K,​V>
        Overrides:
        containsKey in class java.util.AbstractMap<K,​V>
      • get

        public V get​(java.lang.Object key)
        Specified by:
        get in interface java.util.Map<K,​V>
        Overrides:
        get in class java.util.AbstractMap<K,​V>
      • put

        public V put​(K key,
                     V value)
        Specified by:
        put in interface java.util.Map<K,​V>
        Overrides:
        put in class java.util.AbstractMap<K,​V>
      • remove

        public V remove​(java.lang.Object key)
        Specified by:
        remove in interface java.util.Map<K,​V>
        Overrides:
        remove in class java.util.AbstractMap<K,​V>
      • entrySet

        public java.util.Set<java.util.Map.Entry<K,​V>> entrySet()
        Specified by:
        entrySet in interface java.util.Map<K,​V>
        Specified by:
        entrySet in class java.util.AbstractMap<K,​V>
      • clear

        public void clear()
        Specified by:
        clear in interface java.util.Map<K,​V>
        Overrides:
        clear in class java.util.AbstractMap<K,​V>
      • processQueue

        private void processQueue()
        Remove all entries whose values have been discarded.
      • create

        protected abstract ValueRef<K,​V> create​(K key,
                                                      V value,
                                                      java.lang.ref.ReferenceQueue<V> q)
        Create new value ref instance.
        Parameters:
        key - the key
        value - the value
        q - the ref queue
        Returns:
        new value ref instance
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.util.AbstractMap<K,​V>