From e381d54dfdeece8ae596f82f3314bcc22dbb67ec Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 7 Sep 2018 23:12:41 +0800 Subject: [PATCH] modify access to psychomatrix mutable instance --- .../domain/entities/MutablePsychomatrix.kt | 7 +++++-- .../PsychomatrixBase/domain/entities/Psychomatrix.kt | 4 ++++ .../interactors/ModifyPsychomatrixUseCaseInteractor.kt | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/domain/entities/MutablePsychomatrix.kt b/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/domain/entities/MutablePsychomatrix.kt index 725f3c4..9844498 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/domain/entities/MutablePsychomatrix.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/domain/entities/MutablePsychomatrix.kt @@ -3,15 +3,18 @@ package com.github.insanusmokrassar.PsychomatrixBase.domain.entities import com.github.insanusmokrassar.PsychomatrixBase.domain.entities.operations.* import org.joda.time.DateTime -class MutablePsychomatrix(date: DateTime) : Psychomatrix(date) { +class MutablePsychomatrix private constructor(date: DateTime) : Psychomatrix(date) { private var mutableNumbers = calculateNumbers(date).toMutableList() override val numbers: ByteArray get() = mutableNumbers.toByteArray() + override val asMutablePsychomatrix: MutablePsychomatrix + get() = this + private val mutableOperationsHistory: MutableList = ArrayList() - constructor(psychomatrix: Psychomatrix): this(psychomatrix.date) + internal constructor(psychomatrix: Psychomatrix): this(psychomatrix.date) val operationsHistory: List get() = mutableOperationsHistory 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 f88c2ad..3f7ddb2 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 @@ -57,6 +57,10 @@ fun calculateNumbers(dateTime: DateTime): ByteArray { open class Psychomatrix(val date: DateTime) { protected open val numbers: ByteArray = calculateNumbers(date) + open val asMutablePsychomatrix: MutablePsychomatrix by lazy { + MutablePsychomatrix(this) + } + /** * Always array 4*5 of values. In rows was put columns * 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 280ab5c..0b9e871 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 @@ -52,7 +52,7 @@ class ModifyPsychomatrixUseCaseInteractor : ModifyPsychomatrixUseCase { private fun asMutablePsychomatrix(psychomatrix: Psychomatrix): MutablePsychomatrix { return currentPsychomatrixes.firstOrNull { it == psychomatrix - } ?: (psychomatrix as? MutablePsychomatrix) ?: MutablePsychomatrix(psychomatrix).also { + } ?: psychomatrix.asMutablePsychomatrix.also { currentPsychomatrixes.add(it) } }