diff --git a/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/Example.kt b/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/Example.kt index 0164f2e..6105437 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/Example.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/Example.kt @@ -1,13 +1,4 @@ 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) { - val psychomatrix = MutablePsychomatrix(DateTime.now().withDate(2022, 12, 22)) - runBlocking { - println(psychomatrix.availableOperations.await()) - } } diff --git a/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/domain/UseCases/ModifyPsychomatrixUseCase.kt b/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/domain/UseCases/ModifyPsychomatrixUseCase.kt index 89e70f2..72f0d08 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/domain/UseCases/ModifyPsychomatrixUseCase.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/domain/UseCases/ModifyPsychomatrixUseCase.kt @@ -1,31 +1,23 @@ 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.operations.Operation import kotlinx.coroutines.experimental.Deferred import kotlinx.coroutines.experimental.async import kotlinx.coroutines.experimental.channels.ReceiveChannel -typealias PsychomatrixOperationIsConvert = Pair> +typealias PsychomatrixOperationIsConvert = Pair> interface ModifyPsychomatrixUseCase { fun openPsychomatrixChangedSubscription(): ReceiveChannel - suspend fun makeConvert(psychomatrix: Psychomatrix, operation: Operation): Deferred - suspend fun makeInvert(psychomatrix: Psychomatrix, operation: Operation): Deferred + suspend fun makeConvert(psychomatrix: MutablePsychomatrix, operation: Operation): Deferred + suspend fun makeInvert(psychomatrix: MutablePsychomatrix, operation: Operation): Deferred suspend fun getConverts(psychomatrix: Psychomatrix): Deferred> suspend fun getInverts(psychomatrix: Psychomatrix): Deferred> - suspend fun getOperations(psychomatrix: Psychomatrix): Deferred> = async { - listOf( - getConverts(psychomatrix), - getInverts(psychomatrix) - ).flatMap { - it.await() - } - } - suspend fun getPsychomatrixHistory(psychomatrix: Psychomatrix): Deferred> } \ No newline at end of file diff --git a/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/domain/entities/Psychomatrix.kt b/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/domain/entities/Psychomatrix.kt index 0093c4e..f88c2ad 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/domain/entities/Psychomatrix.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/domain/entities/Psychomatrix.kt @@ -186,8 +186,4 @@ open class Psychomatrix(val date: DateTime) { getDownDiagSum() ) } - - override fun equals(other: Any?): Boolean { - return super.equals(other) || (other as? Psychomatrix) ?.date == date - } } diff --git a/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/domain/interactors/ModifyPsychomatrixUseCaseInteractor.kt b/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/domain/interactors/ModifyPsychomatrixUseCaseInteractor.kt index f16e7ba..2432126 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/domain/interactors/ModifyPsychomatrixUseCaseInteractor.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/domain/interactors/ModifyPsychomatrixUseCaseInteractor.kt @@ -20,13 +20,13 @@ class ModifyPsychomatrixUseCaseInteractor : ModifyPsychomatrixUseCase { return psychomatrixChangedBroadcastChannel.openSubscription() } - override suspend fun makeConvert(psychomatrix: Psychomatrix, operation: Operation): Deferred { + override suspend fun makeConvert(psychomatrix: MutablePsychomatrix, operation: Operation): Deferred { return async { asMutablePsychomatrix(psychomatrix).applyConvert(operation) } } - override suspend fun makeInvert(psychomatrix: Psychomatrix, operation: Operation): Deferred { + override suspend fun makeInvert(psychomatrix: MutablePsychomatrix, operation: Operation): Deferred { return async { asMutablePsychomatrix(psychomatrix).applyInvert(operation) } diff --git a/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/presentation/presenters/DefaultRealisations/ModifyPsychomatrixPresenterImpl.kt b/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/presentation/presenters/DefaultRealisations/ModifyPsychomatrixPresenterImpl.kt index 703a84e..596445f 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/presentation/presenters/DefaultRealisations/ModifyPsychomatrixPresenterImpl.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/presentation/presenters/DefaultRealisations/ModifyPsychomatrixPresenterImpl.kt @@ -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.PsychomatrixOperationIsConvert +import com.github.insanusmokrassar.PsychomatrixBase.domain.entities.MutablePsychomatrix import com.github.insanusmokrassar.PsychomatrixBase.domain.entities.Psychomatrix import com.github.insanusmokrassar.PsychomatrixBase.domain.entities.operations.* import com.github.insanusmokrassar.PsychomatrixBase.presentation.presenters.ModifyPsychomatrixPresenter @@ -17,7 +18,7 @@ class ModifyPsychomatrixPresenterImpl( ) : ModifyPsychomatrixPresenter { private val availableConverts = HashMap>() - private val availableInverts = HashMap>() + private val availableInverts = HashMap>() init { openPsychomatrixChangedSubscription().subscribe { @@ -33,7 +34,7 @@ class ModifyPsychomatrixPresenterImpl( return modifyPsychomatrixUseCase.openPsychomatrixChangedSubscription() } - override suspend fun tryToDoOperation(psychomatrix: Psychomatrix, operation: Operation): Deferred { + override suspend fun tryToDoOperation(psychomatrix: MutablePsychomatrix, operation: Operation): Deferred { 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 { history(psychomatrix).await().let { it.subList(it.size - operations, it.size).asReversed() @@ -103,7 +104,7 @@ class ModifyPsychomatrixPresenterImpl( } } - override suspend fun history(psychomatrix: Psychomatrix): Deferred> { + override suspend fun history(psychomatrix: MutablePsychomatrix): Deferred> { return async { availableInverts[psychomatrix] ?: updateInvertsOfPsychomatrix(psychomatrix) } @@ -115,7 +116,7 @@ class ModifyPsychomatrixPresenterImpl( } } - private suspend fun updateInvertsOfPsychomatrix(psychomatrix: Psychomatrix): List { + private suspend fun updateInvertsOfPsychomatrix(psychomatrix: MutablePsychomatrix): List { return modifyPsychomatrixUseCase.getInverts(psychomatrix).await().also { availableInverts[psychomatrix] = it } diff --git a/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/presentation/presenters/ModifyPsychomatrixPresenter.kt b/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/presentation/presenters/ModifyPsychomatrixPresenter.kt index 62e359e..658c4bc 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/presentation/presenters/ModifyPsychomatrixPresenter.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/presentation/presenters/ModifyPsychomatrixPresenter.kt @@ -1,6 +1,7 @@ package com.github.insanusmokrassar.PsychomatrixBase.presentation.presenters 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.operations.Operation import kotlinx.coroutines.experimental.Deferred @@ -11,7 +12,7 @@ interface ModifyPsychomatrixPresenter { fun openPsychomatrixChangedSubscription(): ReceiveChannel - suspend fun tryToDoOperation(psychomatrix: Psychomatrix, operation: Operation): Deferred + suspend fun tryToDoOperation(psychomatrix: MutablePsychomatrix, operation: Operation): Deferred suspend fun twoGrowFourAvailable(psychomatrix: Psychomatrix): Deferred suspend fun fourGrowTwoAvailable(psychomatrix: Psychomatrix): Deferred @@ -27,7 +28,7 @@ interface ModifyPsychomatrixPresenter { suspend fun customGrowAvailable(psychomatrix: Psychomatrix, number: Byte): Deferred - suspend fun rollback(psychomatrix: Psychomatrix, operations: Int): Job + suspend fun rollback(psychomatrix: MutablePsychomatrix, operations: Int): Job - suspend fun history(psychomatrix: Psychomatrix): Deferred> + suspend fun history(psychomatrix: MutablePsychomatrix): Deferred> } \ No newline at end of file