mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-11-08 09:23:50 +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())
|
||||
|
||||
override suspend fun set(toSet: Map<Key, Value>) {
|
||||
if (toSet.isEmpty()) return
|
||||
locker.withWriteLock { map.putAll(toSet) }
|
||||
toSet.forEach { (k, v) -> _onNewValue.emit(k to v) }
|
||||
}
|
||||
|
||||
override suspend fun unset(toUnset: List<Key>) {
|
||||
if (toUnset.isEmpty()) return
|
||||
locker.withWriteLock {
|
||||
toUnset.mapNotNull { k ->
|
||||
map.remove(k) ?.let { _ -> k }
|
||||
|
@ -124,6 +124,8 @@ class MapWriteKeyValuesRepo<Key, Value>(
|
||||
}
|
||||
|
||||
override suspend fun set(toSet: Map<Key, List<Value>>) {
|
||||
if (toSet.isEmpty()) return
|
||||
|
||||
locker.withWriteLock {
|
||||
map.putAll(
|
||||
toSet.mapValues { it.value.toMutableList() }
|
||||
@ -137,6 +139,8 @@ class MapWriteKeyValuesRepo<Key, Value>(
|
||||
}
|
||||
|
||||
override suspend fun remove(toRemove: Map<Key, List<Value>>) {
|
||||
if (toRemove.isEmpty()) return
|
||||
|
||||
val removed = mutableListOf<Pair<Key, Value>>()
|
||||
val cleared = mutableListOf<Key>()
|
||||
locker.withWriteLock {
|
||||
|
Loading…
Reference in New Issue
Block a user