If-Null return/break/... foldable to '?:'
This commit is contained in:
@@ -25,14 +25,13 @@ import java.lang.ref.WeakReference
|
|||||||
import java.util.concurrent.ConcurrentSkipListMap
|
import java.util.concurrent.ConcurrentSkipListMap
|
||||||
import java.util.function.BiConsumer
|
import java.util.function.BiConsumer
|
||||||
|
|
||||||
class LargeSoftCache<K, V> : CacheOperations<K, V> {
|
class LargeSoftCache<K : Any, V : Any> : CacheOperations<K, V> {
|
||||||
protected val cache = ConcurrentSkipListMap<K, WeakReference<V>>()
|
private val cache = ConcurrentSkipListMap<K, WeakReference<V>>()
|
||||||
|
|
||||||
fun keys() = cache.keys
|
fun keys() = cache.keys
|
||||||
|
|
||||||
fun get(key: K): V? {
|
fun get(key: K): V? {
|
||||||
val softRef = cache.get(key)
|
val softRef = cache.get(key) ?: return null
|
||||||
if (softRef == null) return null
|
|
||||||
val value = softRef.get()
|
val value = softRef.get()
|
||||||
|
|
||||||
return if (value != null) {
|
return if (value != null) {
|
||||||
@@ -135,7 +134,7 @@ class LargeSoftCache<K, V> : CacheOperations<K, V> {
|
|||||||
.forEach(BiConsumerWrapper(this, consumer))
|
.forEach(BiConsumerWrapper(this, consumer))
|
||||||
}
|
}
|
||||||
|
|
||||||
class BiConsumerWrapper<K, V>(
|
class BiConsumerWrapper<K : Any, V : Any>(
|
||||||
val cache: LargeSoftCache<K, V>,
|
val cache: LargeSoftCache<K, V>,
|
||||||
val inner: BiConsumer<K, V>,
|
val inner: BiConsumer<K, V>,
|
||||||
) : BiConsumer<K, WeakReference<V>> {
|
) : BiConsumer<K, WeakReference<V>> {
|
||||||
|
|||||||
Reference in New Issue
Block a user