modify access to psychomatrix mutable instance

This commit is contained in:
InsanusMokrassar 2018-09-07 23:12:41 +08:00
parent f436cf2e9f
commit e381d54dfd
3 changed files with 10 additions and 3 deletions

View File

@ -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<Operation> = ArrayList()
constructor(psychomatrix: Psychomatrix): this(psychomatrix.date)
internal constructor(psychomatrix: Psychomatrix): this(psychomatrix.date)
val operationsHistory: List<Operation>
get() = mutableOperationsHistory

View File

@ -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
*

View File

@ -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)
}
}