Class MildValues<K,​V>

  • All Implemented Interfaces:
    java.util.Map<K,​V>
    Direct Known Subclasses:
    MildConcurrentValues

    class MildValues<K,​V>
    extends java.lang.Object
    implements java.util.Map<K,​V>
    NON-thread-safe Map whose values are kept alive by soft/weak References.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      (package private) class  MildValues.EntryItr
      Iterator that iterates over reachable entries in the map.
      (package private) static interface  MildValues.InverseMapping
      Represents an inverse mapping from a value to its key.
      private static class  MildValues.Soft<K,​V>
      Soft value with an MildValues.InverseMapping back to its key.
      (package private) class  MildValues.StrongEntry
      Map.Entry that delegates to the original entry, but maintains a strong reference to the value.
      (package private) class  MildValues.ValueItr
      Iterator that iterates over reachable values in the map.
      private static class  MildValues.Weak<K,​V>
      Weak value with an MildValues.InverseMapping back to its key.
      • 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
      (package private) java.util.Map<K,​java.lang.ref.Reference<V>> map  
      (package private) java.lang.ref.ReferenceQueue<V> queue  
      private boolean soft  
    • Constructor Summary

      Constructors 
      Constructor Description
      MildValues​(java.util.Map<K,​java.lang.ref.Reference<V>> map, boolean soft)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()  
      (package private) void compact()
      Compacts the map by removing cleared values.
      boolean containsKey​(java.lang.Object key)  
      boolean containsValue​(java.lang.Object value)  
      java.util.Set<java.util.Map.Entry<K,​V>> entrySet()  
      V get​(java.lang.Object key)  
      boolean isEmpty()  
      java.util.Set<K> keySet()  
      (package private) java.lang.ref.Reference<V> mildValue​(K key, V value)  
      V put​(K key, V value)  
      void putAll​(java.util.Map<? extends K,​? extends V> m)  
      V remove​(java.lang.Object key)  
      int size()  
      (package private) static <V> java.lang.ref.Reference<V> tempValue​(V value)  
      java.util.Collection<V> values()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.Map

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

      • queue

        final java.lang.ref.ReferenceQueue<V> queue
      • map

        final java.util.Map<K,​java.lang.ref.Reference<V>> map
      • soft

        private final boolean soft
    • Constructor Detail

      • MildValues

        MildValues​(java.util.Map<K,​java.lang.ref.Reference<V>> map,
                   boolean soft)
    • Method Detail

      • containsKey

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

        public final boolean containsValue​(java.lang.Object value)
        Specified by:
        containsValue in interface java.util.Map<K,​V>
      • get

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

        public final V put​(K key,
                           V value)
        Specified by:
        put in interface java.util.Map<K,​V>
      • putAll

        public final void putAll​(java.util.Map<? extends K,​? extends V> m)
        Specified by:
        putAll in interface java.util.Map<K,​V>
      • remove

        public final V remove​(java.lang.Object key)
        Specified by:
        remove in interface java.util.Map<K,​V>
      • clear

        public final void clear()
        Specified by:
        clear in interface java.util.Map<K,​V>
      • isEmpty

        public final boolean isEmpty()
        Specified by:
        isEmpty in interface java.util.Map<K,​V>
      • size

        public final int size()
        Specified by:
        size in interface java.util.Map<K,​V>
      • keySet

        public final java.util.Set<K> keySet()
        Specified by:
        keySet in interface java.util.Map<K,​V>
      • values

        public final java.util.Collection<V> values()
        Specified by:
        values in interface java.util.Map<K,​V>
      • entrySet

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

        final java.lang.ref.Reference<V> mildValue​(K key,
                                                   V value)
        Returns:
        Soft or weak Reference for the given key-value mapping.
      • tempValue

        static final <V> java.lang.ref.Reference<V> tempValue​(V value)
        Returns:
        Temporary Reference for the given value; used in queries.
      • compact

        void compact()
        Compacts the map by removing cleared values.