From 50802232c39df274a0c61946643bf0fd2452608b Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sat, 29 May 2021 17:42:30 +0300 Subject: [PATCH] Fix discrepancies --- .../main/kotlin/hep/dataforge/CoreExtensions.kt | 2 +- .../src/main/kotlin/hep/dataforge/Utils.kt | 4 ++-- .../kotlin/hep/dataforge/cache/CachePlugin.kt | 2 +- .../main/kotlin/hep/dataforge/goals/GoalGroup.kt | 2 +- .../kotlin/hep/dataforge/io/output/TextOutput.kt | 6 +++--- .../hep/dataforge/workspace/WorkspaceTest.kt | 16 ++++++++-------- .../kotlin/hep/dataforge/maths/chain/Chain.kt | 16 ++++++++++------ .../dataforge/grind/workspace/ExecTest.groovy | 2 ++ 8 files changed, 28 insertions(+), 22 deletions(-) diff --git a/dataforge-core/src/main/kotlin/hep/dataforge/CoreExtensions.kt b/dataforge-core/src/main/kotlin/hep/dataforge/CoreExtensions.kt index 9c03774..9695de8 100644 --- a/dataforge-core/src/main/kotlin/hep/dataforge/CoreExtensions.kt +++ b/dataforge-core/src/main/kotlin/hep/dataforge/CoreExtensions.kt @@ -41,7 +41,7 @@ fun Context.buildContext(name: String, vararg plugins: Class, init: } fun buildContext(name: String, vararg plugins: Class, init: ContextBuilder.() -> Unit = {}): Context { - return Global.buildContext(name = name, plugins = *plugins, init = init) + return Global.buildContext(name = name, plugins = plugins, init = init) } //Value operations diff --git a/dataforge-core/src/main/kotlin/hep/dataforge/Utils.kt b/dataforge-core/src/main/kotlin/hep/dataforge/Utils.kt index a7fe3de..14ce849 100644 --- a/dataforge-core/src/main/kotlin/hep/dataforge/Utils.kt +++ b/dataforge-core/src/main/kotlin/hep/dataforge/Utils.kt @@ -7,10 +7,10 @@ import kotlin.reflect.KClass import kotlin.reflect.KFunction import kotlin.reflect.jvm.javaMethod -inline val Optional?.nullable: T? +val Optional?.nullable: T? get() = this?.orElse(null) -inline val T?.optional: Optional +val T?.optional: Optional get() = Optional.ofNullable(this) /** diff --git a/dataforge-core/src/main/kotlin/hep/dataforge/cache/CachePlugin.kt b/dataforge-core/src/main/kotlin/hep/dataforge/cache/CachePlugin.kt index afd7d1a..51fcd45 100644 --- a/dataforge-core/src/main/kotlin/hep/dataforge/cache/CachePlugin.kt +++ b/dataforge-core/src/main/kotlin/hep/dataforge/cache/CachePlugin.kt @@ -113,7 +113,7 @@ class CachePlugin(meta: Meta) : BasicPlugin(meta) { private fun evalData() { data.goal.run() - data.goal.onComplete { res, err -> + (data.goal as Goal).onComplete { res, err -> if (err != null) { result.completeExceptionally(err) } else { diff --git a/dataforge-core/src/main/kotlin/hep/dataforge/goals/GoalGroup.kt b/dataforge-core/src/main/kotlin/hep/dataforge/goals/GoalGroup.kt index 4cb7e7a..5153ccb 100644 --- a/dataforge-core/src/main/kotlin/hep/dataforge/goals/GoalGroup.kt +++ b/dataforge-core/src/main/kotlin/hep/dataforge/goals/GoalGroup.kt @@ -24,7 +24,7 @@ class GoalGroup(private val dependencies: Collection>) : Goal { private var res: CompletableFuture = CompletableFuture .allOf(*dependencies.stream().map> { it.asCompletableFuture() }.toList().toTypedArray()) - .whenComplete { aVoid, throwable -> + .whenComplete { _, throwable -> if (throwable != null) { listeners.forEach { l -> l.onGoalFailed(throwable) } } else { diff --git a/dataforge-core/src/main/kotlin/hep/dataforge/io/output/TextOutput.kt b/dataforge-core/src/main/kotlin/hep/dataforge/io/output/TextOutput.kt index 77eb373..b217fca 100644 --- a/dataforge-core/src/main/kotlin/hep/dataforge/io/output/TextOutput.kt +++ b/dataforge-core/src/main/kotlin/hep/dataforge/io/output/TextOutput.kt @@ -209,9 +209,9 @@ class ANSIStreamOutput(context: Context, stream: OutputStream) : StreamOutput(co append(IOUtils.wrapANSI(event.loggerName, IOUtils.ANSI_BLUE) + "\t") when (event.level) { - Level.ERROR -> appendln(IOUtils.wrapANSI(event.message, IOUtils.ANSI_RED)) - Level.WARN -> appendln(IOUtils.wrapANSI(event.message, IOUtils.ANSI_YELLOW)) - else -> appendln(event.message) + Level.ERROR -> appendLine(IOUtils.wrapANSI(event.message, IOUtils.ANSI_RED)) + Level.WARN -> appendLine(IOUtils.wrapANSI(event.message, IOUtils.ANSI_YELLOW)) + else -> appendLine(event.message) } }.toByteArray() } diff --git a/dataforge-core/src/test/kotlin/hep/dataforge/workspace/WorkspaceTest.kt b/dataforge-core/src/test/kotlin/hep/dataforge/workspace/WorkspaceTest.kt index 3ee6dda..a05898d 100644 --- a/dataforge-core/src/test/kotlin/hep/dataforge/workspace/WorkspaceTest.kt +++ b/dataforge-core/src/test/kotlin/hep/dataforge/workspace/WorkspaceTest.kt @@ -51,7 +51,7 @@ class WorkspaceTest { res2.computeAll() assertEquals(6, counter.get().toLong()) val res3 = wsp.runTask("test2", MetaBuilder().putValue("a", 1)) - .getCheckedData("data_2", Number::class.java).get().toLong() + .getCheckedData("data_2", Number::class.java).get().toLong() assertEquals(6, res3) assertEquals(8, counter.get().toLong()) } @@ -103,13 +103,13 @@ class WorkspaceTest { } wsp = BasicWorkspace.Builder() - .apply { this.context = context } - .staticData("data_1", 1) - .staticData("data_2", 2) - .staticData("data_3", 3) - .task(task1) - .task(task2) - .build() + .apply { this.context = context } + .staticData("data_1", 1) + .staticData("data_2", 2) + .staticData("data_3", 3) + .task(task1) + .task(task2) + .build() } diff --git a/dataforge-maths/src/main/kotlin/hep/dataforge/maths/chain/Chain.kt b/dataforge-maths/src/main/kotlin/hep/dataforge/maths/chain/Chain.kt index 30adf24..9bac0d1 100644 --- a/dataforge-maths/src/main/kotlin/hep/dataforge/maths/chain/Chain.kt +++ b/dataforge-maths/src/main/kotlin/hep/dataforge/maths/chain/Chain.kt @@ -117,16 +117,16 @@ class SimpleChain(private val gen: suspend () -> R) : Chain { /** * A stateless Markov chain */ -class MarkovChain(private val seed: () -> R, private val gen: suspend (R) -> R) : Chain { +class MarkovChain(private val seedFactory: () -> R, private val gen: suspend (R) -> R) : Chain { - constructor(seed: R, gen: suspend (R) -> R) : this({ seed }, gen) + constructor(seed: R, gen: suspend (R) -> R) : this(seedFactory = { seed }, gen) private val _value = TransientValue() override val value: R get() = _value.value ?: runBlocking { next() } override suspend fun next(): R { - _value.update(gen(_value.value ?: seed())) + _value.update(gen(_value.value ?: seedFactory())) return value } @@ -138,15 +138,19 @@ class MarkovChain(private val seed: () -> R, private val gen: suspe /** * A chain with possibly mutable state. The state must not be changed outside the chain. Two chins should never share the state */ -class StatefulChain(val state: S, private val seed: S.() -> R, private val gen: suspend S.(R) -> R) : Chain { - constructor(state: S, seed: R, gen: suspend S.(R) -> R) : this(state, { seed }, gen) +class StatefulChain( + val state: S, + private val seedFactory: S.() -> R, + private val gen: suspend S.(R) -> R, +) : Chain { + constructor(state: S, seed: R, gen: suspend S.(R) -> R) : this(state, seedFactory = { seed }, gen) private val _value = TransientValue() override val value: R get() = _value.value ?: runBlocking { next() } override suspend fun next(): R { - _value.update(gen(state,_value.value ?: seed(state))) + _value.update(gen(state, _value.value ?: seedFactory(state))) return value } diff --git a/grind/src/test/groovy/hep/dataforge/grind/workspace/ExecTest.groovy b/grind/src/test/groovy/hep/dataforge/grind/workspace/ExecTest.groovy index 27a8d4d..4b9fefb 100644 --- a/grind/src/test/groovy/hep/dataforge/grind/workspace/ExecTest.groovy +++ b/grind/src/test/groovy/hep/dataforge/grind/workspace/ExecTest.groovy @@ -4,12 +4,14 @@ import hep.dataforge.context.Global import hep.dataforge.data.DataSet import hep.dataforge.grind.Grind import hep.dataforge.meta.Meta +import org.junit.Ignore import spock.lang.Specification import spock.lang.Timeout class ExecTest extends Specification { @Timeout(3) + @Ignore def "get Java version"() { given: def exec = new ExecSpec()