K
- the key type.V
- the value type.@NotThreadSafe public class LazyMap<K,V> extends AbstractMap<K,V> implements Map<K,V>
Map
that is backed by a delegate map that contains suppliers
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.
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
Modifier and Type | Method and Description |
---|---|
boolean |
containsKey(Object key) |
Set<Map.Entry<K,V>> |
entrySet() |
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) |
V |
remove(Object key) |
int |
size() |
clear, clone, containsValue, equals, hashCode, put, putAll, toString, values
finalize, getClass, notify, notifyAll, wait, wait, wait
clear, compute, computeIfAbsent, computeIfPresent, containsValue, equals, forEach, getOrDefault, hashCode, merge, put, putAll, putIfAbsent, remove, replace, replace, replaceAll, values
public static <K,V> LazyMap<K,V> newInstance(Map<K,? extends com.google.common.base.Supplier<? extends V>> delegate)
public boolean containsKey(Object key)
containsKey
in interface Map<K,V>
containsKey
in class AbstractMap<K,V>
public int size()
public boolean isEmpty()
Copyright © 2003–2017 Atlassian. All rights reserved.