forked from NPM/numass-framework
Fix discrepancies
This commit is contained in:
parent
e45d1958a9
commit
50802232c3
@ -41,7 +41,7 @@ fun Context.buildContext(name: String, vararg plugins: Class<out Plugin>, init:
|
||||
}
|
||||
|
||||
fun buildContext(name: String, vararg plugins: Class<out Plugin>, init: ContextBuilder.() -> Unit = {}): Context {
|
||||
return Global.buildContext(name = name, plugins = *plugins, init = init)
|
||||
return Global.buildContext(name = name, plugins = plugins, init = init)
|
||||
}
|
||||
|
||||
//Value operations
|
||||
|
@ -7,10 +7,10 @@ import kotlin.reflect.KClass
|
||||
import kotlin.reflect.KFunction
|
||||
import kotlin.reflect.jvm.javaMethod
|
||||
|
||||
inline val <T> Optional<T>?.nullable: T?
|
||||
val <T> Optional<T>?.nullable: T?
|
||||
get() = this?.orElse(null)
|
||||
|
||||
inline val <T> T?.optional: Optional<T>
|
||||
val <T: Any> T?.optional: Optional<T>
|
||||
get() = Optional.ofNullable(this)
|
||||
|
||||
/**
|
||||
|
@ -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<V>).onComplete { res, err ->
|
||||
if (err != null) {
|
||||
result.completeExceptionally(err)
|
||||
} else {
|
||||
|
@ -24,7 +24,7 @@ class GoalGroup(private val dependencies: Collection<Goal<*>>) : Goal<Void> {
|
||||
|
||||
private var res: CompletableFuture<Void> = CompletableFuture
|
||||
.allOf(*dependencies.stream().map<CompletableFuture<*>> { it.asCompletableFuture() }.toList().toTypedArray())
|
||||
.whenComplete { aVoid, throwable ->
|
||||
.whenComplete { _, throwable ->
|
||||
if (throwable != null) {
|
||||
listeners.forEach { l -> l.onGoalFailed(throwable) }
|
||||
} else {
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -117,16 +117,16 @@ class SimpleChain<out R : Any>(private val gen: suspend () -> R) : Chain<R> {
|
||||
/**
|
||||
* A stateless Markov chain
|
||||
*/
|
||||
class MarkovChain<out R : Any>(private val seed: () -> R, private val gen: suspend (R) -> R) : Chain<R> {
|
||||
class MarkovChain<out R : Any>(private val seedFactory: () -> R, private val gen: suspend (R) -> R) : Chain<R> {
|
||||
|
||||
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<R>()
|
||||
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<out R : Any>(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<S, out R : Any>(val state: S, private val seed: S.() -> R, private val gen: suspend S.(R) -> R) : Chain<R> {
|
||||
constructor(state: S, seed: R, gen: suspend S.(R) -> R) : this(state, { seed }, gen)
|
||||
class StatefulChain<S, out R : Any>(
|
||||
val state: S,
|
||||
private val seedFactory: S.() -> R,
|
||||
private val gen: suspend S.(R) -> R,
|
||||
) : Chain<R> {
|
||||
constructor(state: S, seed: R, gen: suspend S.(R) -> R) : this(state, seedFactory = { seed }, gen)
|
||||
|
||||
private val _value = TransientValue<R>()
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user