mirror of
https://github.com/InsanusMokrassar/PsychomatrixBase.git
synced 2024-11-14 20:33:57 +00:00
change of modification
This commit is contained in:
parent
c2a4f76130
commit
4a84f602a9
@ -13,11 +13,11 @@ interface ModifyPsychomatrixUseCase {
|
||||
|
||||
fun openPsychomatrixChangedSubscription(): ReceiveChannel<PsychomatrixOperationIsConvert>
|
||||
|
||||
suspend fun makeConvert(psychomatrix: MutablePsychomatrix, operation: Operation): Deferred<Boolean>
|
||||
suspend fun makeInvert(psychomatrix: MutablePsychomatrix, operation: Operation): Deferred<Boolean>
|
||||
fun makeConvert(psychomatrix: MutablePsychomatrix, operation: Operation): Deferred<Boolean>
|
||||
fun makeInvert(psychomatrix: MutablePsychomatrix, operation: Operation): Deferred<Boolean>
|
||||
|
||||
suspend fun getConverts(psychomatrix: Psychomatrix): Deferred<List<Operation>>
|
||||
suspend fun getInverts(psychomatrix: Psychomatrix): Deferred<List<Operation>>
|
||||
fun getConverts(psychomatrix: Psychomatrix): Deferred<List<Operation>>
|
||||
fun getInverts(psychomatrix: Psychomatrix): Deferred<List<Operation>>
|
||||
|
||||
suspend fun getPsychomatrixHistory(psychomatrix: Psychomatrix): Deferred<List<Operation>>
|
||||
fun getPsychomatrixHistory(psychomatrix: Psychomatrix): Deferred<List<Operation>>
|
||||
}
|
@ -20,34 +20,34 @@ class ModifyPsychomatrixUseCaseInteractor : ModifyPsychomatrixUseCase {
|
||||
return psychomatrixChangedBroadcastChannel.openSubscription()
|
||||
}
|
||||
|
||||
override suspend fun makeConvert(psychomatrix: MutablePsychomatrix, operation: Operation): Deferred<Boolean> {
|
||||
override fun makeConvert(psychomatrix: MutablePsychomatrix, operation: Operation): Deferred<Boolean> {
|
||||
return async {
|
||||
asMutablePsychomatrix(psychomatrix).applyConvert(operation)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun makeInvert(psychomatrix: MutablePsychomatrix, operation: Operation): Deferred<Boolean> {
|
||||
override fun makeInvert(psychomatrix: MutablePsychomatrix, operation: Operation): Deferred<Boolean> {
|
||||
return async {
|
||||
asMutablePsychomatrix(psychomatrix).applyInvert(operation)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun getConverts(psychomatrix: Psychomatrix): Deferred<List<Operation>> {
|
||||
override fun getConverts(psychomatrix: Psychomatrix): Deferred<List<Operation>> {
|
||||
return asMutablePsychomatrix(psychomatrix).availableConverts
|
||||
}
|
||||
|
||||
override suspend fun getInverts(psychomatrix: Psychomatrix): Deferred<List<Operation>> {
|
||||
override fun getInverts(psychomatrix: Psychomatrix): Deferred<List<Operation>> {
|
||||
return asMutablePsychomatrix(psychomatrix).availableInverts
|
||||
}
|
||||
|
||||
override suspend fun getPsychomatrixHistory(psychomatrix: Psychomatrix): Deferred<List<Operation>> {
|
||||
override fun getPsychomatrixHistory(psychomatrix: Psychomatrix): Deferred<List<Operation>> {
|
||||
return asMutablePsychomatrix(psychomatrix).operationsHistory
|
||||
}
|
||||
|
||||
private fun asMutablePsychomatrix(psychomatrix: Psychomatrix): MutablePsychomatrix {
|
||||
return currentPsychomatrixes.firstOrNull {
|
||||
it.date == psychomatrix.date
|
||||
} ?: MutablePsychomatrix(psychomatrix).also {
|
||||
it == psychomatrix
|
||||
} ?: (psychomatrix as? MutablePsychomatrix) ?: MutablePsychomatrix(psychomatrix).also {
|
||||
currentPsychomatrixes.add(it)
|
||||
}
|
||||
}
|
||||
|
@ -17,108 +17,27 @@ class ModifyPsychomatrixPresenterImpl(
|
||||
private val modifyPsychomatrixUseCase: ModifyPsychomatrixUseCase
|
||||
) : ModifyPsychomatrixPresenter {
|
||||
|
||||
private val availableConverts = HashMap<Psychomatrix, List<Operation>>()
|
||||
private val availableInverts = HashMap<MutablePsychomatrix, List<Operation>>()
|
||||
|
||||
init {
|
||||
openPsychomatrixChangedSubscription().subscribe {
|
||||
if (it.second.second) {
|
||||
updateConvertsOfPsychomatrix(it.first)
|
||||
} else {
|
||||
updateInvertsOfPsychomatrix(it.first)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun openPsychomatrixChangedSubscription(): ReceiveChannel<PsychomatrixOperationIsConvert> {
|
||||
return modifyPsychomatrixUseCase.openPsychomatrixChangedSubscription()
|
||||
}
|
||||
|
||||
override suspend fun tryToDoOperation(psychomatrix: MutablePsychomatrix, operation: Operation): Deferred<Boolean> {
|
||||
override fun makeConvert(psychomatrix: MutablePsychomatrix, operation: Operation): Deferred<Boolean> {
|
||||
return modifyPsychomatrixUseCase.makeConvert(psychomatrix, operation)
|
||||
}
|
||||
|
||||
override suspend fun twoGrowFourAvailable(psychomatrix: Psychomatrix): Deferred<Boolean> {
|
||||
return async {
|
||||
(availableConverts[psychomatrix] ?: updateConvertsOfPsychomatrix(psychomatrix)).contains(TwoGrowFour)
|
||||
}
|
||||
override fun makeInvert(psychomatrix: MutablePsychomatrix, operation: Operation): Deferred<Boolean> {
|
||||
return modifyPsychomatrixUseCase.makeInvert(psychomatrix, operation)
|
||||
}
|
||||
|
||||
override suspend fun fourGrowTwoAvailable(psychomatrix: Psychomatrix): Deferred<Boolean> {
|
||||
return async {
|
||||
(availableConverts[psychomatrix] ?: updateConvertsOfPsychomatrix(psychomatrix)).contains(FourGrowTwo)
|
||||
}
|
||||
override fun getConverts(psychomatrix: Psychomatrix): Deferred<List<Operation>> {
|
||||
return modifyPsychomatrixUseCase.getConverts(psychomatrix)
|
||||
}
|
||||
|
||||
override suspend fun oneGrowEightAvailable(psychomatrix: Psychomatrix): Deferred<Boolean> {
|
||||
return async {
|
||||
(availableConverts[psychomatrix] ?: updateConvertsOfPsychomatrix(psychomatrix)).contains(OneGrowEight)
|
||||
}
|
||||
override fun getInverts(psychomatrix: Psychomatrix): Deferred<List<Operation>> {
|
||||
return modifyPsychomatrixUseCase.getInverts(psychomatrix)
|
||||
}
|
||||
|
||||
override suspend fun eightGrowOneAvailable(psychomatrix: Psychomatrix): Deferred<Boolean> {
|
||||
return async {
|
||||
(availableConverts[psychomatrix] ?: updateConvertsOfPsychomatrix(psychomatrix)).contains(EightGrowOne)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun sixGrowSevenAvailable(psychomatrix: Psychomatrix): Deferred<Boolean> {
|
||||
return async {
|
||||
(availableConverts[psychomatrix] ?: updateConvertsOfPsychomatrix(psychomatrix)).contains(SixGrowSeven)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun sevenGrowSixAvailable(psychomatrix: Psychomatrix): Deferred<Boolean> {
|
||||
return async {
|
||||
(availableConverts[psychomatrix] ?: updateConvertsOfPsychomatrix(psychomatrix)).contains(SevenGrowSix)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun fiveGrowNineAvailable(psychomatrix: Psychomatrix): Deferred<Boolean> {
|
||||
return async {
|
||||
(availableConverts[psychomatrix] ?: updateConvertsOfPsychomatrix(psychomatrix)).contains(FiveGrowNine)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun nineGrowFiveAvailable(psychomatrix: Psychomatrix): Deferred<Boolean> {
|
||||
return async {
|
||||
(availableConverts[psychomatrix] ?: updateConvertsOfPsychomatrix(psychomatrix)).contains(NineGrowFive)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun customGrowAvailable(psychomatrix: Psychomatrix, number: Byte): Deferred<Boolean> {
|
||||
return async {
|
||||
(availableConverts[psychomatrix] ?: updateConvertsOfPsychomatrix(psychomatrix)).firstOrNull {
|
||||
it is GrowCustom && it.number == number
|
||||
} != null
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun rollback(psychomatrix: MutablePsychomatrix, operations: Int): Job {
|
||||
return launch {
|
||||
history(psychomatrix).await().let {
|
||||
it.subList(it.size - operations, it.size).asReversed()
|
||||
}.forEach {
|
||||
modifyPsychomatrixUseCase.makeInvert(psychomatrix, it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun history(psychomatrix: MutablePsychomatrix): Deferred<List<Operation>> {
|
||||
return async {
|
||||
availableInverts[psychomatrix] ?: updateInvertsOfPsychomatrix(psychomatrix)
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun updateConvertsOfPsychomatrix(psychomatrix: Psychomatrix): List<Operation> {
|
||||
return modifyPsychomatrixUseCase.getConverts(psychomatrix).await().also {
|
||||
availableConverts[psychomatrix] = it
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun updateInvertsOfPsychomatrix(psychomatrix: MutablePsychomatrix): List<Operation> {
|
||||
return modifyPsychomatrixUseCase.getInverts(psychomatrix).await().also {
|
||||
availableInverts[psychomatrix] = it
|
||||
}
|
||||
override fun getPsychomatrixHistory(psychomatrix: Psychomatrix): Deferred<List<Operation>> {
|
||||
return getInverts(psychomatrix)
|
||||
}
|
||||
}
|
@ -12,23 +12,11 @@ interface ModifyPsychomatrixPresenter {
|
||||
|
||||
fun openPsychomatrixChangedSubscription(): ReceiveChannel<PsychomatrixOperationIsConvert>
|
||||
|
||||
suspend fun tryToDoOperation(psychomatrix: MutablePsychomatrix, operation: Operation): Deferred<Boolean>
|
||||
fun makeConvert(psychomatrix: MutablePsychomatrix, operation: Operation): Deferred<Boolean>
|
||||
fun makeInvert(psychomatrix: MutablePsychomatrix, operation: Operation): Deferred<Boolean>
|
||||
|
||||
suspend fun twoGrowFourAvailable(psychomatrix: Psychomatrix): Deferred<Boolean>
|
||||
suspend fun fourGrowTwoAvailable(psychomatrix: Psychomatrix): Deferred<Boolean>
|
||||
fun getConverts(psychomatrix: Psychomatrix): Deferred<List<Operation>>
|
||||
fun getInverts(psychomatrix: Psychomatrix): Deferred<List<Operation>>
|
||||
|
||||
suspend fun oneGrowEightAvailable(psychomatrix: Psychomatrix): Deferred<Boolean>
|
||||
suspend fun eightGrowOneAvailable(psychomatrix: Psychomatrix): Deferred<Boolean>
|
||||
|
||||
suspend fun sixGrowSevenAvailable(psychomatrix: Psychomatrix): Deferred<Boolean>
|
||||
suspend fun sevenGrowSixAvailable(psychomatrix: Psychomatrix): Deferred<Boolean>
|
||||
|
||||
suspend fun fiveGrowNineAvailable(psychomatrix: Psychomatrix): Deferred<Boolean>
|
||||
suspend fun nineGrowFiveAvailable(psychomatrix: Psychomatrix): Deferred<Boolean>
|
||||
|
||||
suspend fun customGrowAvailable(psychomatrix: Psychomatrix, number: Byte): Deferred<Boolean>
|
||||
|
||||
suspend fun rollback(psychomatrix: MutablePsychomatrix, operations: Int): Job
|
||||
|
||||
suspend fun history(psychomatrix: MutablePsychomatrix): Deferred<List<Operation>>
|
||||
fun getPsychomatrixHistory(psychomatrix: Psychomatrix): Deferred<List<Operation>>
|
||||
}
|
Loading…
Reference in New Issue
Block a user