mirror of
https://github.com/InsanusMokrassar/PsychomatrixBase.git
synced 2024-11-14 20:33:57 +00:00
modify access to psychomatrix mutable instance
This commit is contained in:
parent
f436cf2e9f
commit
e381d54dfd
@ -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
|
||||
|
@ -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
|
||||
*
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user