Class LazyMap<K,V>
- java.lang.Object
-
- java.util.AbstractMap<K,V>
-
- com.atlassian.confluence.util.collections.LazyMap<K,V>
-
- Type Parameters:
K
- the key type.V
- the value type.
- All Implemented Interfaces:
Map<K,V>
@NotThreadSafe public class LazyMap<K,V> extends AbstractMap<K,V> implements Map<K,V>
AMap
that is backed by a delegate map that containssuppliers
for the values that are called lazily when required. The values returned from the delegate are cached so they are only retrieved once.The goal is to reduce the overhead required to instantiate and store entries which might not be used. For example, when rendering Velocity templates, the context map is populated with many things that are only ever required occasionally.
Note: even though this class is effectively immutable and does not support direct mutation, the caching strategy is not thread-safe and should not be used if thread-safety is required. Adding thread-safety to this class would be fairly trivial through.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object,V extends Object>
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description boolean
containsKey(Object key)
Set<Map.Entry<K,V>>
entrySet()
static <K,V>
LazyMap<K,V>fromSuppliersMap(Map<K,? extends Supplier<? extends V>> delegate)
V
get(Object key)
.boolean
isEmpty()
Set<K>
keySet()
static <K,V>
LazyMap<K,V>newInstance(Map<K,? extends com.google.common.base.Supplier<? extends V>> delegate)
Deprecated.since 7.0.1.V
remove(Object key)
int
size()
-
Methods inherited from class java.util.AbstractMap
clear, clone, containsValue, equals, hashCode, put, putAll, toString, values
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Map
clear, compute, computeIfAbsent, computeIfPresent, containsValue, equals, forEach, getOrDefault, hashCode, merge, put, putAll, putIfAbsent, remove, replace, replace, replaceAll, values
-
-
-
-
Method Detail
-
newInstance
@Deprecated public static <K,V> LazyMap<K,V> newInstance(Map<K,? extends com.google.common.base.Supplier<? extends V>> delegate)
Deprecated.since 7.0.1. UsefromSuppliersMap(Map)
-
fromSuppliersMap
public static <K,V> LazyMap<K,V> fromSuppliersMap(Map<K,? extends Supplier<? extends V>> delegate)
- Since:
- 7.0.1
-
containsKey
public boolean containsKey(Object key)
- Specified by:
containsKey
in interfaceMap<K,V>
- Overrides:
containsKey
in classAbstractMap<K,V>
-
size
public int size()
-
isEmpty
public boolean isEmpty()
-
-