diff --git a/repos/inmemory/src/commonMain/kotlin/dev/inmo/micro_utils/repos/MapCRUDRepo.kt b/repos/inmemory/src/commonMain/kotlin/dev/inmo/micro_utils/repos/MapCRUDRepo.kt index dd92ce2c028..c9aa60c63f4 100644 --- a/repos/inmemory/src/commonMain/kotlin/dev/inmo/micro_utils/repos/MapCRUDRepo.kt +++ b/repos/inmemory/src/commonMain/kotlin/dev/inmo/micro_utils/repos/MapCRUDRepo.kt @@ -6,6 +6,13 @@ import dev.inmo.micro_utils.coroutines.withWriteLock import dev.inmo.micro_utils.pagination.* import kotlinx.coroutines.flow.* +/** + * [Map]-based [ReadMapCRUDRepo]. All internal operations will be locked with [locker] (mostly with + * [SmartRWLocker.withReadAcquire]) + * + * **Warning**: It is not recommended to use constructor with both [Map] and [SmartRWLocker]. Besides, in case + * you are using your own [Map] as a [map] you should be careful with operations on this [map] + */ class ReadMapCRUDRepo( private val map: Map = emptyMap(), private val locker: SmartRWLocker = SmartRWLocker() @@ -47,6 +54,13 @@ class ReadMapCRUDRepo( } } +/** + * [MutableMap]-based [WriteMapCRUDRepo]. All internal operations will be locked with [locker] (mostly with + * [SmartRWLocker.withWriteLock]) + * + * **Warning**: It is not recommended to use constructor with both [MutableMap] and [SmartRWLocker]. Besides, in case + * you are using your own [MutableMap] as a [map] you should be careful with operations on this [map] + */ abstract class WriteMapCRUDRepo( protected val map: MutableMap = mutableMapOf(), protected val locker: SmartRWLocker = SmartRWLocker() @@ -98,6 +112,12 @@ abstract class WriteMapCRUDRepo( } +/** + * [MutableMap]-based [MapCRUDRepo]. All internal operations will be locked with [locker] + * + * **Warning**: It is not recommended to use constructor with both [MutableMap] and [SmartRWLocker]. Besides, in case + * you are using your own [MutableMap] as a [map] you should be careful with operations on this [map] + */ abstract class MapCRUDRepo( map: MutableMap, locker: SmartRWLocker = SmartRWLocker() @@ -105,6 +125,12 @@ abstract class MapCRUDRepo( ReadCRUDRepo by ReadMapCRUDRepo(map, locker), WriteMapCRUDRepo(map, locker) +/** + * [MutableMap]-based [MapCRUDRepo]. All internal operations will be locked with [locker] + * + * **Warning**: Besides, in case you are using your own [MutableMap] as a [map] you should be careful with operations + * on this [map] + */ fun MapCRUDRepo( map: MutableMap, updateCallback: suspend MutableMap.(newValue: InputValueType, id: IdType, old: ObjectType) -> ObjectType, @@ -120,12 +146,21 @@ fun MapCRUDRepo( override suspend fun createObject(newValue: InputValueType): Pair = map.createCallback(newValue) } +/** + * [MutableMap]-based [MapCRUDRepo]. All internal operations will be locked with [locker] + */ fun MapCRUDRepo( updateCallback: suspend MutableMap.(newValue: InputValueType, id: IdType, old: ObjectType) -> ObjectType, locker: SmartRWLocker = SmartRWLocker(), createCallback: suspend MutableMap.(newValue: InputValueType) -> Pair ) = MapCRUDRepo(mutableMapOf(), updateCallback, locker, createCallback) +/** + * [MutableMap]-based [MapCRUDRepo]. All internal operations will be locked with [locker] + * + * **Warning**: Besides, in case you are using your own [MutableMap] as a [this] you should be careful with operations + * on this [this] + */ fun MutableMap.asCrudRepo( updateCallback: suspend MutableMap.(newValue: InputValueType, id: IdType, old: ObjectType) -> ObjectType, locker: SmartRWLocker = SmartRWLocker(), diff --git a/repos/inmemory/src/commonMain/kotlin/dev/inmo/micro_utils/repos/MapKeyValueRepo.kt b/repos/inmemory/src/commonMain/kotlin/dev/inmo/micro_utils/repos/MapKeyValueRepo.kt index 1d5c5599572..71ccd98c865 100644 --- a/repos/inmemory/src/commonMain/kotlin/dev/inmo/micro_utils/repos/MapKeyValueRepo.kt +++ b/repos/inmemory/src/commonMain/kotlin/dev/inmo/micro_utils/repos/MapKeyValueRepo.kt @@ -10,6 +10,13 @@ import dev.inmo.micro_utils.pagination.utils.reverse import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableSharedFlow +/** + * [Map]-based [ReadKeyValueRepo]. All internal operations will be locked with [locker] (mostly with + * [SmartRWLocker.withReadAcquire]) + * + * **Warning**: It is not recommended to use constructor with both [Map] and [SmartRWLocker]. Besides, in case you are + * using your own [Map] as a [map] you should be careful with operations on this [map] + */ class ReadMapKeyValueRepo( protected val map: Map, private val locker: SmartRWLocker @@ -70,6 +77,13 @@ class ReadMapKeyValueRepo( override suspend fun count(): Long = locker.withReadAcquire { map.size.toLong() } } +/** + * [MutableMap]-based [WriteKeyValueRepo]. All internal operations will be locked with [locker] (mostly with + * [SmartRWLocker.withWriteLock]) + * + * **Warning**: It is not recommended to use constructor with both [MutableMap] and [SmartRWLocker]. Besides, in case + * you are using your own [MutableMap] as a [map] you should be careful with operations on this [map] + */ class WriteMapKeyValueRepo( private val map: MutableMap, private val locker: SmartRWLocker @@ -107,6 +121,12 @@ class WriteMapKeyValueRepo( } } +/** + * [MutableMap]-based [KeyValueRepo]. All internal operations will be locked with [locker] + * + * **Warning**: It is not recommended to use constructor with both [MutableMap] and [SmartRWLocker]. Besides, in case + * you are using your own [MutableMap] as a [map] you should be careful with operations on this [map] + */ @Suppress("DELEGATED_MEMBER_HIDES_SUPERTYPE_OVERRIDE") class MapKeyValueRepo( private val map: MutableMap, @@ -120,4 +140,10 @@ class MapKeyValueRepo( } } +/** + * [MutableMap]-based [KeyValueRepo]. All internal operations will be locked with [locker] + * + * **Warning**: It is not recommended to use constructor with both [MutableMap] and [SmartRWLocker]. Besides, in case + * you are using your own [MutableMap] as a [this] you should be careful with operations on this [this] + */ fun MutableMap.asKeyValueRepo(locker: SmartRWLocker = SmartRWLocker()): KeyValueRepo = MapKeyValueRepo(this, locker) diff --git a/repos/inmemory/src/commonMain/kotlin/dev/inmo/micro_utils/repos/MapKeyValuesRepo.kt b/repos/inmemory/src/commonMain/kotlin/dev/inmo/micro_utils/repos/MapKeyValuesRepo.kt index 2d35f352b65..c1c61edcc79 100644 --- a/repos/inmemory/src/commonMain/kotlin/dev/inmo/micro_utils/repos/MapKeyValuesRepo.kt +++ b/repos/inmemory/src/commonMain/kotlin/dev/inmo/micro_utils/repos/MapKeyValuesRepo.kt @@ -8,6 +8,13 @@ import dev.inmo.micro_utils.pagination.utils.paginate import dev.inmo.micro_utils.pagination.utils.reverse import kotlinx.coroutines.flow.* +/** + * [Map]-based [ReadKeyValuesRepo]. All internal operations will be locked with [locker] (mostly with + * [SmartRWLocker.withReadAcquire]) + * + * **Warning**: It is not recommended to use constructor with both [Map] and [SmartRWLocker]. Besides, in case + * you are using your own [Map] as a [map] you should be careful with operations on this [map] + */ class MapReadKeyValuesRepo( private val map: Map> = emptyMap(), private val locker: SmartRWLocker = SmartRWLocker() @@ -63,6 +70,13 @@ class MapReadKeyValuesRepo( override suspend fun count(): Long = locker.withReadAcquire { map.size }.toLong() } +/** + * [MutableMap]-based [WriteKeyValuesRepo]. All internal operations will be locked with [locker] (mostly with + * [SmartRWLocker.withWriteLock]) + * + * **Warning**: It is not recommended to use constructor with both [MutableMap] and [SmartRWLocker]. Besides, in case + * you are using your own [MutableMap] as a [map] you should be careful with operations on this [map] + */ class MapWriteKeyValuesRepo( private val map: MutableMap> = mutableMapOf(), private val locker: SmartRWLocker = SmartRWLocker() @@ -133,6 +147,12 @@ class MapWriteKeyValuesRepo( } } +/** + * [MutableMap]-based [KeyValuesRepo]. All internal operations will be locked with [locker] + * + * **Warning**: It is not recommended to use constructor with both [MutableMap] and [SmartRWLocker]. Besides, in case + * you are using your own [MutableMap] as a [map] you should be careful with operations on this [map] + */ @Suppress("DELEGATED_MEMBER_HIDES_SUPERTYPE_OVERRIDE") class MapKeyValuesRepo( private val map: MutableMap> = mutableMapOf(), @@ -141,6 +161,11 @@ class MapKeyValuesRepo( ReadKeyValuesRepo by MapReadKeyValuesRepo(map, locker), WriteKeyValuesRepo by MapWriteKeyValuesRepo(map, locker) +/** + * [MutableMap]-based [KeyValuesRepo]. All internal operations will be locked with [locker] + * + * **Warning**: In case you are using your own [MutableMap] as [this] receiver you should be careful with operations on [this] map + */ fun MutableMap>.asKeyValuesRepo(locker: SmartRWLocker = SmartRWLocker()): KeyValuesRepo = MapKeyValuesRepo( map { (k, v) -> k to v.toMutableList() }.toMap().toMutableMap(), locker