mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-11-22 16:23:50 +00:00
add check of emptiness in map reslozations of KV/KVs repos
This commit is contained in:
parent
c79c20033c
commit
89ce3c9f82
@ -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