Class MapIteratorCache<K,V>

java.lang.Object
com.google.common.graph.MapIteratorCache<K,V>
Direct Known Subclasses:
MapRetrievalCache

class MapIteratorCache<K,V> extends 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 Details

    • backingMap

      private final Map<K,V> backingMap
    • cacheEntry

      @CheckForNull private transient volatile Map.Entry<K,V> cacheEntry
  • Constructor Details

    • MapIteratorCache

      MapIteratorCache(Map<K,V> backingMap)
  • Method Details

    • put

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

      @CheckForNull final V remove(Object key)
    • clear

      final void clear()
    • get

      @CheckForNull V get(Object key)
    • getWithoutCaching

      @CheckForNull final V getWithoutCaching(Object key)
    • containsKey

      final boolean containsKey(@CheckForNull Object key)
    • unmodifiableKeySet

      final Set<K> unmodifiableKeySet()
    • getIfCached

      @CheckForNull V getIfCached(@CheckForNull Object key)
    • clearCache

      void clearCache()