Package com.google.common.graph
Class MapIteratorCache<K,V>
- java.lang.Object
-
- com.google.common.graph.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 throughunmodifiableKeySet()
. 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>
entrySetCache
-
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 void
clear()
protected void
clearCache()
boolean
containsKey(java.lang.Object key)
V
get(java.lang.Object key)
protected V
getIfCached(java.lang.Object key)
V
getWithoutCaching(java.lang.Object key)
V
put(K key, V value)
V
remove(java.lang.Object key)
java.util.Set<K>
unmodifiableKeySet()
-
-
-
Method Detail
-
remove
public V remove(@Nullable java.lang.Object key)
-
clear
public void clear()
-
get
public V get(@Nullable java.lang.Object key)
-
getWithoutCaching
public final V getWithoutCaching(@Nullable java.lang.Object key)
-
containsKey
public final boolean containsKey(@Nullable java.lang.Object key)
-
unmodifiableKeySet
public final java.util.Set<K> unmodifiableKeySet()
-
getIfCached
protected V getIfCached(@Nullable java.lang.Object key)
-
clearCache
protected void clearCache()
-
-