-
- All Implemented Interfaces:
public class CollectionInitializerQuite often many lambda objects are generated during frequent calls like getOrPut:
class MyClass { private val cache = mutableMapOf<String, Stack<MyData>>() fun service(key: String) { cache.getOrPut(key) { Stack<MyData>() } } }That way it's more effective pre-defining initializers and use them like below - by doing that we avoie unnecessary lambda objects construction:
cache.getOrPut(key, CollectionInitializer.stack())
-
-
Field Summary
Fields Modifier and Type Field Description public final static CollectionInitializerINSTANCE
-
Method Summary
Modifier and Type Method Description final <T extends Any> Function0<Stack<T>>stack()final <T extends Any> Function0<List<T>>mutableList()final <T extends Any> Function0<Set<T>>mutableSet()final <K extends Any, V extends Any> Function0<Map<K, V>>mutableMap()final <T extends Any> Function0<Set<T>>concurrentHashSet()final <K extends Any, V extends Any> Function0<ConcurrentHashMap<K, V>>concurrentHashMap()final <K extends Any, V extends Any> Function0<ConcurrentHashMap<K, V>>copyOnWriteArrayList()-
-
Method Detail
-
mutableList
final <T extends Any> Function0<List<T>> mutableList()
-
mutableSet
final <T extends Any> Function0<Set<T>> mutableSet()
-
concurrentHashSet
final <T extends Any> Function0<Set<T>> concurrentHashSet()
-
concurrentHashMap
final <K extends Any, V extends Any> Function0<ConcurrentHashMap<K, V>> concurrentHashMap()
-
copyOnWriteArrayList
final <K extends Any, V extends Any> Function0<ConcurrentHashMap<K, V>> copyOnWriteArrayList()
-
-
-
-