-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Данила Беляков
authored and
Данила Беляков
committed
Nov 14, 2024
1 parent
2e2cb34
commit d86f387
Showing
30 changed files
with
667 additions
and
204 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 2 additions & 44 deletions
46
alice-ktx/src/main/kotlin/com/github/alice/ktx/state/FSMContext.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,10 @@ | ||
package com.github.alice.ktx.state | ||
|
||
import kotlin.reflect.KClass | ||
|
||
/** | ||
* Интерфейс для доступа к информации состояния конкретного пользователя. | ||
* Создаётся и передаётся в обработчики при каждом событии. | ||
* */ | ||
interface FSMContext: ReadOnlyFSMContext { | ||
|
||
/** | ||
* Установить состояние по ключу. | ||
* */ | ||
fun setState(key: String) | ||
|
||
/** | ||
* Записать данные (перезапись) с произвольным типом. | ||
* */ | ||
fun <V: Any> setTypedData(vararg pairs: Pair<String, V>, clazz: KClass<V>) | ||
|
||
/** | ||
* Записать данные (перезапись). | ||
* */ | ||
fun setData(vararg pairs: Pair<String, String>) | ||
|
||
/** | ||
* Обновление данных в хранилище по ключу с произвольным типом. | ||
* @return Обновленные данные. | ||
* */ | ||
fun <V: Any> updateTypedData(vararg pairs: Pair<String, V>, clazz: KClass<V>): Map<String, String> | ||
|
||
/** | ||
* Обновление данные в хранилище по ключу. | ||
* @return Обновленные данные. | ||
* */ | ||
fun updateData(vararg pairs: Pair<String, String>): Map<String, String> | ||
|
||
/** | ||
* Удалить данные по ключу. | ||
* */ | ||
fun removeData(key: String): String? | ||
|
||
/** | ||
* Удалить данные по ключу с произвольным типом. | ||
* */ | ||
fun <V: Any> removeTypedData(key: String, clazz: KClass<V>): V? | ||
interface FSMContext: MutableFSMContext { | ||
|
||
/** | ||
* Очистить состояние и данные. | ||
* */ | ||
fun clear() | ||
suspend fun init() | ||
} |
48 changes: 48 additions & 0 deletions
48
alice-ktx/src/main/kotlin/com/github/alice/ktx/state/MutableFSMContext.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.github.alice.ktx.state | ||
|
||
import kotlin.reflect.KClass | ||
|
||
interface MutableFSMContext : ReadOnlyFSMContext { | ||
|
||
/** | ||
* Установить состояние по ключу. | ||
* */ | ||
suspend fun setState(key: String) | ||
|
||
/** | ||
* Записать данные (перезапись) с произвольным типом. | ||
* */ | ||
suspend fun <V: Any> setTypedData(vararg pairs: Pair<String, V>, clazz: KClass<V>) | ||
|
||
/** | ||
* Записать данные (перезапись). | ||
* */ | ||
suspend fun setData(vararg pairs: Pair<String, String>) | ||
|
||
/** | ||
* Обновление данных в хранилище по ключу с произвольным типом. | ||
* @return Обновленные данные. | ||
* */ | ||
suspend fun <V: Any> updateTypedData(vararg pairs: Pair<String, V>, clazz: KClass<V>): Map<String, String> | ||
|
||
/** | ||
* Обновление данные в хранилище по ключу. | ||
* @return Обновленные данные. | ||
* */ | ||
suspend fun updateData(vararg pairs: Pair<String, String>): Map<String, String> | ||
|
||
/** | ||
* Удалить данные по ключу. | ||
* */ | ||
suspend fun removeData(key: String): String? | ||
|
||
/** | ||
* Удалить данные по ключу с произвольным типом. | ||
* */ | ||
suspend fun <V: Any> removeTypedData(key: String, clazz: KClass<V>): V? | ||
|
||
/** | ||
* Очистить состояние и данные. | ||
* */ | ||
suspend fun clear() | ||
} |
14 changes: 4 additions & 10 deletions
14
alice-ktx/src/main/kotlin/com/github/alice/ktx/state/ReadOnlyFSMContext.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,26 @@ | ||
package com.github.alice.ktx.state | ||
|
||
import com.github.alice.ktx.models.FSMStrategy | ||
import kotlin.reflect.KClass | ||
|
||
interface ReadOnlyFSMContext { | ||
|
||
/** | ||
* Получить стратегию FSM. | ||
* */ | ||
fun getStrategy(): FSMStrategy | ||
|
||
/** | ||
* Получить текущее состояние. | ||
* */ | ||
fun getState(): String? | ||
suspend fun getState(): String? | ||
|
||
/** | ||
* Получить все данные. | ||
* */ | ||
fun getData(): Map<String, String> | ||
suspend fun getData(): Map<String, String> | ||
|
||
/** | ||
* Получить данные по ключу с произвольным типом. | ||
* */ | ||
fun <V: Any> getTypedData(key: String, clazz: KClass<V>): V? | ||
suspend fun <V: Any> getTypedData(key: String, clazz: KClass<V>): V? | ||
|
||
/** | ||
* Получить данные по ключу. | ||
* */ | ||
fun getData(key: String): String? | ||
suspend fun getData(key: String): String? | ||
} |
Oops, something went wrong.