mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-11-26 03:58:45 +00:00
add check of emptiness in map reslozations of KV/KVs repos
This commit is contained in:
parent
bf293a8f8f
commit
9f2f0de0c4
@ -102,11 +102,13 @@ class WriteMapKeyValueRepo<Key, Value>(
|
|||||||
constructor(map: MutableMap<Key, Value> = mutableMapOf()) : this(map, SmartRWLocker())
|
constructor(map: MutableMap<Key, Value> = mutableMapOf()) : this(map, SmartRWLocker())
|
||||||
|
|
||||||
override suspend fun set(toSet: Map<Key, Value>) {
|
override suspend fun set(toSet: Map<Key, Value>) {
|
||||||
|
if (toSet.isEmpty()) return
|
||||||
locker.withWriteLock { map.putAll(toSet) }
|
locker.withWriteLock { map.putAll(toSet) }
|
||||||
toSet.forEach { (k, v) -> _onNewValue.emit(k to v) }
|
toSet.forEach { (k, v) -> _onNewValue.emit(k to v) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun unset(toUnset: List<Key>) {
|
override suspend fun unset(toUnset: List<Key>) {
|
||||||
|
if (toUnset.isEmpty()) return
|
||||||
locker.withWriteLock {
|
locker.withWriteLock {
|
||||||
toUnset.mapNotNull { k ->
|
toUnset.mapNotNull { k ->
|
||||||
map.remove(k) ?.let { _ -> k }
|
map.remove(k) ?.let { _ -> k }
|
||||||
|
@ -124,6 +124,8 @@ class MapWriteKeyValuesRepo<Key, Value>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun set(toSet: Map<Key, List<Value>>) {
|
override suspend fun set(toSet: Map<Key, List<Value>>) {
|
||||||
|
if (toSet.isEmpty()) return
|
||||||
|
|
||||||
locker.withWriteLock {
|
locker.withWriteLock {
|
||||||
map.putAll(
|
map.putAll(
|
||||||
toSet.mapValues { it.value.toMutableList() }
|
toSet.mapValues { it.value.toMutableList() }
|
||||||
@ -137,6 +139,8 @@ class MapWriteKeyValuesRepo<Key, Value>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun remove(toRemove: Map<Key, List<Value>>) {
|
override suspend fun remove(toRemove: Map<Key, List<Value>>) {
|
||||||
|
if (toRemove.isEmpty()) return
|
||||||
|
|
||||||
val removed = mutableListOf<Pair<Key, Value>>()
|
val removed = mutableListOf<Pair<Key, Value>>()
|
||||||
val cleared = mutableListOf<Key>()
|
val cleared = mutableListOf<Key>()
|
||||||
locker.withWriteLock {
|
locker.withWriteLock {
|
||||||
|
Loading…
Reference in New Issue
Block a user