Class LazyLoadingMap<K,T>
java.lang.Object
java.util.AbstractMap<K,V>
java.util.HashMap<K,T>
org.apache.sling.graphql.helpers.lazyloading.LazyLoadingMap<K,T>
- All Implemented Interfaces:
Serializable,Cloneable,Map<K,T>
A
HashMap that optionally uses Suppliers to provide its
values. Each Supplier is called at most once, if the corresponding
value is requested. Some "global" operations requires all values
to be computed, and should be considered costly.
Like HashMap, this class is NOT thread safe. If needed,
Collections.synchronizedMap(java.util.Map<K, V>) can be used
to synchronize it.
Note that remove(java.lang.Object) behaves slightly differently than
the HashMap version.- See Also:
-
Nested Class Summary
Nested ClassesNested 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 TypeMethodDescriptionvoidclear()computeAllThrowsException(boolean b) Optionally throw a RuntimeException if computeAll is calledcomputeValueOnRemove(boolean b) Optionally compute the value on remove, so that it doesn't return nullbooleancontainsKey(Object key) booleancontainsValue(Object value) Calls computeAll - should be avoided if possibleentrySet()Calls computeAll - should be avoided if possiblebooleanCalls computeAll - should be avoided if possiblegetStats()Return statistics on our suppliers, for metrics etc.inthashCode()booleanisEmpty()keySet()Adds a Supplier that provides a lazy loaded value.UnlesscomputeValueOnRemove(boolean)is set to true, this returns null to avoid calling a supplier "for nothing".intsize()values()Calls computeAll - should be avoided if possibleMethods inherited from class java.util.HashMap
clone, compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, put, putAll, putIfAbsent, remove, replace, replace, replaceAllMethods inherited from class java.util.AbstractMap
toString
-
Constructor Details
-
LazyLoadingMap
public LazyLoadingMap()
-
-
Method Details
-
equals
Calls computeAll - should be avoided if possible -
hashCode
public int hashCode() -
put
Adds a Supplier that provides a lazy loaded value. Removes existing value with the same key if it exists. -
get
-
remove
UnlesscomputeValueOnRemove(boolean)is set to true, this returns null to avoid calling a supplier "for nothing". -
clear
public void clear() -
containsKey
- Specified by:
containsKeyin interfaceMap<K,T> - Overrides:
containsKeyin classHashMap<K,T>
-
size
public int size() -
isEmpty
public boolean isEmpty() -
keySet
-
values
Calls computeAll - should be avoided if possible -
entrySet
Calls computeAll - should be avoided if possible -
containsValue
Calls computeAll - should be avoided if possible- Specified by:
containsValuein interfaceMap<K,T> - Overrides:
containsValuein classHashMap<K,T>
-
getStats
Return statistics on our suppliers, for metrics etc. -
computeValueOnRemove
Optionally compute the value on remove, so that it doesn't return null -
computeAllThrowsException
Optionally throw a RuntimeException if computeAll is called
-