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>
A
Map
that is constructed from a map of suppliers
for the values, that are evaluated lazily
when required. The values returned from the suppliers 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.
Use copyOf(com.atlassian.confluence.util.collections.LazyMap<K, V>)
, putAll(LazyMap)
and putAllIfAbsent(com.atlassian.confluence.util.collections.LazyMap<K, V>)
when copying or merging LazyMap
instances. These methods guarantee that the suppliers will not be invoked unnecessarily and never more than once,
even when copied to a new map.
This class 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.
- Since:
- 3.4
-
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> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
containsKey
(Object key) static <K,
V> LazyMap<K, V> entrySet()
static <K,
V> LazyMap<K, V> fromSuppliersMap
(Map<K, ? extends Supplier<? extends V>> supplierMap) As at 9.1.1, the returned map is no longer directly backed by the given map.boolean
isEmpty()
keySet()
void
static <K,
V> LazyMap<K, V> newInstance
(Map<K, ? extends com.google.common.base.Supplier<? extends V>> supplierMap) Deprecated, for removal: This API element is subject to removal in a future version.since 7.0.1.void
void
void
putAllIfAbsent
(LazyMap<K, V> other) int
size()
Methods inherited from class java.util.AbstractMap
clear, clone, containsValue, equals, hashCode, toString, values
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Constructor Details
-
LazyMap
public LazyMap()- Since:
- 9.1.1
-
-
Method Details
-
newInstance
@Deprecated(forRemoval=true) public static <K,V> LazyMap<K,V> newInstance(Map<K, ? extends com.google.common.base.Supplier<? extends V>> supplierMap) Deprecated, for removal: This API element is subject to removal in a future version.since 7.0.1. UsefromSuppliersMap(Map)
-
fromSuppliersMap
public static <K,V> LazyMap<K,V> fromSuppliersMap(Map<K, ? extends Supplier<? extends V>> supplierMap) As at 9.1.1, the returned map is no longer directly backed by the given map. UselazyPut(K, java.util.function.Supplier<? extends V>)
,remove(java.lang.Object)
and/or other applicable methods to modify the map.- Since:
- 7.0.1
-
copyOf
- Since:
- 9.1.1
-
get
-
lazyPut
- Since:
- 9.1.1
-
put
-
putAll
-
putAll
- Since:
- 9.1.1
-
putAllIfAbsent
- Since:
- 9.1.1
-
keySet
-
containsKey
- Specified by:
containsKey
in interfaceMap<K,
V> - Overrides:
containsKey
in classAbstractMap<K,
V>
-
entrySet
-
size
public int size() -
isEmpty
public boolean isEmpty() -
remove
-