Improved 'owner' property in corresponding states

This commit is contained in:
Andrew Golovashevich 2025-08-24 01:48:20 +03:00
parent ad87bb7904
commit 826f286404
2 changed files with 24 additions and 2 deletions

View File

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

View File

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