Class MapIteratorCache<K,​V>

  • Direct Known Subclasses:
    MapRetrievalCache

    class MapIteratorCache<K,​V>
    extends java.lang.Object
    A map-like data structure that wraps a backing map and caches values while iterating through unmodifiableKeySet(). By design, the cache is cleared when this structure is mutated. If this structure is never mutated, it provides a thread-safe view of the backing map.

    The MapIteratorCache assumes ownership of the backing map, and cannot guarantee correctness in the face of external mutations to the backing map. As such, it is strongly recommended that the caller does not persist a reference to the backing map (unless the backing map is immutable).

    This class is tailored toward use cases in common.graph. It is *NOT* a general purpose map.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.Map<K,​V> backingMap  
      private java.util.Map.Entry<K,​V> cacheEntry  
    • Constructor Summary

      Constructors 
      Constructor Description
      MapIteratorCache​(java.util.Map<K,​V> backingMap)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) void clear()  
      (package private) void clearCache()  
      (package private) boolean containsKey​(java.lang.Object key)  
      (package private) V get​(java.lang.Object key)  
      (package private) V getIfCached​(java.lang.Object key)  
      (package private) V getWithoutCaching​(java.lang.Object key)  
      (package private) V put​(K key, V value)  
      (package private) V remove​(java.lang.Object key)  
      (package private) java.util.Set<K> unmodifiableKeySet()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • backingMap

        private final java.util.Map<K,​V> backingMap
      • cacheEntry

        @CheckForNull
        private transient volatile java.util.Map.Entry<K,​V> cacheEntry
    • Constructor Detail

      • MapIteratorCache

        MapIteratorCache​(java.util.Map<K,​V> backingMap)
    • Method Detail

      • put

        @CheckForNull
        final V put​(K key,
                    V value)
      • remove

        @CheckForNull
        final V remove​(java.lang.Object key)
      • clear

        final void clear()
      • get

        @CheckForNull
        V get​(java.lang.Object key)
      • getWithoutCaching

        @CheckForNull
        final V getWithoutCaching​(java.lang.Object key)
      • containsKey

        final boolean containsKey​(@CheckForNull
                                  java.lang.Object key)
      • unmodifiableKeySet

        final java.util.Set<K> unmodifiableKeySet()
      • getIfCached

        @CheckForNull
        V getIfCached​(@CheckForNull
                      java.lang.Object key)
      • clearCache

        void clearCache()