Java implementation of CloseableWrapper
This commit is contained in:
parent
96931fda41
commit
c078394921
@ -65,7 +65,7 @@ xomrk {
|
||||
val commonMain by getting {
|
||||
dependencies {
|
||||
implementation(kotlinStdlibDependency)
|
||||
implementation("ru.landgrafhomyak.utility:highlevel-try-finally:0.5")
|
||||
implementation("ru.landgrafhomyak.utility:highlevel-try-finally:0.6")
|
||||
}
|
||||
}
|
||||
val commonTest by getting {
|
||||
|
||||
@ -1 +1 @@
|
||||
Subproject commit 099c3fad269770649d5a67acd3cd07e378bc9f37
|
||||
Subproject commit 6cfa6bddd04a041ae02ec8098c478762313c71de
|
||||
@ -1,40 +1,26 @@
|
||||
package ru.landgrafhomyak.utility.closeable_state_1
|
||||
|
||||
public class CloseableStateCloseableWrapper(
|
||||
private val _parent: CloseableState.ExternallySynchronized,
|
||||
private val _self: CloseableState.ExternallySynchronized
|
||||
) : CloseableState.ExternallySynchronized {
|
||||
public expect class CloseableStateCloseableWrapper : CloseableState.ExternallySynchronized {
|
||||
|
||||
override val isInUse: Boolean by this._self::isInUse
|
||||
public constructor(parent: CloseableState.ExternallySynchronized, self: CloseableState.ExternallySynchronized)
|
||||
|
||||
override val isClosed: Boolean by this._self::isInUse
|
||||
override val isInUse: Boolean
|
||||
|
||||
override fun assertNotClosed(): Unit =
|
||||
this._self.assertNotClosed()
|
||||
override val isClosed: Boolean
|
||||
|
||||
override fun assertNotClosed()
|
||||
|
||||
@ManualStateManipulation
|
||||
override fun startUsage() {
|
||||
this._self.tryStartUsage {
|
||||
this._parent.startUsage()
|
||||
}
|
||||
}
|
||||
override fun startUsage()
|
||||
|
||||
@ManualStateManipulation
|
||||
override fun finishUsage() {
|
||||
this._self.tryFinishUsage {
|
||||
this._parent.finishUsage()
|
||||
}
|
||||
}
|
||||
override fun finishUsage()
|
||||
|
||||
@ManualStateManipulation
|
||||
override fun finishUsage(close: Boolean) {
|
||||
this._self.tryFinishUsageThenClose(close) {
|
||||
this._parent.finishUsage()
|
||||
}
|
||||
}
|
||||
override fun finishUsage(close: Boolean)
|
||||
|
||||
@ManualStateManipulation
|
||||
override fun close() {
|
||||
this._self.close()
|
||||
}
|
||||
override fun close()
|
||||
|
||||
override fun toString(): String
|
||||
}
|
||||
@ -51,7 +51,6 @@ public inline fun <R> CloseableState.tryFinishUsage(block: () -> R): R {
|
||||
contract {
|
||||
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
|
||||
}
|
||||
this.assertNotClosed()
|
||||
return safeAutoClose2(action = block, onSuccess = this::finishUsage)
|
||||
}
|
||||
|
||||
@ -76,7 +75,6 @@ public inline fun <R> CloseableState.ExternallySynchronized.tryFinishUsageThenCl
|
||||
contract {
|
||||
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
|
||||
}
|
||||
this.assertNotClosed()
|
||||
return safeAutoClose2(action = block, onSuccess = { this.finishUsage(close) })
|
||||
}
|
||||
|
||||
@ -86,7 +84,6 @@ public inline fun CloseableState.ExternallySynchronized.tryFinishUsageThenClose(
|
||||
contract {
|
||||
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
|
||||
}
|
||||
this.assertNotClosed()
|
||||
var needClose = false
|
||||
return safeAutoClose2(
|
||||
action = { needClose = block() },
|
||||
|
||||
@ -0,0 +1,70 @@
|
||||
package ru.landgrafhomyak.utility.closeable_state_1;
|
||||
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public final class jCloseableStateCloseableWrapper
|
||||
implements CloseableState.ExternallySynchronized {
|
||||
private final CloseableState.ExternallySynchronized _parent;
|
||||
private final CloseableState.ExternallySynchronized _self;
|
||||
|
||||
public jCloseableStateCloseableWrapper(CloseableState.ExternallySynchronized parent, CloseableState.ExternallySynchronized self) {
|
||||
Objects.requireNonNull(parent, "param: parent");
|
||||
Objects.requireNonNull(self, "param: self");
|
||||
this._parent = parent;
|
||||
this._self = self;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isInUse() {
|
||||
return this._self.isInUse();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isClosed() {
|
||||
return this._self.isClosed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void assertNotClosed() {
|
||||
this._self.assertNotClosed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startUsage() {
|
||||
this._self.startUsage();
|
||||
try {
|
||||
this._parent.startUsage();
|
||||
} catch (Throwable e1) {
|
||||
try {
|
||||
this._self.finishUsage();
|
||||
} catch (Throwable e2) {
|
||||
e1.addSuppressed(e2);
|
||||
}
|
||||
throw e1;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finishUsage() {
|
||||
this._parent.finishUsage();
|
||||
this._self.finishUsage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finishUsage(boolean close) {
|
||||
this._parent.finishUsage();
|
||||
this._self.finishUsage(close);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
this._self.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "<closeable state " + this._parent + " wrapped with " + this._self + ">";
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,57 @@
|
||||
package ru.landgrafhomyak.utility.closeable_state_1
|
||||
|
||||
public actual class CloseableStateCloseableWrapper : CloseableState.ExternallySynchronized {
|
||||
private val _parent: CloseableState.ExternallySynchronized
|
||||
private val _self: CloseableState.ExternallySynchronized
|
||||
|
||||
public actual constructor(
|
||||
parent: CloseableState.ExternallySynchronized,
|
||||
self: CloseableState.ExternallySynchronized,
|
||||
) {
|
||||
this._parent = parent
|
||||
this._self = self
|
||||
}
|
||||
|
||||
actual override val isInUse: Boolean
|
||||
get() = this._self.isInUse
|
||||
|
||||
actual override val isClosed: Boolean
|
||||
get() = this._self.isClosed
|
||||
|
||||
actual override fun assertNotClosed(): Unit =
|
||||
this._self.assertNotClosed()
|
||||
|
||||
@ManualStateManipulation
|
||||
actual override fun startUsage() {
|
||||
this._self.startUsage()
|
||||
try {
|
||||
this._parent.startUsage()
|
||||
} catch (e1: Throwable) {
|
||||
try {
|
||||
this._self.finishUsage()
|
||||
} catch (e2: Throwable) {
|
||||
e1.addSuppressed(e2)
|
||||
}
|
||||
throw e1
|
||||
}
|
||||
}
|
||||
|
||||
@ManualStateManipulation
|
||||
actual override fun finishUsage() {
|
||||
this._parent.finishUsage()
|
||||
this._self.finishUsage()
|
||||
}
|
||||
|
||||
@ManualStateManipulation
|
||||
actual override fun finishUsage(close: Boolean) {
|
||||
this._parent.finishUsage()
|
||||
this._self.finishUsage(close)
|
||||
}
|
||||
|
||||
@ManualStateManipulation
|
||||
actual override fun close() {
|
||||
this._self.close()
|
||||
}
|
||||
|
||||
actual override fun toString(): String = "<closeable state ${this._parent} wrapped with ${this._self}>"
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user