mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-12-23 09:07:14 +00:00
add small kdoc for map repos
This commit is contained in:
parent
8a61193500
commit
5b070a8478
@ -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<ObjectType, IdType>(
|
||||
private val map: Map<IdType, ObjectType> = emptyMap(),
|
||||
private val locker: SmartRWLocker = SmartRWLocker()
|
||||
@ -47,6 +54,13 @@ class ReadMapCRUDRepo<ObjectType, IdType>(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [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<ObjectType, IdType, InputValueType>(
|
||||
protected val map: MutableMap<IdType, ObjectType> = mutableMapOf(),
|
||||
protected val locker: SmartRWLocker = SmartRWLocker()
|
||||
@ -98,6 +112,12 @@ abstract class WriteMapCRUDRepo<ObjectType, IdType, InputValueType>(
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* [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<ObjectType, IdType, InputValueType>(
|
||||
map: MutableMap<IdType, ObjectType>,
|
||||
locker: SmartRWLocker = SmartRWLocker()
|
||||
@ -105,6 +125,12 @@ abstract class MapCRUDRepo<ObjectType, IdType, InputValueType>(
|
||||
ReadCRUDRepo<ObjectType, IdType> by ReadMapCRUDRepo(map, locker),
|
||||
WriteMapCRUDRepo<ObjectType, IdType, InputValueType>(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 <ObjectType, IdType, InputValueType> MapCRUDRepo(
|
||||
map: MutableMap<IdType, ObjectType>,
|
||||
updateCallback: suspend MutableMap<IdType, ObjectType>.(newValue: InputValueType, id: IdType, old: ObjectType) -> ObjectType,
|
||||
@ -120,12 +146,21 @@ fun <ObjectType, IdType, InputValueType> MapCRUDRepo(
|
||||
override suspend fun createObject(newValue: InputValueType): Pair<IdType, ObjectType> = map.createCallback(newValue)
|
||||
}
|
||||
|
||||
/**
|
||||
* [MutableMap]-based [MapCRUDRepo]. All internal operations will be locked with [locker]
|
||||
*/
|
||||
fun <ObjectType, IdType, InputValueType> MapCRUDRepo(
|
||||
updateCallback: suspend MutableMap<IdType, ObjectType>.(newValue: InputValueType, id: IdType, old: ObjectType) -> ObjectType,
|
||||
locker: SmartRWLocker = SmartRWLocker(),
|
||||
createCallback: suspend MutableMap<IdType, ObjectType>.(newValue: InputValueType) -> Pair<IdType, ObjectType>
|
||||
) = 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 <ObjectType, IdType, InputValueType> MutableMap<IdType, ObjectType>.asCrudRepo(
|
||||
updateCallback: suspend MutableMap<IdType, ObjectType>.(newValue: InputValueType, id: IdType, old: ObjectType) -> ObjectType,
|
||||
locker: SmartRWLocker = SmartRWLocker(),
|
||||
|
@ -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<Key, Value>(
|
||||
protected val map: Map<Key, Value>,
|
||||
private val locker: SmartRWLocker
|
||||
@ -70,6 +77,13 @@ class ReadMapKeyValueRepo<Key, Value>(
|
||||
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<Key, Value>(
|
||||
private val map: MutableMap<Key, Value>,
|
||||
private val locker: SmartRWLocker
|
||||
@ -107,6 +121,12 @@ class WriteMapKeyValueRepo<Key, Value>(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [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<Key, Value>(
|
||||
private val map: MutableMap<Key, Value>,
|
||||
@ -120,4 +140,10 @@ class MapKeyValueRepo<Key, Value>(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [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 <K, V> MutableMap<K, V>.asKeyValueRepo(locker: SmartRWLocker = SmartRWLocker()): KeyValueRepo<K, V> = MapKeyValueRepo(this, locker)
|
||||
|
@ -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<Key, Value>(
|
||||
private val map: Map<Key, List<Value>> = emptyMap(),
|
||||
private val locker: SmartRWLocker = SmartRWLocker()
|
||||
@ -63,6 +70,13 @@ class MapReadKeyValuesRepo<Key, Value>(
|
||||
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<Key, Value>(
|
||||
private val map: MutableMap<Key, MutableList<Value>> = mutableMapOf(),
|
||||
private val locker: SmartRWLocker = SmartRWLocker()
|
||||
@ -133,6 +147,12 @@ class MapWriteKeyValuesRepo<Key, Value>(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [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<Key, Value>(
|
||||
private val map: MutableMap<Key, MutableList<Value>> = mutableMapOf(),
|
||||
@ -141,6 +161,11 @@ class MapKeyValuesRepo<Key, Value>(
|
||||
ReadKeyValuesRepo<Key, Value> by MapReadKeyValuesRepo(map, locker),
|
||||
WriteKeyValuesRepo<Key, Value> 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 <K, V> MutableMap<K, List<V>>.asKeyValuesRepo(locker: SmartRWLocker = SmartRWLocker()): KeyValuesRepo<K, V> = MapKeyValuesRepo(
|
||||
map { (k, v) -> k to v.toMutableList() }.toMap().toMutableMap(),
|
||||
locker
|
||||
|
Loading…
Reference in New Issue
Block a user