diff --git a/src/commonMain/kotlin/ru/landgrafhomyak/utility/closeable_state_1/OwnedErrorOnConcurrentAccessState.kt b/src/commonMain/kotlin/ru/landgrafhomyak/utility/closeable_state_1/OwnedErrorOnConcurrentAccessState.kt index 04cf3c1..99640f0 100644 --- a/src/commonMain/kotlin/ru/landgrafhomyak/utility/closeable_state_1/OwnedErrorOnConcurrentAccessState.kt +++ b/src/commonMain/kotlin/ru/landgrafhomyak/utility/closeable_state_1/OwnedErrorOnConcurrentAccessState.kt @@ -5,12 +5,23 @@ package ru.landgrafhomyak.utility.closeable_state_1 import kotlin.contracts.ExperimentalContracts public class OwnedErrorOnConcurrentAccessState : ErrorOnConcurrentAccessState { - public val _owner: Any + private var _owner: Any? + + public constructor() : super() { + this._owner = null + } public constructor(owner: Any) : super() { this._owner = owner } + public var owner: Any + get() = this._owner ?: throw IllegalStateException("Owner not set yet") + set(value) { + if (this._owner != null) throw IllegalStateException("Owner already initialized") + this._owner = value + } + override fun throwClosed(): Nothing { throw IllegalStateException("Object is closed: ${this._owner}") } diff --git a/src/commonMain/kotlin/ru/landgrafhomyak/utility/closeable_state_1/OwnedUsagesCounter.kt b/src/commonMain/kotlin/ru/landgrafhomyak/utility/closeable_state_1/OwnedUsagesCounter.kt index d320447..467534a 100644 --- a/src/commonMain/kotlin/ru/landgrafhomyak/utility/closeable_state_1/OwnedUsagesCounter.kt +++ b/src/commonMain/kotlin/ru/landgrafhomyak/utility/closeable_state_1/OwnedUsagesCounter.kt @@ -5,12 +5,23 @@ package ru.landgrafhomyak.utility.closeable_state_1 import kotlin.contracts.ExperimentalContracts public class OwnedUsagesCounter : UsagesCounter { - public val _owner: Any + private var _owner: Any? + + public constructor() : super() { + this._owner = null + } public constructor(owner: Any) : super() { this._owner = owner } + public var owner: Any + get() = this._owner ?: throw IllegalStateException("Owner not set yet") + set(value) { + if (this._owner != null) throw IllegalStateException("Owner already initialized") + this._owner = value + } + override fun throwClosed(): Nothing { throw IllegalStateException("Object is closed: ${this._owner}") }