If-Null return/break/... foldable to '?:'

This commit is contained in:
davotoula
2026-03-06 17:17:26 +01:00
parent 34e1ea92b2
commit c8c42b5d70
@@ -25,14 +25,13 @@ import java.lang.ref.WeakReference
import java.util.concurrent.ConcurrentSkipListMap
import java.util.function.BiConsumer
class LargeSoftCache<K, V> : CacheOperations<K, V> {
protected val cache = ConcurrentSkipListMap<K, WeakReference<V>>()
class LargeSoftCache<K : Any, V : Any> : CacheOperations<K, V> {
private val cache = ConcurrentSkipListMap<K, WeakReference<V>>()
fun keys() = cache.keys
fun get(key: K): V? {
val softRef = cache.get(key)
if (softRef == null) return null
val softRef = cache.get(key) ?: return null
val value = softRef.get()
return if (value != null) {
@@ -135,7 +134,7 @@ class LargeSoftCache<K, V> : CacheOperations<K, V> {
.forEach(BiConsumerWrapper(this, consumer))
}
class BiConsumerWrapper<K, V>(
class BiConsumerWrapper<K : Any, V : Any>(
val cache: LargeSoftCache<K, V>,
val inner: BiConsumer<K, V>,
) : BiConsumer<K, WeakReference<V>> {