Address JDK8/JDK6 issues with computeIfAbsent

This commit is contained in:
Irene Dea
2021-12-01 14:09:54 -08:00
committed by Dmitriy Novozhilov
parent 374d287d08
commit 3c4989b672
8 changed files with 45 additions and 6 deletions
@@ -78,9 +78,14 @@ abstract class TypeRegistry<K : Any, V : Any> {
}
fun <T : K> getId(kClass: KClass<T>): Int {
return idPerType.computeIfAbsent(kClass) { idCounter.getAndIncrement() }
return idPerType.customComputeIfAbsent(kClass) { idCounter.getAndIncrement() }
}
abstract fun <T : K> ConcurrentHashMap<KClass<out K>, Int>.customComputeIfAbsent(
kClass: KClass<T>,
compute: (KClass<out K>) -> Int
): Int
fun allValuesThreadUnsafeForRendering(): Map<KClass<out K>, Int> {
return idPerType
}