mirror of
https://github.com/InsanusMokrassar/PsychomatrixBase.git
synced 2024-11-15 04:43:58 +00:00
totaly rewriten modify branch
This commit is contained in:
parent
fdfd55cdb7
commit
c2a4f76130
@ -1,13 +1,4 @@
|
|||||||
package com.github.insanusmokrassar.PsychomatrixBase
|
package com.github.insanusmokrassar.PsychomatrixBase
|
||||||
|
|
||||||
import com.github.insanusmokrassar.PsychomatrixBase.domain.entities.MutablePsychomatrix
|
|
||||||
import com.github.insanusmokrassar.PsychomatrixBase.domain.entities.operations.TwoGrowFour
|
|
||||||
import kotlinx.coroutines.experimental.runBlocking
|
|
||||||
import org.joda.time.DateTime
|
|
||||||
|
|
||||||
fun main(args: Array<String>) {
|
fun main(args: Array<String>) {
|
||||||
val psychomatrix = MutablePsychomatrix(DateTime.now().withDate(2022, 12, 22))
|
|
||||||
runBlocking {
|
|
||||||
println(psychomatrix.availableOperations.await())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,31 +1,23 @@
|
|||||||
package com.github.insanusmokrassar.PsychomatrixBase.domain.UseCases
|
package com.github.insanusmokrassar.PsychomatrixBase.domain.UseCases
|
||||||
|
|
||||||
|
import com.github.insanusmokrassar.PsychomatrixBase.domain.entities.MutablePsychomatrix
|
||||||
import com.github.insanusmokrassar.PsychomatrixBase.domain.entities.Psychomatrix
|
import com.github.insanusmokrassar.PsychomatrixBase.domain.entities.Psychomatrix
|
||||||
import com.github.insanusmokrassar.PsychomatrixBase.domain.entities.operations.Operation
|
import com.github.insanusmokrassar.PsychomatrixBase.domain.entities.operations.Operation
|
||||||
import kotlinx.coroutines.experimental.Deferred
|
import kotlinx.coroutines.experimental.Deferred
|
||||||
import kotlinx.coroutines.experimental.async
|
import kotlinx.coroutines.experimental.async
|
||||||
import kotlinx.coroutines.experimental.channels.ReceiveChannel
|
import kotlinx.coroutines.experimental.channels.ReceiveChannel
|
||||||
|
|
||||||
typealias PsychomatrixOperationIsConvert = Pair<Psychomatrix, Pair<Operation, Boolean>>
|
typealias PsychomatrixOperationIsConvert = Pair<MutablePsychomatrix, Pair<Operation, Boolean>>
|
||||||
|
|
||||||
interface ModifyPsychomatrixUseCase {
|
interface ModifyPsychomatrixUseCase {
|
||||||
|
|
||||||
fun openPsychomatrixChangedSubscription(): ReceiveChannel<PsychomatrixOperationIsConvert>
|
fun openPsychomatrixChangedSubscription(): ReceiveChannel<PsychomatrixOperationIsConvert>
|
||||||
|
|
||||||
suspend fun makeConvert(psychomatrix: Psychomatrix, operation: Operation): Deferred<Boolean>
|
suspend fun makeConvert(psychomatrix: MutablePsychomatrix, operation: Operation): Deferred<Boolean>
|
||||||
suspend fun makeInvert(psychomatrix: Psychomatrix, operation: Operation): Deferred<Boolean>
|
suspend fun makeInvert(psychomatrix: MutablePsychomatrix, operation: Operation): Deferred<Boolean>
|
||||||
|
|
||||||
suspend fun getConverts(psychomatrix: Psychomatrix): Deferred<List<Operation>>
|
suspend fun getConverts(psychomatrix: Psychomatrix): Deferred<List<Operation>>
|
||||||
suspend fun getInverts(psychomatrix: Psychomatrix): Deferred<List<Operation>>
|
suspend fun getInverts(psychomatrix: Psychomatrix): Deferred<List<Operation>>
|
||||||
|
|
||||||
suspend fun getOperations(psychomatrix: Psychomatrix): Deferred<List<Operation>> = async {
|
|
||||||
listOf(
|
|
||||||
getConverts(psychomatrix),
|
|
||||||
getInverts(psychomatrix)
|
|
||||||
).flatMap {
|
|
||||||
it.await()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun getPsychomatrixHistory(psychomatrix: Psychomatrix): Deferred<List<Operation>>
|
suspend fun getPsychomatrixHistory(psychomatrix: Psychomatrix): Deferred<List<Operation>>
|
||||||
}
|
}
|
@ -186,8 +186,4 @@ open class Psychomatrix(val date: DateTime) {
|
|||||||
getDownDiagSum()
|
getDownDiagSum()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
|
||||||
return super.equals(other) || (other as? Psychomatrix) ?.date == date
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,13 +20,13 @@ class ModifyPsychomatrixUseCaseInteractor : ModifyPsychomatrixUseCase {
|
|||||||
return psychomatrixChangedBroadcastChannel.openSubscription()
|
return psychomatrixChangedBroadcastChannel.openSubscription()
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun makeConvert(psychomatrix: Psychomatrix, operation: Operation): Deferred<Boolean> {
|
override suspend fun makeConvert(psychomatrix: MutablePsychomatrix, operation: Operation): Deferred<Boolean> {
|
||||||
return async {
|
return async {
|
||||||
asMutablePsychomatrix(psychomatrix).applyConvert(operation)
|
asMutablePsychomatrix(psychomatrix).applyConvert(operation)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun makeInvert(psychomatrix: Psychomatrix, operation: Operation): Deferred<Boolean> {
|
override suspend fun makeInvert(psychomatrix: MutablePsychomatrix, operation: Operation): Deferred<Boolean> {
|
||||||
return async {
|
return async {
|
||||||
asMutablePsychomatrix(psychomatrix).applyInvert(operation)
|
asMutablePsychomatrix(psychomatrix).applyInvert(operation)
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package com.github.insanusmokrassar.PsychomatrixBase.presentation.presenters.Def
|
|||||||
|
|
||||||
import com.github.insanusmokrassar.PsychomatrixBase.domain.UseCases.ModifyPsychomatrixUseCase
|
import com.github.insanusmokrassar.PsychomatrixBase.domain.UseCases.ModifyPsychomatrixUseCase
|
||||||
import com.github.insanusmokrassar.PsychomatrixBase.domain.UseCases.PsychomatrixOperationIsConvert
|
import com.github.insanusmokrassar.PsychomatrixBase.domain.UseCases.PsychomatrixOperationIsConvert
|
||||||
|
import com.github.insanusmokrassar.PsychomatrixBase.domain.entities.MutablePsychomatrix
|
||||||
import com.github.insanusmokrassar.PsychomatrixBase.domain.entities.Psychomatrix
|
import com.github.insanusmokrassar.PsychomatrixBase.domain.entities.Psychomatrix
|
||||||
import com.github.insanusmokrassar.PsychomatrixBase.domain.entities.operations.*
|
import com.github.insanusmokrassar.PsychomatrixBase.domain.entities.operations.*
|
||||||
import com.github.insanusmokrassar.PsychomatrixBase.presentation.presenters.ModifyPsychomatrixPresenter
|
import com.github.insanusmokrassar.PsychomatrixBase.presentation.presenters.ModifyPsychomatrixPresenter
|
||||||
@ -17,7 +18,7 @@ class ModifyPsychomatrixPresenterImpl(
|
|||||||
) : ModifyPsychomatrixPresenter {
|
) : ModifyPsychomatrixPresenter {
|
||||||
|
|
||||||
private val availableConverts = HashMap<Psychomatrix, List<Operation>>()
|
private val availableConverts = HashMap<Psychomatrix, List<Operation>>()
|
||||||
private val availableInverts = HashMap<Psychomatrix, List<Operation>>()
|
private val availableInverts = HashMap<MutablePsychomatrix, List<Operation>>()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
openPsychomatrixChangedSubscription().subscribe {
|
openPsychomatrixChangedSubscription().subscribe {
|
||||||
@ -33,7 +34,7 @@ class ModifyPsychomatrixPresenterImpl(
|
|||||||
return modifyPsychomatrixUseCase.openPsychomatrixChangedSubscription()
|
return modifyPsychomatrixUseCase.openPsychomatrixChangedSubscription()
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun tryToDoOperation(psychomatrix: Psychomatrix, operation: Operation): Deferred<Boolean> {
|
override suspend fun tryToDoOperation(psychomatrix: MutablePsychomatrix, operation: Operation): Deferred<Boolean> {
|
||||||
return modifyPsychomatrixUseCase.makeConvert(psychomatrix, operation)
|
return modifyPsychomatrixUseCase.makeConvert(psychomatrix, operation)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,7 +94,7 @@ class ModifyPsychomatrixPresenterImpl(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun rollback(psychomatrix: Psychomatrix, operations: Int): Job {
|
override suspend fun rollback(psychomatrix: MutablePsychomatrix, operations: Int): Job {
|
||||||
return launch {
|
return launch {
|
||||||
history(psychomatrix).await().let {
|
history(psychomatrix).await().let {
|
||||||
it.subList(it.size - operations, it.size).asReversed()
|
it.subList(it.size - operations, it.size).asReversed()
|
||||||
@ -103,7 +104,7 @@ class ModifyPsychomatrixPresenterImpl(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun history(psychomatrix: Psychomatrix): Deferred<List<Operation>> {
|
override suspend fun history(psychomatrix: MutablePsychomatrix): Deferred<List<Operation>> {
|
||||||
return async {
|
return async {
|
||||||
availableInverts[psychomatrix] ?: updateInvertsOfPsychomatrix(psychomatrix)
|
availableInverts[psychomatrix] ?: updateInvertsOfPsychomatrix(psychomatrix)
|
||||||
}
|
}
|
||||||
@ -115,7 +116,7 @@ class ModifyPsychomatrixPresenterImpl(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun updateInvertsOfPsychomatrix(psychomatrix: Psychomatrix): List<Operation> {
|
private suspend fun updateInvertsOfPsychomatrix(psychomatrix: MutablePsychomatrix): List<Operation> {
|
||||||
return modifyPsychomatrixUseCase.getInverts(psychomatrix).await().also {
|
return modifyPsychomatrixUseCase.getInverts(psychomatrix).await().also {
|
||||||
availableInverts[psychomatrix] = it
|
availableInverts[psychomatrix] = it
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.github.insanusmokrassar.PsychomatrixBase.presentation.presenters
|
package com.github.insanusmokrassar.PsychomatrixBase.presentation.presenters
|
||||||
|
|
||||||
import com.github.insanusmokrassar.PsychomatrixBase.domain.UseCases.PsychomatrixOperationIsConvert
|
import com.github.insanusmokrassar.PsychomatrixBase.domain.UseCases.PsychomatrixOperationIsConvert
|
||||||
|
import com.github.insanusmokrassar.PsychomatrixBase.domain.entities.MutablePsychomatrix
|
||||||
import com.github.insanusmokrassar.PsychomatrixBase.domain.entities.Psychomatrix
|
import com.github.insanusmokrassar.PsychomatrixBase.domain.entities.Psychomatrix
|
||||||
import com.github.insanusmokrassar.PsychomatrixBase.domain.entities.operations.Operation
|
import com.github.insanusmokrassar.PsychomatrixBase.domain.entities.operations.Operation
|
||||||
import kotlinx.coroutines.experimental.Deferred
|
import kotlinx.coroutines.experimental.Deferred
|
||||||
@ -11,7 +12,7 @@ interface ModifyPsychomatrixPresenter {
|
|||||||
|
|
||||||
fun openPsychomatrixChangedSubscription(): ReceiveChannel<PsychomatrixOperationIsConvert>
|
fun openPsychomatrixChangedSubscription(): ReceiveChannel<PsychomatrixOperationIsConvert>
|
||||||
|
|
||||||
suspend fun tryToDoOperation(psychomatrix: Psychomatrix, operation: Operation): Deferred<Boolean>
|
suspend fun tryToDoOperation(psychomatrix: MutablePsychomatrix, operation: Operation): Deferred<Boolean>
|
||||||
|
|
||||||
suspend fun twoGrowFourAvailable(psychomatrix: Psychomatrix): Deferred<Boolean>
|
suspend fun twoGrowFourAvailable(psychomatrix: Psychomatrix): Deferred<Boolean>
|
||||||
suspend fun fourGrowTwoAvailable(psychomatrix: Psychomatrix): Deferred<Boolean>
|
suspend fun fourGrowTwoAvailable(psychomatrix: Psychomatrix): Deferred<Boolean>
|
||||||
@ -27,7 +28,7 @@ interface ModifyPsychomatrixPresenter {
|
|||||||
|
|
||||||
suspend fun customGrowAvailable(psychomatrix: Psychomatrix, number: Byte): Deferred<Boolean>
|
suspend fun customGrowAvailable(psychomatrix: Psychomatrix, number: Byte): Deferred<Boolean>
|
||||||
|
|
||||||
suspend fun rollback(psychomatrix: Psychomatrix, operations: Int): Job
|
suspend fun rollback(psychomatrix: MutablePsychomatrix, operations: Int): Job
|
||||||
|
|
||||||
suspend fun history(psychomatrix: Psychomatrix): Deferred<List<Operation>>
|
suspend fun history(psychomatrix: MutablePsychomatrix): Deferred<List<Operation>>
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user