Compare commits
No commits in common. "28f4beb3485cf07df493347cb7a317e1217dfcc4" and "facf7c3c7e423ce22039e7ad2612192b3f3d2f1b" have entirely different histories.
28f4beb348
...
facf7c3c7e
@ -4,22 +4,16 @@
|
||||
|
||||
### Added
|
||||
- Name index comparator
|
||||
- Specialized ByteArrayValue
|
||||
|
||||
### Changed
|
||||
- DataSink `branch` is replaced with `putAll` to avoid confusion with DataTree methods
|
||||
- Meta delegate now uses a specific class that has a descriptor
|
||||
|
||||
### Deprecated
|
||||
|
||||
### Removed
|
||||
|
||||
### Fixed
|
||||
- `listOfScheme` and `listOfConvertable` delegates provides correct items order.
|
||||
- Scheme meta setter works with proper sub-branch.
|
||||
- NameToken.parse improper work with indices.
|
||||
- Proper data handling for cache.
|
||||
|
||||
- `listOfScheme` and `listOfConvertable` delegates provides correct items order
|
||||
|
||||
### Security
|
||||
|
||||
|
@ -8,7 +8,7 @@ plugins {
|
||||
|
||||
allprojects {
|
||||
group = "space.kscience"
|
||||
version = "0.8.2-dev-1"
|
||||
version = "0.8.1-dev-1"
|
||||
}
|
||||
|
||||
subprojects {
|
||||
@ -30,7 +30,7 @@ ksciencePublish {
|
||||
useApache2Licence()
|
||||
useSPCTeam()
|
||||
}
|
||||
repository("spc", "https://maven.sciprog.center/kscience")
|
||||
repository("spc","https://maven.sciprog.center/kscience")
|
||||
sonatype("https://oss.sonatype.org")
|
||||
}
|
||||
|
||||
|
@ -265,6 +265,8 @@ public abstract interface annotation class space/kscience/dataforge/descriptors/
|
||||
}
|
||||
|
||||
public final class space/kscience/dataforge/descriptors/ReflectiveDescriptorsKt {
|
||||
public static final fun forClass (Lspace/kscience/dataforge/meta/descriptors/MetaDescriptor$Companion;Lkotlin/reflect/KClass;Lkotlin/jvm/functions/Function1;)Lspace/kscience/dataforge/meta/descriptors/MetaDescriptor;
|
||||
public static synthetic fun forClass$default (Lspace/kscience/dataforge/meta/descriptors/MetaDescriptor$Companion;Lkotlin/reflect/KClass;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lspace/kscience/dataforge/meta/descriptors/MetaDescriptor;
|
||||
}
|
||||
|
||||
public final class space/kscience/dataforge/properties/MetaAsFlowKt {
|
||||
|
@ -10,11 +10,11 @@ import space.kscience.dataforge.meta.ValueType
|
||||
import space.kscience.dataforge.meta.descriptors.MetaDescriptor
|
||||
import space.kscience.dataforge.meta.descriptors.MetaDescriptorBuilder
|
||||
import space.kscience.dataforge.meta.descriptors.node
|
||||
import space.kscience.dataforge.misc.DFExperimental
|
||||
import java.net.URL
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.reflect.full.isSubclassOf
|
||||
import kotlin.reflect.full.memberProperties
|
||||
import kotlin.reflect.typeOf
|
||||
|
||||
|
||||
/**
|
||||
@ -58,9 +58,9 @@ private fun MetaDescriptorBuilder.loadDescriptorFromResource(resource: Descripto
|
||||
}
|
||||
}
|
||||
|
||||
@DFExperimental
|
||||
public fun MetaDescriptor.Companion.forClass(
|
||||
kClass: KClass<out Any>,
|
||||
|
||||
public fun <T : Any> MetaDescriptor.Companion.forClass(
|
||||
kClass: KClass<T>,
|
||||
mod: MetaDescriptorBuilder.() -> Unit = {},
|
||||
): MetaDescriptor = MetaDescriptor {
|
||||
when {
|
||||
@ -79,7 +79,7 @@ public fun MetaDescriptor.Companion.forClass(
|
||||
is DescriptorUrl -> loadDescriptorFromUrl(URL(it.url))
|
||||
}
|
||||
}
|
||||
kClass.memberProperties.forEach { property->
|
||||
kClass.memberProperties.forEach { property ->
|
||||
|
||||
var flag = false
|
||||
|
||||
@ -88,12 +88,6 @@ public fun MetaDescriptor.Companion.forClass(
|
||||
(property.returnType.classifier as? KClass<*>)?.let {
|
||||
from(forClass(it))
|
||||
}
|
||||
//
|
||||
// (property.getDelegate(Unit) as? MetaDelegate<*>)?.descriptor?.let {
|
||||
// from(it)
|
||||
// flag = true
|
||||
// }
|
||||
|
||||
property.annotations.forEach {
|
||||
when (it) {
|
||||
is Description -> {
|
||||
@ -125,6 +119,6 @@ public fun MetaDescriptor.Companion.forClass(
|
||||
mod()
|
||||
}
|
||||
|
||||
@DFExperimental
|
||||
public inline fun <reified T : Scheme> SchemeSpec<T>.autoDescriptor(noinline mod: MetaDescriptorBuilder.() -> Unit = {}): MetaDescriptor =
|
||||
MetaDescriptor.forClass(T::class, mod)
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
public inline fun <reified T : Scheme> SchemeSpec<T>.autoDescriptor( noinline mod: MetaDescriptorBuilder.() -> Unit = {}): MetaDescriptor =
|
||||
MetaDescriptor.forClass(typeOf<T>().classifier as KClass<T>, mod)
|
@ -1,5 +1,3 @@
|
||||
@file:OptIn(DFExperimental::class)
|
||||
|
||||
package space.kscience.dataforge.descriptors
|
||||
|
||||
import kotlinx.serialization.encodeToString
|
||||
@ -10,9 +8,8 @@ import space.kscience.dataforge.meta.SchemeSpec
|
||||
import space.kscience.dataforge.meta.descriptors.MetaDescriptor
|
||||
import space.kscience.dataforge.meta.int
|
||||
import space.kscience.dataforge.meta.string
|
||||
import space.kscience.dataforge.misc.DFExperimental
|
||||
|
||||
private class TestScheme : Scheme() {
|
||||
private class TestScheme: Scheme(){
|
||||
|
||||
@Description("A")
|
||||
val a by string()
|
||||
@ -20,17 +17,15 @@ private class TestScheme : Scheme() {
|
||||
@Description("B")
|
||||
val b by int()
|
||||
|
||||
val c by int()
|
||||
|
||||
companion object : SchemeSpec<TestScheme>(::TestScheme) {
|
||||
companion object: SchemeSpec<TestScheme>(::TestScheme){
|
||||
override val descriptor: MetaDescriptor = autoDescriptor()
|
||||
}
|
||||
}
|
||||
|
||||
class TestAutoDescriptors {
|
||||
@Test
|
||||
fun autoDescriptor() {
|
||||
fun autoDescriptor(){
|
||||
val autoDescriptor = MetaDescriptor.forClass(TestScheme::class)
|
||||
println(Json { prettyPrint = true }.encodeToString(autoDescriptor))
|
||||
println(Json{prettyPrint = true}.encodeToString(autoDescriptor))
|
||||
}
|
||||
}
|
@ -1,14 +1,11 @@
|
||||
package space.kscience.dataforge.actions
|
||||
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.flow.collect
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import space.kscience.dataforge.data.DataSink
|
||||
import space.kscience.dataforge.data.DataTree
|
||||
import space.kscience.dataforge.data.DataUpdate
|
||||
import space.kscience.dataforge.data.launchUpdate
|
||||
import kotlinx.coroutines.launch
|
||||
import space.kscience.dataforge.data.*
|
||||
import space.kscience.dataforge.meta.Meta
|
||||
import space.kscience.dataforge.misc.UnsafeKType
|
||||
import space.kscience.dataforge.misc.DFInternal
|
||||
import space.kscience.dataforge.names.Name
|
||||
import space.kscience.dataforge.names.startsWith
|
||||
import kotlin.reflect.KType
|
||||
@ -32,7 +29,7 @@ public abstract class AbstractAction<T, R>(
|
||||
* Generate initial content of the output
|
||||
*/
|
||||
protected abstract fun DataSink<R>.generate(
|
||||
source: DataTree<T>,
|
||||
data: DataTree<T>,
|
||||
meta: Meta,
|
||||
)
|
||||
|
||||
@ -43,28 +40,35 @@ public abstract class AbstractAction<T, R>(
|
||||
* @param meta the metadata used for the whole data tree
|
||||
* @param updatedData an updated item
|
||||
*/
|
||||
protected open suspend fun DataSink<R>.update(
|
||||
protected open fun DataSink<R>.update(
|
||||
source: DataTree<T>,
|
||||
meta: Meta,
|
||||
updatedData: DataUpdate<T>,
|
||||
updatedData: NamedData<T>,
|
||||
) {
|
||||
//by default regenerate the whole data set
|
||||
generate(source, meta)
|
||||
}
|
||||
|
||||
@OptIn(UnsafeKType::class)
|
||||
@OptIn(DFInternal::class)
|
||||
override fun execute(
|
||||
source: DataTree<T>,
|
||||
dataSet: DataTree<T>,
|
||||
meta: Meta,
|
||||
updatesScope: CoroutineScope
|
||||
): DataTree<R> = DataTree(outputType) {
|
||||
generate(source, meta)
|
||||
//propagate updates
|
||||
launchUpdate(updatesScope) {
|
||||
source.updates.onEach { update ->
|
||||
update(source, meta, update)
|
||||
}.collect()
|
||||
): DataTree<R> = if (dataSet.isObservable()) {
|
||||
MutableDataTree<R>(outputType, dataSet.updatesScope).apply {
|
||||
generate(dataSet, meta)
|
||||
dataSet.updates().onEach {
|
||||
update(dataSet, meta, it)
|
||||
}.launchIn(updatesScope)
|
||||
|
||||
//close updates when the source is closed
|
||||
updatesScope.launch {
|
||||
dataSet.awaitClose()
|
||||
close()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
DataTree(outputType) {
|
||||
generate(dataSet, meta)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,5 @@
|
||||
package space.kscience.dataforge.actions
|
||||
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.DelicateCoroutinesApi
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import space.kscience.dataforge.data.DataTree
|
||||
import space.kscience.dataforge.meta.Meta
|
||||
import space.kscience.dataforge.misc.DFExperimental
|
||||
@ -16,7 +13,7 @@ public fun interface Action<T, R> {
|
||||
* Transform the data in the node, producing a new node. By default, it is assumed that all calculations are lazy
|
||||
* so not actual computation is started at this moment.
|
||||
*/
|
||||
public fun execute(source: DataTree<T>, meta: Meta, updatesScope: CoroutineScope): DataTree<R>
|
||||
public fun execute(dataSet: DataTree<T>, meta: Meta): DataTree<R>
|
||||
|
||||
public companion object
|
||||
}
|
||||
@ -24,27 +21,23 @@ public fun interface Action<T, R> {
|
||||
/**
|
||||
* A convenience method to transform data using given [action]
|
||||
*/
|
||||
@OptIn(DelicateCoroutinesApi::class)
|
||||
public fun <T, R> DataTree<T>.transform(
|
||||
action: Action<T, R>,
|
||||
meta: Meta = Meta.EMPTY,
|
||||
updateScope: CoroutineScope = GlobalScope,
|
||||
): DataTree<R> = action.execute(this, meta, updateScope)
|
||||
): DataTree<R> = action.execute(this, meta)
|
||||
|
||||
/**
|
||||
* Action composition. The result is terminal if one of its parts is terminal
|
||||
*/
|
||||
public infix fun <T, I, R> Action<T, I>.then(action: Action<I, R>): Action<T, R> = Action { dataSet, meta, scope ->
|
||||
action.execute(this@then.execute(dataSet, meta, scope), meta, scope)
|
||||
public infix fun <T, I, R> Action<T, I>.then(action: Action<I, R>): Action<T, R> = Action { dataSet, meta ->
|
||||
action.execute(this@then.execute(dataSet, meta), meta)
|
||||
}
|
||||
|
||||
@DFExperimental
|
||||
@OptIn(DelicateCoroutinesApi::class)
|
||||
public operator fun <T, R> Action<T, R>.invoke(
|
||||
dataSet: DataTree<T>,
|
||||
meta: Meta = Meta.EMPTY,
|
||||
updateScope: CoroutineScope = GlobalScope,
|
||||
): DataTree<R> = execute(dataSet, meta, updateScope)
|
||||
): DataTree<R> = execute(dataSet, meta)
|
||||
|
||||
|
||||
|
||||
|
@ -6,7 +6,7 @@ import space.kscience.dataforge.meta.MutableMeta
|
||||
import space.kscience.dataforge.meta.seal
|
||||
import space.kscience.dataforge.meta.toMutableMeta
|
||||
import space.kscience.dataforge.misc.DFBuilder
|
||||
import space.kscience.dataforge.misc.UnsafeKType
|
||||
import space.kscience.dataforge.misc.DFInternal
|
||||
import space.kscience.dataforge.names.Name
|
||||
import kotlin.reflect.KType
|
||||
import kotlin.reflect.typeOf
|
||||
@ -48,18 +48,13 @@ public class MapActionBuilder<T, R>(
|
||||
public inline fun <reified R1 : R> result(noinline f: suspend ActionEnv.(T) -> R1): Unit = result(typeOf<R1>(), f)
|
||||
}
|
||||
|
||||
@UnsafeKType
|
||||
public class MapAction<T, R>(
|
||||
@PublishedApi
|
||||
internal class MapAction<T, R>(
|
||||
outputType: KType,
|
||||
private val block: MapActionBuilder<T, R>.() -> Unit,
|
||||
) : AbstractAction<T, R>(outputType) {
|
||||
|
||||
private fun DataSink<R>.mapOne(name: Name, data: Data<T>?, meta: Meta) {
|
||||
//fast return for null data
|
||||
if (data == null) {
|
||||
put(name, null)
|
||||
return
|
||||
}
|
||||
private fun DataSink<R>.mapOne(name: Name, data: Data<T>, meta: Meta) {
|
||||
// Creating a new environment for action using **old** name, old meta and task meta
|
||||
val env = ActionEnv(name, data.meta, meta)
|
||||
|
||||
@ -78,6 +73,7 @@ public class MapAction<T, R>(
|
||||
//getting new meta
|
||||
val newMeta = builder.meta.seal()
|
||||
|
||||
@OptIn(DFInternal::class)
|
||||
val newData = Data(builder.outputType, newMeta, dependencies = listOf(data)) {
|
||||
builder.result(env, data.await())
|
||||
}
|
||||
@ -85,18 +81,12 @@ public class MapAction<T, R>(
|
||||
put(newName, newData)
|
||||
}
|
||||
|
||||
override fun DataSink<R>.generate(source: DataTree<T>, meta: Meta) {
|
||||
source.forEach { mapOne(it.name, it.data, meta) }
|
||||
override fun DataSink<R>.generate(data: DataTree<T>, meta: Meta) {
|
||||
data.forEach { mapOne(it.name, it.data, meta) }
|
||||
}
|
||||
|
||||
|
||||
|
||||
override suspend fun DataSink<R>.update(
|
||||
source: DataTree<T>,
|
||||
meta: Meta,
|
||||
updatedData: DataUpdate<T>,
|
||||
) {
|
||||
mapOne(updatedData.name, updatedData.data, meta)
|
||||
override fun DataSink<R>.update(source: DataTree<T>, meta: Meta, updatedData: NamedData<T>) {
|
||||
mapOne(updatedData.name, updatedData.data, updatedData.meta)
|
||||
}
|
||||
}
|
||||
|
||||
@ -105,7 +95,6 @@ public class MapAction<T, R>(
|
||||
* A one-to-one mapping action
|
||||
*/
|
||||
|
||||
@OptIn(UnsafeKType::class)
|
||||
public inline fun <T, reified R> Action.Companion.mapping(
|
||||
noinline builder: MapActionBuilder<T, R>.() -> Unit,
|
||||
): Action<T, R> = MapAction(typeOf<R>(), builder)
|
||||
|
@ -4,7 +4,7 @@ import space.kscience.dataforge.data.*
|
||||
import space.kscience.dataforge.meta.Meta
|
||||
import space.kscience.dataforge.meta.MutableMeta
|
||||
import space.kscience.dataforge.misc.DFBuilder
|
||||
import space.kscience.dataforge.misc.UnsafeKType
|
||||
import space.kscience.dataforge.misc.DFInternal
|
||||
import space.kscience.dataforge.names.Name
|
||||
import space.kscience.dataforge.names.parseAsName
|
||||
import kotlin.reflect.KType
|
||||
@ -84,8 +84,8 @@ internal class ReduceAction<T, R>(
|
||||
) : AbstractAction<T, R>(outputType) {
|
||||
//TODO optimize reduction. Currently, the whole action recalculates on push
|
||||
|
||||
override fun DataSink<R>.generate(source: DataTree<T>, meta: Meta) {
|
||||
ReduceGroupBuilder<T, R>(meta, outputType).apply(action).buildGroups(source).forEach { group ->
|
||||
override fun DataSink<R>.generate(data: DataTree<T>, meta: Meta) {
|
||||
ReduceGroupBuilder<T, R>(meta, outputType).apply(action).buildGroups(data).forEach { group ->
|
||||
val dataFlow: Map<Name, Data<T>> = group.set.asSequence().fold(HashMap()) { acc, value ->
|
||||
acc.apply {
|
||||
acc[value.name] = value.data
|
||||
@ -97,7 +97,7 @@ internal class ReduceAction<T, R>(
|
||||
val groupMeta = group.meta
|
||||
|
||||
val env = ActionEnv(groupName.parseAsName(), groupMeta, meta)
|
||||
@OptIn(UnsafeKType::class) val res: Data<R> = dataFlow.reduceToData(
|
||||
@OptIn(DFInternal::class) val res: Data<R> = dataFlow.reduceToData(
|
||||
group.outputType,
|
||||
meta = groupMeta
|
||||
) { group.result.invoke(env, it) }
|
||||
|
@ -48,10 +48,10 @@ internal class SplitAction<T, R>(
|
||||
private val action: SplitBuilder<T, R>.() -> Unit,
|
||||
) : AbstractAction<T, R>(outputType) {
|
||||
|
||||
private fun DataSink<R>.splitOne(name: Name, data: Data<T>?, meta: Meta) {
|
||||
val laminate = Laminate(data?.meta, meta)
|
||||
private fun DataSink<R>.splitOne(name: Name, data: Data<T>, meta: Meta) {
|
||||
val laminate = Laminate(data.meta, meta)
|
||||
|
||||
val split = SplitBuilder<T, R>(name, data?.meta ?: Meta.EMPTY).apply(action)
|
||||
val split = SplitBuilder<T, R>(name, data.meta).apply(action)
|
||||
|
||||
|
||||
// apply individual fragment rules to result
|
||||
@ -63,9 +63,6 @@ internal class SplitAction<T, R>(
|
||||
).apply(rule)
|
||||
//data.map<R>(outputType, meta = env.meta) { env.result(it) }.named(fragmentName)
|
||||
|
||||
if (data == null) {
|
||||
put(fragmentName, null)
|
||||
} else {
|
||||
put(
|
||||
fragmentName,
|
||||
@Suppress("OPT_IN_USAGE") Data(outputType, meta = env.meta, dependencies = listOf(data)) {
|
||||
@ -74,18 +71,13 @@ internal class SplitAction<T, R>(
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun DataSink<R>.generate(data: DataTree<T>, meta: Meta) {
|
||||
data.forEach { splitOne(it.name, it.data, meta) }
|
||||
}
|
||||
|
||||
override fun DataSink<R>.generate(source: DataTree<T>, meta: Meta) {
|
||||
source.forEach { splitOne(it.name, it.data, meta) }
|
||||
}
|
||||
|
||||
override suspend fun DataSink<R>.update(
|
||||
source: DataTree<T>,
|
||||
meta: Meta,
|
||||
updatedData: DataUpdate<T>,
|
||||
) {
|
||||
splitOne(updatedData.name, updatedData.data, meta)
|
||||
override fun DataSink<R>.update(source: DataTree<T>, meta: Meta, updatedData: NamedData<T>) {
|
||||
splitOne(updatedData.name, updatedData.data, updatedData.meta)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,8 +4,8 @@ import kotlinx.coroutines.*
|
||||
import space.kscience.dataforge.meta.Meta
|
||||
import space.kscience.dataforge.meta.MetaRepr
|
||||
import space.kscience.dataforge.meta.isEmpty
|
||||
import space.kscience.dataforge.misc.DFInternal
|
||||
import space.kscience.dataforge.misc.DfType
|
||||
import space.kscience.dataforge.misc.UnsafeKType
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
import kotlin.coroutines.EmptyCoroutineContext
|
||||
import kotlin.reflect.KType
|
||||
@ -41,7 +41,7 @@ public interface Data<out T> : Goal<T>, MetaRepr {
|
||||
*/
|
||||
internal val TYPE_OF_NOTHING: KType = typeOf<Unit>()
|
||||
|
||||
public inline fun <reified T> wrapValue(
|
||||
public inline fun <reified T> static(
|
||||
value: T,
|
||||
meta: Meta = Meta.EMPTY,
|
||||
): Data<T> = StaticData(typeOf<T>(), value, meta)
|
||||
@ -50,10 +50,10 @@ public interface Data<out T> : Goal<T>, MetaRepr {
|
||||
* An empty data containing only meta
|
||||
*/
|
||||
@OptIn(DelicateCoroutinesApi::class)
|
||||
public fun buildEmpty(meta: Meta): Data<Nothing> = object : Data<Nothing> {
|
||||
override val type: KType get() = TYPE_OF_NOTHING
|
||||
public fun empty(meta: Meta): Data<Nothing> = object : Data<Nothing> {
|
||||
override val type: KType = TYPE_OF_NOTHING
|
||||
override val meta: Meta = meta
|
||||
override val dependencies: Collection<Goal<*>> get() = emptyList()
|
||||
override val dependencies: Collection<Goal<*>> = emptyList()
|
||||
override val deferred: Deferred<Nothing>
|
||||
get() = GlobalScope.async(start = CoroutineStart.LAZY) {
|
||||
error("The Data is empty and could not be computed")
|
||||
@ -62,8 +62,6 @@ public interface Data<out T> : Goal<T>, MetaRepr {
|
||||
override fun async(coroutineScope: CoroutineScope): Deferred<Nothing> = deferred
|
||||
override fun reset() {}
|
||||
}
|
||||
|
||||
public val EMPTY: Data<Nothing> = buildEmpty(Meta.EMPTY)
|
||||
}
|
||||
}
|
||||
|
||||
@ -89,7 +87,7 @@ public class StaticData<T>(
|
||||
public inline fun <reified T> Data(value: T, meta: Meta = Meta.EMPTY): StaticData<T> =
|
||||
StaticData(typeOf<T>(), value, meta)
|
||||
|
||||
@UnsafeKType
|
||||
@DFInternal
|
||||
public fun <T> Data(
|
||||
type: KType,
|
||||
meta: Meta = Meta.EMPTY,
|
||||
@ -98,7 +96,7 @@ public fun <T> Data(
|
||||
block: suspend () -> T,
|
||||
): Data<T> = LazyData(type, meta, context, dependencies, block)
|
||||
|
||||
@OptIn(UnsafeKType::class)
|
||||
@OptIn(DFInternal::class)
|
||||
public inline fun <reified T> Data(
|
||||
meta: Meta = Meta.EMPTY,
|
||||
context: CoroutineContext = EmptyCoroutineContext,
|
||||
|
@ -1,30 +1,28 @@
|
||||
package space.kscience.dataforge.data
|
||||
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.filter
|
||||
import space.kscience.dataforge.meta.Meta
|
||||
import space.kscience.dataforge.names.Name
|
||||
import space.kscience.dataforge.names.NameToken
|
||||
import space.kscience.dataforge.names.plus
|
||||
import kotlin.reflect.KType
|
||||
|
||||
public fun interface DataFilter {
|
||||
|
||||
public fun accepts(name: Name, meta: Meta?, type: KType): Boolean
|
||||
public fun accepts(name: Name, meta: Meta, type: KType): Boolean
|
||||
|
||||
public companion object {
|
||||
public val EMPTY: DataFilter = DataFilter { _, _, _ -> true }
|
||||
}
|
||||
}
|
||||
|
||||
public fun DataFilter.accepts(data: NamedData<*>): Boolean = accepts(data.name, data.meta, data.type)
|
||||
|
||||
public fun DataFilter.accepts(update: DataUpdate<*>): Boolean = accepts(update.name, update.data?.meta, update.type)
|
||||
|
||||
public fun <T, DU : DataUpdate<T>> Sequence<DU>.filterData(predicate: DataFilter): Sequence<DU> = filter { data ->
|
||||
public fun <T> Sequence<NamedData<T>>.filterData(predicate: DataFilter): Sequence<NamedData<T>> = filter { data ->
|
||||
predicate.accepts(data)
|
||||
}
|
||||
|
||||
public fun <T, DU : DataUpdate<T>> Flow<DU>.filterData(predicate: DataFilter): Flow<DU> = filter { data ->
|
||||
public fun <T> Flow<NamedData<T>>.filterData(predicate: DataFilter): Flow<NamedData<T>> = filter { data ->
|
||||
predicate.accepts(data)
|
||||
}
|
||||
|
||||
@ -43,8 +41,7 @@ public fun <T> DataSource<T>.filterData(
|
||||
public fun <T> ObservableDataSource<T>.filterData(
|
||||
predicate: DataFilter,
|
||||
): ObservableDataSource<T> = object : ObservableDataSource<T> {
|
||||
override val updates: Flow<DataUpdate<T>>
|
||||
get() = this@filterData.updates.filter { predicate.accepts(it) }
|
||||
override fun updates(): Flow<NamedData<T>> = this@filterData.updates().filter { predicate.accepts(it) }
|
||||
|
||||
override val dataType: KType get() = this@filterData.dataType
|
||||
|
||||
@ -52,32 +49,14 @@ public fun <T> ObservableDataSource<T>.filterData(
|
||||
this@filterData.read(name)?.takeIf { predicate.accepts(name, it.meta, it.type) }
|
||||
}
|
||||
|
||||
internal class FilteredDataTree<T>(
|
||||
val source: DataTree<T>,
|
||||
val filter: DataFilter,
|
||||
val branch: Name,
|
||||
override val dataType: KType = source.dataType,
|
||||
) : DataTree<T> {
|
||||
|
||||
override val data: Data<T>?
|
||||
get() = source[branch].takeIf {
|
||||
filter.accepts(Name.EMPTY, it?.meta, it?.type ?: dataType)
|
||||
}
|
||||
|
||||
override val items: Map<NameToken, DataTree<T>>
|
||||
get() = source.branch(branch)?.items
|
||||
?.mapValues { FilteredDataTree(source, filter, branch + it.key) }
|
||||
?.filter { !it.value.isEmpty() }
|
||||
?: emptyMap()
|
||||
|
||||
override val updates: Flow<DataUpdate<T>>
|
||||
get() = source.updates.filter { filter.accepts(it) }
|
||||
}
|
||||
|
||||
|
||||
public fun <T> DataTree<T>.filterData(
|
||||
public fun <T> GenericDataTree<T, *>.filterData(
|
||||
predicate: DataFilter,
|
||||
): DataTree<T> = FilteredDataTree(this, predicate, Name.EMPTY)
|
||||
): DataTree<T> = asSequence().filterData(predicate).toTree(dataType)
|
||||
|
||||
public fun <T> GenericObservableDataTree<T, *>.filterData(
|
||||
scope: CoroutineScope,
|
||||
predicate: DataFilter,
|
||||
): ObservableDataTree<T> = asSequence().filterData(predicate).toObservableTree(dataType, scope, updates().filterData(predicate))
|
||||
|
||||
|
||||
///**
|
||||
|
@ -1,159 +0,0 @@
|
||||
package space.kscience.dataforge.data
|
||||
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.channels.BufferOverflow
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
import kotlinx.coroutines.flow.mapNotNull
|
||||
import kotlinx.coroutines.launch
|
||||
import space.kscience.dataforge.misc.UnsafeKType
|
||||
import space.kscience.dataforge.names.*
|
||||
import kotlin.reflect.KType
|
||||
import kotlin.reflect.typeOf
|
||||
|
||||
public interface DataSink<in T> {
|
||||
/**
|
||||
* Put data without notification
|
||||
*/
|
||||
public fun put(name: Name, data: Data<T>?)
|
||||
|
||||
/**
|
||||
* Put data and propagate changes downstream
|
||||
*/
|
||||
public suspend fun update(name: Name, data: Data<T>?)
|
||||
}
|
||||
|
||||
/**
|
||||
* Launch continuous update using
|
||||
*/
|
||||
public fun <T> DataSink<T>.launchUpdate(
|
||||
scope: CoroutineScope,
|
||||
updater: suspend DataSink<T>.() -> Unit,
|
||||
): Job = scope.launch {
|
||||
object : DataSink<T> {
|
||||
override fun put(name: Name, data: Data<T>?) {
|
||||
launch {
|
||||
this@launchUpdate.update(name, data)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun update(name: Name, data: Data<T>?) {
|
||||
this@launchUpdate.update(name, data)
|
||||
}
|
||||
}.updater()
|
||||
}
|
||||
|
||||
/**
|
||||
* A mutable version of [DataTree]
|
||||
*/
|
||||
public interface MutableDataTree<T> : DataTree<T>, DataSink<T> {
|
||||
override var data: Data<T>?
|
||||
|
||||
override val items: Map<NameToken, MutableDataTree<T>>
|
||||
|
||||
public fun getOrCreateItem(token: NameToken): MutableDataTree<T>
|
||||
|
||||
public operator fun set(token: NameToken, data: Data<T>?)
|
||||
|
||||
override fun put(name: Name, data: Data<T>?): Unit = set(name, data)
|
||||
}
|
||||
|
||||
public tailrec operator fun <T> MutableDataTree<T>.set(name: Name, data: Data<T>?): Unit {
|
||||
when (name.length) {
|
||||
0 -> this.data = data
|
||||
1 -> set(name.first(), data)
|
||||
else -> getOrCreateItem(name.first())[name.cutFirst()] = data
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide a mutable subtree if it exists
|
||||
*/
|
||||
public tailrec fun <T> MutableDataTree<T>.branch(name: Name): MutableDataTree<T>? =
|
||||
when (name.length) {
|
||||
0 -> this
|
||||
1 -> items[name.first()]
|
||||
else -> items[name.first()]?.branch(name.cutFirst())
|
||||
}
|
||||
|
||||
private class MutableDataTreeRoot<T>(
|
||||
override val dataType: KType,
|
||||
) : MutableDataTree<T> {
|
||||
|
||||
override val updates = MutableSharedFlow<DataUpdate<T>>(100, onBufferOverflow = BufferOverflow.DROP_LATEST)
|
||||
|
||||
|
||||
inner class MutableDataTreeBranch(val branchName: Name) : MutableDataTree<T> {
|
||||
|
||||
override var data: Data<T>? = null
|
||||
|
||||
override val items = HashMap<NameToken, MutableDataTree<T>>()
|
||||
|
||||
override val updates: Flow<DataUpdate<T>> = this@MutableDataTreeRoot.updates.mapNotNull { update ->
|
||||
update.name.removeFirstOrNull(branchName)?.let {
|
||||
DataUpdate(update.data?.type ?: dataType, it, update.data)
|
||||
}
|
||||
}
|
||||
override val dataType: KType get() = this@MutableDataTreeRoot.dataType
|
||||
|
||||
|
||||
override fun getOrCreateItem(token: NameToken): MutableDataTree<T> =
|
||||
items.getOrPut(token) { MutableDataTreeBranch(branchName + token) }
|
||||
|
||||
|
||||
override fun set(token: NameToken, data: Data<T>?) {
|
||||
val subTree = getOrCreateItem(token)
|
||||
subTree.data = data
|
||||
}
|
||||
|
||||
override suspend fun update(name: Name, data: Data<T>?) {
|
||||
if (name.isEmpty()) {
|
||||
this.data = data
|
||||
this@MutableDataTreeRoot.updates.emit(DataUpdate(data?.type ?: dataType, branchName + name, data))
|
||||
} else {
|
||||
getOrCreateItem(name.first()).update(name.cutFirst(), data)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
override var data: Data<T>? = null
|
||||
|
||||
override val items = HashMap<NameToken, MutableDataTree<T>>()
|
||||
|
||||
override fun getOrCreateItem(token: NameToken): MutableDataTree<T> = items.getOrPut(token) {
|
||||
MutableDataTreeBranch(token.asName())
|
||||
}
|
||||
|
||||
override fun set(token: NameToken, data: Data<T>?) {
|
||||
val subTree = getOrCreateItem(token)
|
||||
subTree.data = data
|
||||
}
|
||||
|
||||
override suspend fun update(name: Name, data: Data<T>?) {
|
||||
if (name.isEmpty()) {
|
||||
this.data = data
|
||||
updates.emit(DataUpdate(data?.type ?: dataType, name, data))
|
||||
} else {
|
||||
getOrCreateItem(name.first()).update(name.cutFirst(), data)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new [MutableDataTree]
|
||||
*/
|
||||
@UnsafeKType
|
||||
public fun <T> MutableDataTree(
|
||||
type: KType,
|
||||
): MutableDataTree<T> = MutableDataTreeRoot<T>(type)
|
||||
|
||||
/**
|
||||
* Create and initialize a observable mutable data tree.
|
||||
*/
|
||||
@OptIn(UnsafeKType::class)
|
||||
public inline fun <reified T> MutableDataTree(
|
||||
generator: MutableDataTree<T>.() -> Unit = {},
|
||||
): MutableDataTree<T> = MutableDataTree<T>(typeOf<T>()).apply { generator() }
|
@ -1,8 +1,9 @@
|
||||
package space.kscience.dataforge.data
|
||||
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.emptyFlow
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.flow.*
|
||||
import space.kscience.dataforge.meta.Meta
|
||||
import space.kscience.dataforge.misc.DFInternal
|
||||
import space.kscience.dataforge.names.*
|
||||
import kotlin.contracts.contract
|
||||
import kotlin.reflect.KType
|
||||
@ -32,42 +33,46 @@ public interface ObservableDataSource<out T> : DataSource<T> {
|
||||
/**
|
||||
* Flow updates made to the data
|
||||
*/
|
||||
public val updates: Flow<DataUpdate<T>>
|
||||
public fun updates(): Flow<NamedData<T>>
|
||||
}
|
||||
|
||||
/**
|
||||
* A tree like structure for data holding
|
||||
*/
|
||||
public interface DataTree<out T> : ObservableDataSource<T> {
|
||||
public interface GenericDataTree<out T, out TR : GenericDataTree<T, TR>> : DataSource<T> {
|
||||
public val self: TR
|
||||
|
||||
public val data: Data<T>?
|
||||
public val items: Map<NameToken, DataTree<T>>
|
||||
public val items: Map<NameToken, TR>
|
||||
|
||||
|
||||
override fun read(name: Name): Data<T>? = when (name.length) {
|
||||
0 -> data
|
||||
else -> items[name.first()]?.read(name.cutFirst())
|
||||
}
|
||||
|
||||
/**
|
||||
* Flow updates made to the data
|
||||
*/
|
||||
override val updates: Flow<DataUpdate<T>>
|
||||
|
||||
public companion object {
|
||||
private object EmptyDataTree :
|
||||
DataTree<Nothing> {
|
||||
private object EmptyDataTree : GenericDataTree<Nothing, EmptyDataTree> {
|
||||
override val self: EmptyDataTree get() = this
|
||||
override val data: Data<Nothing>? = null
|
||||
override val items: Map<NameToken, EmptyDataTree> = emptyMap()
|
||||
override val dataType: KType = typeOf<Unit>()
|
||||
|
||||
override fun read(name: Name): Data<Nothing>? = null
|
||||
override val updates: Flow<DataUpdate<Nothing>> get() = emptyFlow()
|
||||
|
||||
}
|
||||
|
||||
public val EMPTY: DataTree<Nothing> = EmptyDataTree
|
||||
public val EMPTY: GenericDataTree<Nothing, *> = EmptyDataTree
|
||||
}
|
||||
}
|
||||
|
||||
public typealias DataTree<T> = GenericDataTree<T, GenericDataTree<T, *>>
|
||||
|
||||
/**
|
||||
* Return a single data in this tree. Throw error if it is not single.
|
||||
*/
|
||||
public fun <T> DataTree<T>.single(): NamedData<T> = asSequence().single()
|
||||
|
||||
/**
|
||||
* An alias for easier access to tree values
|
||||
*/
|
||||
@ -88,44 +93,238 @@ public fun <T> DataTree<T>.asSequence(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Walk the data tree depth-first.
|
||||
*
|
||||
* @return a [Sequence] of pairs [Name]-[DataTree] for all nodes including the root one.
|
||||
*/
|
||||
public fun <T> DataTree<T>.walk(
|
||||
namePrefix: Name = Name.EMPTY,
|
||||
): Sequence<Pair<Name, DataTree<T>>> = sequence {
|
||||
yield(namePrefix to this@walk)
|
||||
items.forEach { (token, tree) ->
|
||||
yieldAll(tree.walk(namePrefix + token))
|
||||
}
|
||||
}
|
||||
|
||||
public val DataTree<*>.meta: Meta? get() = data?.meta
|
||||
|
||||
/**
|
||||
* Provide subtree if it exists
|
||||
*/
|
||||
public tailrec fun <T> DataTree<T>.branch(name: Name): DataTree<T>? =
|
||||
public tailrec fun <T, TR : GenericDataTree<T, TR>> GenericDataTree<T, TR>.branch(name: Name): TR? =
|
||||
when (name.length) {
|
||||
0 -> this
|
||||
0 -> self
|
||||
1 -> items[name.first()]
|
||||
else -> items[name.first()]?.branch(name.cutFirst())
|
||||
}
|
||||
|
||||
public fun <T> DataTree<T>.branch(name: String): DataTree<T>? =
|
||||
public fun <T, TR : GenericDataTree<T, TR>> GenericDataTree<T, TR>.branch(name: String): TR? =
|
||||
branch(name.parseAsName())
|
||||
|
||||
public fun DataTree<*>.isEmpty(): Boolean = data == null && items.isEmpty()
|
||||
public fun GenericDataTree<*, *>.isEmpty(): Boolean = data == null && items.isEmpty()
|
||||
|
||||
@PublishedApi
|
||||
internal class FlatDataTree<T>(
|
||||
override val dataType: KType,
|
||||
private val dataSet: Map<Name, Data<T>>,
|
||||
private val prefix: Name,
|
||||
) : GenericDataTree<T, FlatDataTree<T>> {
|
||||
override val self: FlatDataTree<T> get() = this
|
||||
override val data: Data<T>? get() = dataSet[prefix]
|
||||
override val items: Map<NameToken, FlatDataTree<T>>
|
||||
get() = dataSet.keys
|
||||
.filter { it.startsWith(prefix) && it.length > prefix.length }
|
||||
.map { it.tokens[prefix.length] }
|
||||
.associateWith { FlatDataTree(dataType, dataSet, prefix + it) }
|
||||
|
||||
override fun read(name: Name): Data<T>? = dataSet[prefix + name]
|
||||
}
|
||||
|
||||
/**
|
||||
* Represent this flat data map as a [DataTree] without copying it
|
||||
*/
|
||||
public inline fun <reified T> Map<Name, Data<T>>.asTree(): DataTree<T> = FlatDataTree(typeOf<T>(), this, Name.EMPTY)
|
||||
|
||||
internal fun <T> Sequence<NamedData<T>>.toTree(type: KType): DataTree<T> =
|
||||
FlatDataTree(type, associate { it.name to it.data }, Name.EMPTY)
|
||||
|
||||
/**
|
||||
* Collect a sequence of [NamedData] to a [DataTree]
|
||||
*/
|
||||
public inline fun <reified T> Sequence<NamedData<T>>.toTree(): DataTree<T> =
|
||||
FlatDataTree(typeOf<T>(), associate { it.name to it.data }, Name.EMPTY)
|
||||
|
||||
public interface GenericObservableDataTree<out T, out TR : GenericObservableDataTree<T, TR>> :
|
||||
GenericDataTree<T, TR>, ObservableDataSource<T>, AutoCloseable {
|
||||
|
||||
/**
|
||||
* A scope that is used to propagate updates. When this scope is closed, no new updates could arrive.
|
||||
*/
|
||||
public val updatesScope: CoroutineScope
|
||||
|
||||
/**
|
||||
* Close this data tree updates channel
|
||||
*/
|
||||
override fun close() {
|
||||
updatesScope.cancel()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public typealias ObservableDataTree<T> = GenericObservableDataTree<T, GenericObservableDataTree<T, *>>
|
||||
|
||||
/**
|
||||
* Check if the [DataTree] is observable
|
||||
*/
|
||||
public fun <T> DataSource<T>.isObservable(): Boolean {
|
||||
public fun <T> DataTree<T>.isObservable(): Boolean {
|
||||
contract {
|
||||
returns(true) implies (this@isObservable is ObservableDataSource<T>)
|
||||
returns(true) implies (this@isObservable is GenericObservableDataTree<T, *>)
|
||||
}
|
||||
return this is ObservableDataSource<T>
|
||||
return this is GenericObservableDataTree<T, *>
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait for this data tree to stop spawning updates (updatesScope is closed).
|
||||
* If this [DataTree] is not observable, return immediately.
|
||||
*/
|
||||
public suspend fun <T> DataTree<T>.awaitClose() {
|
||||
if (isObservable()) {
|
||||
updatesScope.coroutineContext[Job]?.join()
|
||||
}
|
||||
}
|
||||
|
||||
public fun <T> DataTree<T>.updates(): Flow<NamedData<T>> =
|
||||
if (this is GenericObservableDataTree<T, *>) updates() else emptyFlow()
|
||||
|
||||
public fun interface DataSink<in T> {
|
||||
public fun put(name: Name, data: Data<T>?)
|
||||
}
|
||||
|
||||
@DFInternal
|
||||
public class DataTreeBuilder<T>(private val type: KType) : DataSink<T> {
|
||||
private val map = HashMap<Name, Data<T>>()
|
||||
override fun put(name: Name, data: Data<T>?) {
|
||||
if (data == null) {
|
||||
map.remove(name)
|
||||
} else {
|
||||
map[name] = data
|
||||
}
|
||||
}
|
||||
|
||||
public fun build(): DataTree<T> = FlatDataTree(type, map, Name.EMPTY)
|
||||
}
|
||||
|
||||
@DFInternal
|
||||
public inline fun <T> DataTree(
|
||||
dataType: KType,
|
||||
generator: DataSink<T>.() -> Unit,
|
||||
): DataTree<T> = DataTreeBuilder<T>(dataType).apply(generator).build()
|
||||
|
||||
/**
|
||||
* Create and a data tree.
|
||||
*/
|
||||
@OptIn(DFInternal::class)
|
||||
public inline fun <reified T> DataTree(
|
||||
generator: DataSink<T>.() -> Unit,
|
||||
): DataTree<T> = DataTreeBuilder<T>(typeOf<T>()).apply(generator).build()
|
||||
|
||||
/**
|
||||
* A mutable version of [GenericDataTree]
|
||||
*/
|
||||
public interface MutableDataTree<T> : GenericObservableDataTree<T, MutableDataTree<T>>, DataSink<T> {
|
||||
override var data: Data<T>?
|
||||
|
||||
override val items: Map<NameToken, MutableDataTree<T>>
|
||||
|
||||
public fun getOrCreateItem(token: NameToken): MutableDataTree<T>
|
||||
|
||||
public operator fun set(token: NameToken, data: Data<T>?)
|
||||
|
||||
override fun put(name: Name, data: Data<T>?): Unit = set(name, data)
|
||||
}
|
||||
|
||||
public tailrec operator fun <T> MutableDataTree<T>.set(name: Name, data: Data<T>?): Unit {
|
||||
when (name.length) {
|
||||
0 -> this.data = data
|
||||
1 -> set(name.first(), data)
|
||||
else -> getOrCreateItem(name.first())[name.cutFirst()] = data
|
||||
}
|
||||
}
|
||||
|
||||
private class MutableDataTreeImpl<T>(
|
||||
override val dataType: KType,
|
||||
override val updatesScope: CoroutineScope,
|
||||
) : MutableDataTree<T> {
|
||||
|
||||
|
||||
private val updates = MutableSharedFlow<NamedData<T>>()
|
||||
|
||||
private val children = HashMap<NameToken, MutableDataTree<T>>()
|
||||
|
||||
override var data: Data<T>? = null
|
||||
set(value) {
|
||||
if (!updatesScope.isActive) error("Can't send updates to closed MutableDataTree")
|
||||
field = value
|
||||
if (value != null) {
|
||||
updatesScope.launch {
|
||||
updates.emit(value.named(Name.EMPTY))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override val items: Map<NameToken, MutableDataTree<T>> get() = children
|
||||
|
||||
override fun getOrCreateItem(token: NameToken): MutableDataTree<T> = children.getOrPut(token){
|
||||
MutableDataTreeImpl(dataType, updatesScope)
|
||||
}
|
||||
|
||||
override val self: MutableDataTree<T> get() = this
|
||||
|
||||
override fun set(token: NameToken, data: Data<T>?) {
|
||||
if (!updatesScope.isActive) error("Can't send updates to closed MutableDataTree")
|
||||
val subTree = getOrCreateItem(token)
|
||||
subTree.updates().onEach {
|
||||
updates.emit(it.named(token + it.name))
|
||||
}.launchIn(updatesScope)
|
||||
subTree.data = data
|
||||
}
|
||||
|
||||
override fun updates(): Flow<NamedData<T>> = updates
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new [MutableDataTree]
|
||||
*
|
||||
* @param parentScope a [CoroutineScope] to control data propagation. By default uses [GlobalScope]
|
||||
*/
|
||||
@OptIn(DelicateCoroutinesApi::class)
|
||||
public fun <T> MutableDataTree(
|
||||
type: KType,
|
||||
parentScope: CoroutineScope = GlobalScope,
|
||||
): MutableDataTree<T> = MutableDataTreeImpl<T>(
|
||||
type,
|
||||
CoroutineScope(parentScope.coroutineContext + Job(parentScope.coroutineContext[Job]))
|
||||
)
|
||||
|
||||
/**
|
||||
* Create and initialize a observable mutable data tree.
|
||||
*/
|
||||
@OptIn(DelicateCoroutinesApi::class)
|
||||
public inline fun <reified T> MutableDataTree(
|
||||
parentScope: CoroutineScope = GlobalScope,
|
||||
generator: MutableDataTree<T>.() -> Unit = {},
|
||||
): MutableDataTree<T> = MutableDataTree<T>(typeOf<T>(), parentScope).apply { generator() }
|
||||
|
||||
//@DFInternal
|
||||
//public fun <T> ObservableDataTree(
|
||||
// type: KType,
|
||||
// scope: CoroutineScope,
|
||||
// generator: suspend MutableDataTree<T>.() -> Unit = {},
|
||||
//): ObservableDataTree<T> = MutableDataTree<T>(type, scope.coroutineContext).apply(generator)
|
||||
|
||||
public inline fun <reified T> ObservableDataTree(
|
||||
parentScope: CoroutineScope,
|
||||
generator: MutableDataTree<T>.() -> Unit = {},
|
||||
): ObservableDataTree<T> = MutableDataTree<T>(typeOf<T>(), parentScope).apply(generator)
|
||||
|
||||
|
||||
/**
|
||||
* Collect a [Sequence] into an observable tree with additional [updates]
|
||||
*/
|
||||
public fun <T> Sequence<NamedData<T>>.toObservableTree(
|
||||
dataType: KType,
|
||||
parentScope: CoroutineScope,
|
||||
updates: Flow<NamedData<T>>,
|
||||
): ObservableDataTree<T> = MutableDataTree<T>(dataType, parentScope).apply {
|
||||
this.putAll(this@toObservableTree)
|
||||
updates.onEach {
|
||||
put(it.name, it.data)
|
||||
}.launchIn(updatesScope)
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ package space.kscience.dataforge.data
|
||||
|
||||
import space.kscience.dataforge.meta.get
|
||||
import space.kscience.dataforge.meta.string
|
||||
import space.kscience.dataforge.misc.UnsafeKType
|
||||
import space.kscience.dataforge.misc.DFInternal
|
||||
|
||||
public interface GroupRule {
|
||||
public fun <T> gather(set: DataTree<T>): Map<String, DataTree<T>>
|
||||
@ -31,7 +31,7 @@ public interface GroupRule {
|
||||
* @param defaultTagValue
|
||||
* @return
|
||||
*/
|
||||
@OptIn(UnsafeKType::class)
|
||||
@OptIn(DFInternal::class)
|
||||
public fun byMetaValue(
|
||||
key: String,
|
||||
defaultTagValue: String,
|
||||
@ -40,15 +40,15 @@ public interface GroupRule {
|
||||
override fun <T> gather(
|
||||
set: DataTree<T>,
|
||||
): Map<String, DataTree<T>> {
|
||||
val map = HashMap<String, MutableDataTree<T>>()
|
||||
val map = HashMap<String, DataTreeBuilder<T>>()
|
||||
|
||||
set.forEach { data ->
|
||||
val tagValue: String = data.meta[key]?.string ?: defaultTagValue
|
||||
map.getOrPut(tagValue) { MutableDataTree(set.dataType) }.put(data.name, data.data)
|
||||
map.getOrPut(tagValue) { DataTreeBuilder(set.dataType) }.put(data.name, data.data)
|
||||
}
|
||||
|
||||
|
||||
return map
|
||||
return map.mapValues { it.value.build() }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,4 +20,4 @@ public fun <T> Data<T>.withMeta(newMeta: Meta): Data<T> = if (this is MetaMaskDa
|
||||
* Create a new [Data] with the same computation, but different meta. The meta is created by applying [block] to
|
||||
* the existing data meta.
|
||||
*/
|
||||
public inline fun <T> Data<T>.withMeta(block: MutableMeta.() -> Unit): Data<T> = withMeta(meta.copy(block))
|
||||
public inline fun <T> Data<T>.mapMeta(block: MutableMeta.() -> Unit): Data<T> = withMeta(meta.copy(block))
|
@ -3,30 +3,10 @@ package space.kscience.dataforge.data
|
||||
import space.kscience.dataforge.meta.isEmpty
|
||||
import space.kscience.dataforge.misc.Named
|
||||
import space.kscience.dataforge.names.Name
|
||||
import kotlin.reflect.KType
|
||||
|
||||
/**
|
||||
* An interface implementing a data update event.
|
||||
*
|
||||
* If [data] is null, then corresponding element should be removed.
|
||||
*/
|
||||
public interface DataUpdate<out T> : Named {
|
||||
public val type: KType
|
||||
public interface NamedData<out T> : Named, Data<T> {
|
||||
override val name: Name
|
||||
public val data: Data<T>?
|
||||
}
|
||||
|
||||
public fun <T> DataUpdate(type: KType, name: Name, data: Data<T>?): DataUpdate<T> = object : DataUpdate<T> {
|
||||
override val type: KType = type
|
||||
override val name: Name = name
|
||||
override val data: Data<T>? = data
|
||||
}
|
||||
|
||||
/**
|
||||
* A data coupled to a name.
|
||||
*/
|
||||
public interface NamedData<out T> : DataUpdate<T>, Data<T> {
|
||||
override val data: Data<T>
|
||||
public val data: Data<T>
|
||||
}
|
||||
|
||||
public operator fun NamedData<*>.component1(): Name = name
|
||||
@ -53,5 +33,3 @@ public fun <T> Data<T>.named(name: Name): NamedData<T> = if (this is NamedData)
|
||||
} else {
|
||||
NamedDataImpl(name, this)
|
||||
}
|
||||
|
||||
public fun <T> NamedData(name: Name, data: Data<T>): NamedData<T> = data.named(name)
|
@ -1,12 +1,14 @@
|
||||
package space.kscience.dataforge.data
|
||||
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import space.kscience.dataforge.meta.Meta
|
||||
import space.kscience.dataforge.meta.MutableMeta
|
||||
import space.kscience.dataforge.names.*
|
||||
import space.kscience.dataforge.names.Name
|
||||
import space.kscience.dataforge.names.asName
|
||||
import space.kscience.dataforge.names.isEmpty
|
||||
import space.kscience.dataforge.names.plus
|
||||
|
||||
|
||||
public fun <T> DataSink<T>.put(value: NamedData<T>) {
|
||||
@ -20,27 +22,31 @@ public inline fun <T> DataSink<T>.putAll(
|
||||
if (prefix.isEmpty()) {
|
||||
apply(block)
|
||||
} else {
|
||||
val proxyDataSink = object :DataSink<T>{
|
||||
override fun put(name: Name, data: Data<T>?) {
|
||||
this@putAll.put(prefix + name, data)
|
||||
}
|
||||
|
||||
override suspend fun update(name: Name, data: Data<T>?) {
|
||||
this@putAll.update(prefix + name, data)
|
||||
}
|
||||
|
||||
val proxyDataSink = DataSink { nameWithoutPrefix, data ->
|
||||
this.put(prefix + nameWithoutPrefix, data)
|
||||
}
|
||||
|
||||
proxyDataSink.apply(block)
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated("Use putAll", ReplaceWith("putAll(prefix, block)"))
|
||||
public inline fun <T> DataSink<T>.branch(
|
||||
prefix: Name,
|
||||
block: DataSink<T>.() -> Unit,
|
||||
): Unit = putAll(prefix, block)
|
||||
|
||||
|
||||
public inline fun <T> DataSink<T>.putAll(
|
||||
prefix: String,
|
||||
block: DataSink<T>.() -> Unit,
|
||||
): Unit = putAll(prefix.asName(), block)
|
||||
|
||||
@Deprecated("Use putAll", ReplaceWith("putAll(prefix, block)"))
|
||||
public inline fun <T> DataSink<T>.branch(
|
||||
prefix: String,
|
||||
block: DataSink<T>.() -> Unit,
|
||||
): Unit = putAll(prefix, block)
|
||||
|
||||
public fun <T> DataSink<T>.put(name: String, value: Data<T>) {
|
||||
put(Name.parse(name), value)
|
||||
@ -50,15 +56,20 @@ public fun <T> DataSink<T>.putAll(name: Name, tree: DataTree<T>) {
|
||||
putAll(name) { putAll(tree.asSequence()) }
|
||||
}
|
||||
|
||||
@Deprecated("Use putAll", ReplaceWith("putAll(name, tree)"))
|
||||
public fun <T> DataSink<T>.branch(name: Name, tree: DataTree<T>): Unit = putAll(name, tree)
|
||||
|
||||
public fun <T> DataSink<T>.putAll(name: String, tree: DataTree<T>) {
|
||||
putAll(Name.parse(name)) { putAll(tree.asSequence()) }
|
||||
}
|
||||
|
||||
@Deprecated("Use putAll", ReplaceWith("putAll(name, tree)"))
|
||||
public fun <T> DataSink<T>.branch(name: String, tree: DataTree<T>): Unit = putAll(name, tree)
|
||||
|
||||
/**
|
||||
* Produce lazy [Data] and emit it into the [MutableDataTree]
|
||||
*/
|
||||
public inline fun <reified T> DataSink<T>.putValue(
|
||||
public inline fun <reified T> DataSink<T>.put(
|
||||
name: String,
|
||||
meta: Meta = Meta.EMPTY,
|
||||
noinline producer: suspend () -> T,
|
||||
@ -67,7 +78,7 @@ public inline fun <reified T> DataSink<T>.putValue(
|
||||
put(name, data)
|
||||
}
|
||||
|
||||
public inline fun <reified T> DataSink<T>.putValue(
|
||||
public inline fun <reified T> DataSink<T>.put(
|
||||
name: Name,
|
||||
meta: Meta = Meta.EMPTY,
|
||||
noinline producer: suspend () -> T,
|
||||
@ -79,35 +90,24 @@ public inline fun <reified T> DataSink<T>.putValue(
|
||||
/**
|
||||
* Emit static data with the fixed value
|
||||
*/
|
||||
public inline fun <reified T> DataSink<T>.putValue(
|
||||
public inline fun <reified T> DataSink<T>.wrap(
|
||||
name: String,
|
||||
data: T,
|
||||
meta: Meta = Meta.EMPTY,
|
||||
): Unit = put(name, Data.static(data, meta))
|
||||
|
||||
public inline fun <reified T> DataSink<T>.wrap(
|
||||
name: Name,
|
||||
value: T,
|
||||
data: T,
|
||||
meta: Meta = Meta.EMPTY,
|
||||
): Unit = put(name, Data.wrapValue(value, meta))
|
||||
): Unit = put(name, Data.static(data, meta))
|
||||
|
||||
public inline fun <reified T> DataSink<T>.putValue(
|
||||
public inline fun <reified T> DataSink<T>.wrap(
|
||||
name: String,
|
||||
value: T,
|
||||
meta: Meta = Meta.EMPTY,
|
||||
): Unit = put(name, Data.wrapValue(value, meta))
|
||||
data: T,
|
||||
mutableMeta: MutableMeta.() -> Unit,
|
||||
): Unit = put(Name.parse(name), Data.static(data, Meta(mutableMeta)))
|
||||
|
||||
public inline fun <reified T> DataSink<T>.putValue(
|
||||
name: String,
|
||||
value: T,
|
||||
metaBuilder: MutableMeta.() -> Unit,
|
||||
): Unit = put(Name.parse(name), Data.wrapValue(value, Meta(metaBuilder)))
|
||||
|
||||
public suspend inline fun <reified T> DataSink<T>.updateValue(
|
||||
name: Name,
|
||||
value: T,
|
||||
meta: Meta = Meta.EMPTY,
|
||||
): Unit = update(name, Data.wrapValue(value, meta))
|
||||
|
||||
public suspend inline fun <reified T> DataSink<T>.updateValue(
|
||||
name: String,
|
||||
value: T,
|
||||
meta: Meta = Meta.EMPTY,
|
||||
): Unit = update(name.parseAsName(), Data.wrapValue(value, meta))
|
||||
|
||||
public fun <T> DataSink<T>.putAll(sequence: Sequence<NamedData<T>>) {
|
||||
sequence.forEach {
|
||||
@ -123,12 +123,18 @@ public fun <T> DataSink<T>.putAll(tree: DataTree<T>) {
|
||||
* Copy given data set and mirror its changes to this [DataSink] in [this@setAndObserve]. Returns an update [Job]
|
||||
*/
|
||||
public fun <T : Any> DataSink<T>.putAllAndWatch(
|
||||
scope: CoroutineScope,
|
||||
branchName: Name = Name.EMPTY,
|
||||
source: DataTree<T>,
|
||||
dataSet: ObservableDataTree<T>,
|
||||
): Job {
|
||||
putAll(branchName, source)
|
||||
return source.updates.onEach {
|
||||
update(branchName + it.name, it.data)
|
||||
}.launchIn(scope)
|
||||
putAll(branchName, dataSet)
|
||||
return dataSet.updates().onEach {
|
||||
put(branchName + it.name, it.data)
|
||||
}.launchIn(dataSet.updatesScope)
|
||||
}
|
||||
|
||||
|
||||
@Deprecated("Use putAllAndWatch", ReplaceWith("putAllAndWatch(name, dataSet)"))
|
||||
public fun <T : Any> DataSink<T>.watchBranch(
|
||||
name: Name,
|
||||
dataSet: ObservableDataTree<T>,
|
||||
): Job = putAllAndWatch(name, dataSet)
|
@ -1,7 +1,7 @@
|
||||
package space.kscience.dataforge.data
|
||||
|
||||
import space.kscience.dataforge.meta.*
|
||||
import space.kscience.dataforge.misc.UnsafeKType
|
||||
import space.kscience.dataforge.misc.DFInternal
|
||||
import space.kscience.dataforge.names.Name
|
||||
import space.kscience.dataforge.names.NameToken
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
@ -68,7 +68,7 @@ internal fun Map<*, Data<*>>.joinMeta(): Meta = Meta {
|
||||
}
|
||||
}
|
||||
|
||||
@UnsafeKType
|
||||
@DFInternal
|
||||
public fun <K, T, R> Map<K, Data<T>>.reduceToData(
|
||||
outputType: KType,
|
||||
meta: Meta = joinMeta(),
|
||||
@ -103,7 +103,7 @@ public inline fun <K, T, reified R> Map<K, Data<T>>.reduceToData(
|
||||
|
||||
//Iterable operations
|
||||
|
||||
@UnsafeKType
|
||||
@DFInternal
|
||||
public inline fun <T, R> Iterable<Data<T>>.reduceToData(
|
||||
outputType: KType,
|
||||
meta: Meta = joinMeta(),
|
||||
@ -118,7 +118,7 @@ public inline fun <T, R> Iterable<Data<T>>.reduceToData(
|
||||
transformation(map { it.awaitWithMeta() })
|
||||
}
|
||||
|
||||
@OptIn(UnsafeKType::class)
|
||||
@OptIn(DFInternal::class)
|
||||
public inline fun <T, reified R> Iterable<Data<T>>.reduceToData(
|
||||
meta: Meta = joinMeta(),
|
||||
coroutineContext: CoroutineContext = EmptyCoroutineContext,
|
||||
@ -141,7 +141,7 @@ public inline fun <T, reified R> Iterable<Data<T>>.foldToData(
|
||||
/**
|
||||
* Transform an [Iterable] of [NamedData] to a single [Data].
|
||||
*/
|
||||
@UnsafeKType
|
||||
@DFInternal
|
||||
public inline fun <T, R> Iterable<NamedData<T>>.reduceNamedToData(
|
||||
outputType: KType,
|
||||
meta: Meta = joinMeta(),
|
||||
@ -156,7 +156,7 @@ public inline fun <T, R> Iterable<NamedData<T>>.reduceNamedToData(
|
||||
transformation(map { it.awaitWithMeta() })
|
||||
}
|
||||
|
||||
@OptIn(UnsafeKType::class)
|
||||
@OptIn(DFInternal::class)
|
||||
public inline fun <T, reified R> Iterable<NamedData<T>>.reduceNamedToData(
|
||||
meta: Meta = joinMeta(),
|
||||
coroutineContext: CoroutineContext = EmptyCoroutineContext,
|
||||
@ -181,8 +181,7 @@ public inline fun <T, reified R> Iterable<NamedData<T>>.foldNamedToData(
|
||||
|
||||
//DataSet operations
|
||||
|
||||
|
||||
@UnsafeKType
|
||||
@DFInternal
|
||||
public suspend fun <T, R> DataTree<T>.transform(
|
||||
outputType: KType,
|
||||
metaTransform: MutableMeta.() -> Unit = {},
|
||||
@ -199,7 +198,7 @@ public suspend fun <T, R> DataTree<T>.transform(
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(UnsafeKType::class)
|
||||
@OptIn(DFInternal::class)
|
||||
public suspend inline fun <T, reified R> DataTree<T>.transform(
|
||||
noinline metaTransform: MutableMeta.() -> Unit = {},
|
||||
coroutineContext: CoroutineContext = EmptyCoroutineContext,
|
||||
|
@ -1,112 +0,0 @@
|
||||
package space.kscience.dataforge.data
|
||||
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
import kotlinx.coroutines.flow.mapNotNull
|
||||
import kotlinx.coroutines.sync.Mutex
|
||||
import kotlinx.coroutines.sync.withLock
|
||||
import space.kscience.dataforge.misc.UnsafeKType
|
||||
import space.kscience.dataforge.names.*
|
||||
import kotlin.reflect.KType
|
||||
import kotlin.reflect.typeOf
|
||||
|
||||
|
||||
private class FlatDataTree<T>(
|
||||
override val dataType: KType,
|
||||
private val dataSet: Map<Name, Data<T>>,
|
||||
private val sourceUpdates: Flow<DataUpdate<T>>,
|
||||
private val prefix: Name,
|
||||
) : DataTree<T> {
|
||||
override val data: Data<T>? get() = dataSet[prefix]
|
||||
override val items: Map<NameToken, FlatDataTree<T>>
|
||||
get() = dataSet.keys
|
||||
.filter { it.startsWith(prefix) && it.length > prefix.length }
|
||||
.map { it.tokens[prefix.length] }
|
||||
.associateWith { FlatDataTree(dataType, dataSet, sourceUpdates, prefix + it) }
|
||||
|
||||
override fun read(name: Name): Data<T>? = dataSet[prefix + name]
|
||||
|
||||
override val updates: Flow<DataUpdate<T>> =
|
||||
sourceUpdates.mapNotNull { update ->
|
||||
update.name.removeFirstOrNull(prefix)?.let { DataUpdate(dataType, it, update.data) }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A builder for static [DataTree].
|
||||
*/
|
||||
private class DataTreeBuilder<T>(
|
||||
private val type: KType,
|
||||
initialData: Map<Name, Data<T>> = emptyMap(),
|
||||
) : DataSink<T> {
|
||||
|
||||
private val map = HashMap<Name, Data<T>>(initialData)
|
||||
|
||||
private val mutex = Mutex()
|
||||
|
||||
private val updatesFlow = MutableSharedFlow<DataUpdate<T>>()
|
||||
|
||||
override fun put(name: Name, data: Data<T>?) {
|
||||
if (data == null) {
|
||||
map.remove(name)
|
||||
} else {
|
||||
map[name] = data
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun update(name: Name, data: Data<T>?) {
|
||||
mutex.withLock {
|
||||
if (data == null) {
|
||||
map.remove(name)
|
||||
} else {
|
||||
map.put(name, data)
|
||||
}
|
||||
}
|
||||
updatesFlow.emit(DataUpdate(data?.type ?: type, name, data))
|
||||
}
|
||||
|
||||
public fun build(): DataTree<T> = FlatDataTree(type, map, updatesFlow, Name.EMPTY)
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a static [DataTree]
|
||||
*/
|
||||
@UnsafeKType
|
||||
public fun <T> DataTree(
|
||||
dataType: KType,
|
||||
generator: DataSink<T>.() -> Unit,
|
||||
): DataTree<T> = DataTreeBuilder<T>(dataType).apply(generator).build()
|
||||
|
||||
/**
|
||||
* Create and a data tree.
|
||||
*/
|
||||
@OptIn(UnsafeKType::class)
|
||||
public inline fun <reified T> DataTree(
|
||||
noinline generator: DataSink<T>.() -> Unit,
|
||||
): DataTree<T> = DataTree(typeOf<T>(), generator)
|
||||
|
||||
|
||||
/**
|
||||
* Represent this flat data map as a [DataTree] without copying it
|
||||
*/
|
||||
@UnsafeKType
|
||||
public fun <T> Map<Name, Data<T>>.asTree(type: KType): DataTree<T> =
|
||||
DataTreeBuilder(type, this).build()
|
||||
|
||||
/**
|
||||
* Represent this flat data map as a [DataTree] without copying it
|
||||
*/
|
||||
@OptIn(UnsafeKType::class)
|
||||
public inline fun <reified T> Map<Name, Data<T>>.asTree(): DataTree<T> = asTree(typeOf<T>())
|
||||
|
||||
|
||||
@UnsafeKType
|
||||
public fun <T> Sequence<NamedData<T>>.toTree(type: KType): DataTree<T> =
|
||||
DataTreeBuilder(type, associate { it.name to it.data }).build()
|
||||
|
||||
|
||||
/**
|
||||
* Collect a sequence of [NamedData] to a [DataTree]
|
||||
*/
|
||||
@OptIn(UnsafeKType::class)
|
||||
public inline fun <reified T> Sequence<NamedData<T>>.toTree(): DataTree<T> = toTree(typeOf<T>())
|
@ -1,73 +0,0 @@
|
||||
package space.kscience.dataforge.data
|
||||
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.flow.collect
|
||||
import kotlinx.coroutines.flow.take
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import space.kscience.dataforge.names.asName
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.time.Duration.Companion.milliseconds
|
||||
|
||||
|
||||
internal class DataTreeBuilderTest {
|
||||
@Test
|
||||
fun testTreeBuild() = runTest(timeout = 500.milliseconds) {
|
||||
val node = DataTree<Any> {
|
||||
putAll("primary") {
|
||||
putValue("a", "a")
|
||||
putValue("b", "b")
|
||||
}
|
||||
putValue("c.d", "c.d")
|
||||
putValue("c.f", "c.f")
|
||||
}
|
||||
assertEquals("a", node["primary.a"]?.await())
|
||||
assertEquals("b", node["primary.b"]?.await())
|
||||
assertEquals("c.d", node["c.d"]?.await())
|
||||
assertEquals("c.f", node["c.f"]?.await())
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testDataUpdate() = runTest(timeout = 500.milliseconds) {
|
||||
val updateData = DataTree<Any> {
|
||||
putAll("update") {
|
||||
put("a", Data.wrapValue("a"))
|
||||
put("b", Data.wrapValue("b"))
|
||||
}
|
||||
}
|
||||
|
||||
val node = DataTree<Any> {
|
||||
putAll("primary") {
|
||||
putValue("a", "a")
|
||||
putValue("b", "b")
|
||||
}
|
||||
putValue("root", "root")
|
||||
putAll(updateData)
|
||||
}
|
||||
|
||||
assertEquals("a", node["update.a"]?.await())
|
||||
assertEquals("a", node["primary.a"]?.await())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testDynamicUpdates() = runTest(timeout = 500.milliseconds) {
|
||||
var job: Job? = null
|
||||
|
||||
val subNode = MutableDataTree<Int>()
|
||||
|
||||
val rootNode = MutableDataTree<Int>() {
|
||||
job = putAllAndWatch(this@runTest, "sub".asName(), subNode)
|
||||
}
|
||||
|
||||
repeat(10) {
|
||||
subNode.updateValue("value[$it]", it)
|
||||
}
|
||||
|
||||
rootNode.updates.take(10).collect()
|
||||
assertEquals(9, rootNode["sub.value[9]"]?.await())
|
||||
assertEquals(8, rootNode["sub.value[8]"]?.await())
|
||||
|
||||
job?.cancel()
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package space.kscience.dataforge.data
|
||||
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.filter
|
||||
import space.kscience.dataforge.misc.DFInternal
|
||||
@ -24,40 +25,32 @@ private fun <R> Data<*>.castOrNull(type: KType): Data<R>? =
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@DFInternal
|
||||
public fun <R> Sequence<DataUpdate<*>>.filterByDataType(type: KType): Sequence<NamedData<R>> =
|
||||
public fun <R> Sequence<NamedData<*>>.filterByDataType(type: KType): Sequence<NamedData<R>> =
|
||||
filter { it.type.isSubtypeOf(type) } as Sequence<NamedData<R>>
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@DFInternal
|
||||
public fun <R> Flow<DataUpdate<*>>.filterByDataType(type: KType): Flow<NamedData<R>> =
|
||||
public fun <R> Flow<NamedData<*>>.filterByDataType(type: KType): Flow<NamedData<R>> =
|
||||
filter { it.type.isSubtypeOf(type) } as Flow<NamedData<R>>
|
||||
|
||||
/**
|
||||
* Select all data matching given type and filters. Does not modify paths
|
||||
*
|
||||
* @param filter additional filtering condition based on item name and meta. By default, accepts all
|
||||
* @param predicate additional filtering condition based on item name and meta. By default, accepts all
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@DFInternal
|
||||
public fun <R> DataTree<*>.filterByType(
|
||||
type: KType,
|
||||
branch: Name = Name.EMPTY,
|
||||
filter: DataFilter = DataFilter.EMPTY,
|
||||
): DataTree<R> {
|
||||
val filterWithType = DataFilter { name, meta, dataType ->
|
||||
filter.accepts(name, meta, dataType) && dataType.isSubtypeOf(type)
|
||||
}
|
||||
return FilteredDataTree(this, filterWithType, branch, type) as DataTree<R>
|
||||
}
|
||||
predicate: DataFilter = DataFilter.EMPTY,
|
||||
): DataTree<R> = asSequence().filterByDataType<R>(type).filterData(predicate).toTree(type)
|
||||
|
||||
/**
|
||||
* Select a single datum of the appropriate type
|
||||
*/
|
||||
@OptIn(DFInternal::class)
|
||||
public inline fun <reified R : Any> DataTree<*>.filterByType(
|
||||
branch: Name = Name.EMPTY,
|
||||
filter: DataFilter = DataFilter.EMPTY,
|
||||
): DataTree<R> = filterByType(typeOf<R>(), branch, filter = filter)
|
||||
predicate: DataFilter = DataFilter.EMPTY,
|
||||
): DataTree<R> = filterByType(typeOf<R>(), predicate)
|
||||
|
||||
/**
|
||||
* Select a single datum if it is present and of given [type]
|
||||
@ -70,3 +63,25 @@ public inline fun <reified R : Any> DataTree<*>.getByType(name: Name): NamedData
|
||||
|
||||
public inline fun <reified R : Any> DataTree<*>.getByType(name: String): NamedData<R>? =
|
||||
this@getByType.getByType(typeOf<R>(), Name.parse(name))
|
||||
|
||||
/**
|
||||
* Select all data matching given type and filters. Does not modify paths
|
||||
*
|
||||
* @param predicate additional filtering condition based on item name and meta. By default, accepts all
|
||||
*/
|
||||
@DFInternal
|
||||
public fun <R> ObservableDataTree<*>.filterByType(
|
||||
type: KType,
|
||||
scope: CoroutineScope,
|
||||
predicate: DataFilter = DataFilter.EMPTY,
|
||||
): ObservableDataTree<R> = asSequence()
|
||||
.filterByDataType<R>(type)
|
||||
.filterData(predicate)
|
||||
.toObservableTree(type, scope, updates().filterByDataType<R>(type).filterData(predicate))
|
||||
|
||||
|
||||
@OptIn(DFInternal::class)
|
||||
public inline fun <reified R> ObservableDataTree<*>.filterByType(
|
||||
scope: CoroutineScope,
|
||||
predicate: DataFilter = DataFilter.EMPTY,
|
||||
): ObservableDataTree<R> = filterByType(typeOf<R>(), scope, predicate)
|
@ -14,14 +14,14 @@ public infix fun <T : Any> String.put(data: Data<T>): Unit =
|
||||
* Append node
|
||||
*/
|
||||
context(DataSink<T>)
|
||||
public infix fun <T : Any> String.putAll(dataSet: DataTree<T>): Unit =
|
||||
public infix fun <T : Any> String.put(dataSet: DataTree<T>): Unit =
|
||||
putAll(this, dataSet)
|
||||
|
||||
/**
|
||||
* Build and append node
|
||||
*/
|
||||
context(DataSink<T>)
|
||||
public infix fun <T : Any> String.putAll(
|
||||
public infix fun <T : Any> String.put(
|
||||
block: DataSink<T>.() -> Unit,
|
||||
): Unit = putAll(Name.parse(this), block)
|
||||
|
||||
|
@ -1,24 +1,22 @@
|
||||
package space.kscience.dataforge.data
|
||||
|
||||
import kotlinx.coroutines.flow.collect
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.coroutines.flow.take
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.jupiter.api.Test
|
||||
import space.kscience.dataforge.actions.Action
|
||||
import space.kscience.dataforge.actions.invoke
|
||||
import space.kscience.dataforge.actions.mapping
|
||||
import space.kscience.dataforge.misc.DFExperimental
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.time.Duration.Companion.milliseconds
|
||||
|
||||
@OptIn(DFExperimental::class)
|
||||
internal class ActionsTest {
|
||||
@Test
|
||||
fun testStaticMapAction() = runTest(timeout = 500.milliseconds) {
|
||||
fun testStaticMapAction() = runTest {
|
||||
val data: DataTree<Int> = DataTree {
|
||||
repeat(10) {
|
||||
putValue(it.toString(), it)
|
||||
wrap(it.toString(), it)
|
||||
}
|
||||
}
|
||||
|
||||
@ -30,7 +28,7 @@ internal class ActionsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testDynamicMapAction() = runTest(timeout = 500.milliseconds) {
|
||||
fun testDynamicMapAction() = runBlocking {
|
||||
val source: MutableDataTree<Int> = MutableDataTree()
|
||||
|
||||
val plusOne = Action.mapping<Int, Int> {
|
||||
@ -41,9 +39,13 @@ internal class ActionsTest {
|
||||
|
||||
|
||||
repeat(10) {
|
||||
source.updateValue(it.toString(), it)
|
||||
source.wrap(it.toString(), it)
|
||||
}
|
||||
result.updates.take(10).onEach { println(it.name) }.collect()
|
||||
|
||||
delay(20)
|
||||
|
||||
source.close()
|
||||
result.awaitClose()
|
||||
|
||||
assertEquals(2, result["1"]?.await())
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
package space.kscience.dataforge.data
|
||||
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import space.kscience.dataforge.misc.DFExperimental
|
||||
import space.kscience.dataforge.names.asName
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
|
||||
internal class DataTreeBuilderTest {
|
||||
@Test
|
||||
fun testTreeBuild() = runTest {
|
||||
val node = DataTree<Any> {
|
||||
"primary" put {
|
||||
wrap("a", "a")
|
||||
wrap("b", "b")
|
||||
}
|
||||
wrap("c.d", "c.d")
|
||||
wrap("c.f", "c.f")
|
||||
}
|
||||
assertEquals("a", node["primary.a"]?.await())
|
||||
assertEquals("b", node["primary.b"]?.await())
|
||||
assertEquals("c.d", node["c.d"]?.await())
|
||||
assertEquals("c.f", node["c.f"]?.await())
|
||||
|
||||
}
|
||||
|
||||
@OptIn(DFExperimental::class)
|
||||
@Test
|
||||
fun testDataUpdate() = runTest {
|
||||
val updateData = DataTree<Any> {
|
||||
"update" put {
|
||||
"a" put Data.static("a")
|
||||
"b" put Data.static("b")
|
||||
}
|
||||
}
|
||||
|
||||
val node = DataTree<Any> {
|
||||
"primary" put {
|
||||
wrap("a", "a")
|
||||
wrap("b", "b")
|
||||
}
|
||||
wrap("root", "root")
|
||||
putAll(updateData)
|
||||
}
|
||||
|
||||
assertEquals("a", node["update.a"]?.await())
|
||||
assertEquals("a", node["primary.a"]?.await())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testDynamicUpdates() = runBlocking {
|
||||
val subNode = MutableDataTree<Int>()
|
||||
|
||||
val rootNode = MutableDataTree<Int> {
|
||||
putAllAndWatch("sub".asName(), subNode)
|
||||
}
|
||||
|
||||
repeat(10) {
|
||||
subNode.wrap("value[$it]", it)
|
||||
}
|
||||
|
||||
delay(20)
|
||||
assertEquals(9, rootNode["sub.value[9]"]?.await())
|
||||
}
|
||||
}
|
@ -6,7 +6,7 @@ import space.kscience.dataforge.io.IOFormatFactory.Companion.IO_FORMAT_TYPE
|
||||
import space.kscience.dataforge.io.MetaFormatFactory.Companion.META_FORMAT_TYPE
|
||||
import space.kscience.dataforge.meta.Meta
|
||||
import space.kscience.dataforge.meta.string
|
||||
import space.kscience.dataforge.misc.UnsafeKType
|
||||
import space.kscience.dataforge.misc.DFInternal
|
||||
import space.kscience.dataforge.names.Name
|
||||
import kotlin.reflect.KType
|
||||
import kotlin.reflect.typeOf
|
||||
@ -19,11 +19,11 @@ public class IOPlugin(meta: Meta) : AbstractPlugin(meta) {
|
||||
}
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@UnsafeKType
|
||||
@DFInternal
|
||||
public fun <T> resolveIOFormat(type: KType, meta: Meta): IOFormat<T>? =
|
||||
ioFormatFactories.singleOrNull { it.type == type }?.build(context, meta) as? IOFormat<T>
|
||||
|
||||
@OptIn(UnsafeKType::class)
|
||||
@OptIn(DFInternal::class)
|
||||
public inline fun <reified T> resolveIOFormat(meta: Meta = Meta.EMPTY): IOFormat<T>? =
|
||||
resolveIOFormat(typeOf<T>(), meta)
|
||||
|
||||
|
@ -1,15 +1,3 @@
|
||||
public final class space/kscience/dataforge/meta/ByteArrayValue : java/lang/Iterable, kotlin/jvm/internal/markers/KMappedMarker, space/kscience/dataforge/meta/Value {
|
||||
public fun <init> ([B)V
|
||||
public fun equals (Ljava/lang/Object;)Z
|
||||
public fun getList ()Ljava/util/List;
|
||||
public fun getType ()Lspace/kscience/dataforge/meta/ValueType;
|
||||
public synthetic fun getValue ()Ljava/lang/Object;
|
||||
public fun getValue ()[B
|
||||
public fun hashCode ()I
|
||||
public fun iterator ()Ljava/util/Iterator;
|
||||
public fun toString ()Ljava/lang/String;
|
||||
}
|
||||
|
||||
public abstract interface class space/kscience/dataforge/meta/Configurable {
|
||||
public abstract fun getMeta ()Lspace/kscience/dataforge/meta/MutableMeta;
|
||||
}
|
||||
@ -42,20 +30,7 @@ public final class space/kscience/dataforge/meta/EnumValue : space/kscience/data
|
||||
}
|
||||
|
||||
public final class space/kscience/dataforge/meta/ExoticValuesKt {
|
||||
public static final fun asValue ([B)Lspace/kscience/dataforge/meta/Value;
|
||||
public static final fun asValue ([D)Lspace/kscience/dataforge/meta/Value;
|
||||
public static final fun byteArray (Lspace/kscience/dataforge/meta/MetaProvider;[BLspace/kscience/dataforge/names/Name;)Lkotlin/properties/ReadOnlyProperty;
|
||||
public static final fun byteArray (Lspace/kscience/dataforge/meta/MutableMetaProvider;[BLspace/kscience/dataforge/names/Name;)Lkotlin/properties/ReadWriteProperty;
|
||||
public static synthetic fun byteArray$default (Lspace/kscience/dataforge/meta/MetaProvider;[BLspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lkotlin/properties/ReadOnlyProperty;
|
||||
public static synthetic fun byteArray$default (Lspace/kscience/dataforge/meta/MutableMetaProvider;[BLspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lkotlin/properties/ReadWriteProperty;
|
||||
public static final fun doubleArray (Lspace/kscience/dataforge/meta/MetaProvider;[DLspace/kscience/dataforge/names/Name;)Lkotlin/properties/ReadOnlyProperty;
|
||||
public static final fun doubleArray (Lspace/kscience/dataforge/meta/MutableMetaProvider;[DLspace/kscience/dataforge/names/Name;)Lkotlin/properties/ReadWriteProperty;
|
||||
public static synthetic fun doubleArray$default (Lspace/kscience/dataforge/meta/MetaProvider;[DLspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lkotlin/properties/ReadOnlyProperty;
|
||||
public static synthetic fun doubleArray$default (Lspace/kscience/dataforge/meta/MutableMetaProvider;[DLspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lkotlin/properties/ReadWriteProperty;
|
||||
public static final fun getByteArray (Lspace/kscience/dataforge/meta/Meta;)[B
|
||||
public static final fun getByteArray (Lspace/kscience/dataforge/meta/Value;)[B
|
||||
public static final fun getDoubleArray (Lspace/kscience/dataforge/meta/Meta;)[D
|
||||
public static final fun getDoubleArray (Lspace/kscience/dataforge/meta/Value;)[D
|
||||
public static final fun lazyParseValue (Ljava/lang/String;)Lspace/kscience/dataforge/meta/LazyParsedValue;
|
||||
}
|
||||
|
||||
@ -224,56 +199,53 @@ public final class space/kscience/dataforge/meta/MetaConverterKt {
|
||||
public static final fun convertNullable (Lspace/kscience/dataforge/meta/MetaConverter;Ljava/lang/Object;)Lspace/kscience/dataforge/meta/Meta;
|
||||
}
|
||||
|
||||
public abstract interface class space/kscience/dataforge/meta/MetaDelegate : kotlin/properties/ReadOnlyProperty, space/kscience/dataforge/meta/descriptors/Described {
|
||||
}
|
||||
|
||||
public final class space/kscience/dataforge/meta/MetaDelegateKt {
|
||||
public static final fun boolean (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
public static final fun boolean (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;Lkotlin/jvm/functions/Function0;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
public static final fun boolean (Lspace/kscience/dataforge/meta/MetaProvider;ZLspace/kscience/dataforge/names/Name;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
public static synthetic fun boolean$default (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
public static synthetic fun boolean$default (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;Lkotlin/jvm/functions/Function0;ILjava/lang/Object;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
public static synthetic fun boolean$default (Lspace/kscience/dataforge/meta/MetaProvider;ZLspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
public static final fun double (Lspace/kscience/dataforge/meta/MetaProvider;DLspace/kscience/dataforge/names/Name;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
public static final fun double (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
public static synthetic fun double$default (Lspace/kscience/dataforge/meta/MetaProvider;DLspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
public static synthetic fun double$default (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
public static final fun float (Lspace/kscience/dataforge/meta/MetaProvider;FLspace/kscience/dataforge/names/Name;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
public static final fun float (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
public static synthetic fun float$default (Lspace/kscience/dataforge/meta/MetaProvider;FLspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
public static synthetic fun float$default (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
public static final fun int (Lspace/kscience/dataforge/meta/MetaProvider;ILspace/kscience/dataforge/names/Name;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
public static final fun int (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
public static synthetic fun int$default (Lspace/kscience/dataforge/meta/MetaProvider;ILspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
public static synthetic fun int$default (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
public static final fun listOfSpec (Lspace/kscience/dataforge/meta/Meta;Lspace/kscience/dataforge/meta/MetaSpec;Lspace/kscience/dataforge/names/Name;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
public static synthetic fun listOfSpec$default (Lspace/kscience/dataforge/meta/Meta;Lspace/kscience/dataforge/meta/MetaSpec;Lspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
public static final fun long (Lspace/kscience/dataforge/meta/MetaProvider;JLspace/kscience/dataforge/names/Name;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
public static final fun long (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
public static synthetic fun long$default (Lspace/kscience/dataforge/meta/MetaProvider;JLspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
public static synthetic fun long$default (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
public static final fun boolean (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;)Lkotlin/properties/ReadOnlyProperty;
|
||||
public static final fun boolean (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;Lkotlin/jvm/functions/Function0;)Lkotlin/properties/ReadOnlyProperty;
|
||||
public static final fun boolean (Lspace/kscience/dataforge/meta/MetaProvider;ZLspace/kscience/dataforge/names/Name;)Lkotlin/properties/ReadOnlyProperty;
|
||||
public static synthetic fun boolean$default (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lkotlin/properties/ReadOnlyProperty;
|
||||
public static synthetic fun boolean$default (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;Lkotlin/jvm/functions/Function0;ILjava/lang/Object;)Lkotlin/properties/ReadOnlyProperty;
|
||||
public static synthetic fun boolean$default (Lspace/kscience/dataforge/meta/MetaProvider;ZLspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lkotlin/properties/ReadOnlyProperty;
|
||||
public static final fun double (Lspace/kscience/dataforge/meta/MetaProvider;DLspace/kscience/dataforge/names/Name;)Lkotlin/properties/ReadOnlyProperty;
|
||||
public static final fun double (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;)Lkotlin/properties/ReadOnlyProperty;
|
||||
public static synthetic fun double$default (Lspace/kscience/dataforge/meta/MetaProvider;DLspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lkotlin/properties/ReadOnlyProperty;
|
||||
public static synthetic fun double$default (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lkotlin/properties/ReadOnlyProperty;
|
||||
public static final fun float (Lspace/kscience/dataforge/meta/MetaProvider;FLspace/kscience/dataforge/names/Name;)Lkotlin/properties/ReadOnlyProperty;
|
||||
public static final fun float (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;)Lkotlin/properties/ReadOnlyProperty;
|
||||
public static synthetic fun float$default (Lspace/kscience/dataforge/meta/MetaProvider;FLspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lkotlin/properties/ReadOnlyProperty;
|
||||
public static synthetic fun float$default (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lkotlin/properties/ReadOnlyProperty;
|
||||
public static final fun int (Lspace/kscience/dataforge/meta/MetaProvider;ILspace/kscience/dataforge/names/Name;)Lkotlin/properties/ReadOnlyProperty;
|
||||
public static final fun int (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;)Lkotlin/properties/ReadOnlyProperty;
|
||||
public static synthetic fun int$default (Lspace/kscience/dataforge/meta/MetaProvider;ILspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lkotlin/properties/ReadOnlyProperty;
|
||||
public static synthetic fun int$default (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lkotlin/properties/ReadOnlyProperty;
|
||||
public static final fun listOfSpec (Lspace/kscience/dataforge/meta/Meta;Lspace/kscience/dataforge/meta/MetaSpec;Lspace/kscience/dataforge/names/Name;)Lkotlin/properties/ReadOnlyProperty;
|
||||
public static synthetic fun listOfSpec$default (Lspace/kscience/dataforge/meta/Meta;Lspace/kscience/dataforge/meta/MetaSpec;Lspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lkotlin/properties/ReadOnlyProperty;
|
||||
public static final fun long (Lspace/kscience/dataforge/meta/MetaProvider;JLspace/kscience/dataforge/names/Name;)Lkotlin/properties/ReadOnlyProperty;
|
||||
public static final fun long (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;)Lkotlin/properties/ReadOnlyProperty;
|
||||
public static synthetic fun long$default (Lspace/kscience/dataforge/meta/MetaProvider;JLspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lkotlin/properties/ReadOnlyProperty;
|
||||
public static synthetic fun long$default (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lkotlin/properties/ReadOnlyProperty;
|
||||
public static final fun node (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;)Lkotlin/properties/ReadOnlyProperty;
|
||||
public static final fun node (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;Lspace/kscience/dataforge/meta/MetaSpec;)Lkotlin/properties/ReadOnlyProperty;
|
||||
public static final fun node (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;Lspace/kscience/dataforge/meta/descriptors/MetaDescriptor;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
public static synthetic fun node$default (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lkotlin/properties/ReadOnlyProperty;
|
||||
public static synthetic fun node$default (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;Lspace/kscience/dataforge/meta/MetaSpec;ILjava/lang/Object;)Lkotlin/properties/ReadOnlyProperty;
|
||||
public static synthetic fun node$default (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;Lspace/kscience/dataforge/meta/descriptors/MetaDescriptor;ILjava/lang/Object;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
public static final fun number (Lspace/kscience/dataforge/meta/MetaProvider;Ljava/lang/Number;Lspace/kscience/dataforge/names/Name;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
public static final fun number (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
public static final fun number (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;Lkotlin/jvm/functions/Function0;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
public static synthetic fun number$default (Lspace/kscience/dataforge/meta/MetaProvider;Ljava/lang/Number;Lspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
public static synthetic fun number$default (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
public static synthetic fun number$default (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;Lkotlin/jvm/functions/Function0;ILjava/lang/Object;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
public static final fun spec (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/meta/MetaSpec;Lspace/kscience/dataforge/names/Name;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
public static synthetic fun spec$default (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/meta/MetaSpec;Lspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
public static final fun string (Lspace/kscience/dataforge/meta/MetaProvider;Ljava/lang/String;Lspace/kscience/dataforge/names/Name;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
public static final fun string (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
public static final fun string (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;Lkotlin/jvm/functions/Function0;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
public static synthetic fun string$default (Lspace/kscience/dataforge/meta/MetaProvider;Ljava/lang/String;Lspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
public static synthetic fun string$default (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
public static synthetic fun string$default (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;Lkotlin/jvm/functions/Function0;ILjava/lang/Object;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
public static final fun value (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;Lspace/kscience/dataforge/meta/descriptors/MetaDescriptor;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
public static final fun value (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;Lspace/kscience/dataforge/meta/descriptors/MetaDescriptor;Lkotlin/jvm/functions/Function1;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
public static synthetic fun value$default (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;Lspace/kscience/dataforge/meta/descriptors/MetaDescriptor;ILjava/lang/Object;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
public static synthetic fun value$default (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;Lspace/kscience/dataforge/meta/descriptors/MetaDescriptor;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lspace/kscience/dataforge/meta/MetaDelegate;
|
||||
public static final fun number (Lspace/kscience/dataforge/meta/MetaProvider;Ljava/lang/Number;Lspace/kscience/dataforge/names/Name;)Lkotlin/properties/ReadOnlyProperty;
|
||||
public static final fun number (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;)Lkotlin/properties/ReadOnlyProperty;
|
||||
public static final fun number (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;Lkotlin/jvm/functions/Function0;)Lkotlin/properties/ReadOnlyProperty;
|
||||
public static synthetic fun number$default (Lspace/kscience/dataforge/meta/MetaProvider;Ljava/lang/Number;Lspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lkotlin/properties/ReadOnlyProperty;
|
||||
public static synthetic fun number$default (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lkotlin/properties/ReadOnlyProperty;
|
||||
public static synthetic fun number$default (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;Lkotlin/jvm/functions/Function0;ILjava/lang/Object;)Lkotlin/properties/ReadOnlyProperty;
|
||||
public static final fun spec (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/meta/MetaSpec;Lspace/kscience/dataforge/names/Name;)Lkotlin/properties/ReadOnlyProperty;
|
||||
public static synthetic fun spec$default (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/meta/MetaSpec;Lspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lkotlin/properties/ReadOnlyProperty;
|
||||
public static final fun string (Lspace/kscience/dataforge/meta/MetaProvider;Ljava/lang/String;Lspace/kscience/dataforge/names/Name;)Lkotlin/properties/ReadOnlyProperty;
|
||||
public static final fun string (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;)Lkotlin/properties/ReadOnlyProperty;
|
||||
public static final fun string (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;Lkotlin/jvm/functions/Function0;)Lkotlin/properties/ReadOnlyProperty;
|
||||
public static synthetic fun string$default (Lspace/kscience/dataforge/meta/MetaProvider;Ljava/lang/String;Lspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lkotlin/properties/ReadOnlyProperty;
|
||||
public static synthetic fun string$default (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lkotlin/properties/ReadOnlyProperty;
|
||||
public static synthetic fun string$default (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;Lkotlin/jvm/functions/Function0;ILjava/lang/Object;)Lkotlin/properties/ReadOnlyProperty;
|
||||
public static final fun value (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;)Lkotlin/properties/ReadOnlyProperty;
|
||||
public static final fun value (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;Lkotlin/jvm/functions/Function1;)Lkotlin/properties/ReadOnlyProperty;
|
||||
public static synthetic fun value$default (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lkotlin/properties/ReadOnlyProperty;
|
||||
public static synthetic fun value$default (Lspace/kscience/dataforge/meta/MetaProvider;Lspace/kscience/dataforge/names/Name;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lkotlin/properties/ReadOnlyProperty;
|
||||
}
|
||||
|
||||
public final class space/kscience/dataforge/meta/MetaKt {
|
||||
@ -380,7 +352,6 @@ public abstract interface class space/kscience/dataforge/meta/MutableMeta : spac
|
||||
public fun put (Ljava/lang/String;Lspace/kscience/dataforge/meta/MetaRepr;)V
|
||||
public fun put (Ljava/lang/String;Lspace/kscience/dataforge/meta/Value;)V
|
||||
public fun put (Ljava/lang/String;Z)V
|
||||
public fun put (Ljava/lang/String;[B)V
|
||||
public fun put (Ljava/lang/String;[D)V
|
||||
public fun put (Lspace/kscience/dataforge/names/Name;Ljava/lang/Enum;)V
|
||||
public fun put (Lspace/kscience/dataforge/names/Name;Ljava/lang/Number;)V
|
||||
@ -400,64 +371,63 @@ public final class space/kscience/dataforge/meta/MutableMeta$Companion {
|
||||
public final fun serializer ()Lkotlinx/serialization/KSerializer;
|
||||
}
|
||||
|
||||
public abstract interface class space/kscience/dataforge/meta/MutableMetaDelegate : kotlin/properties/ReadWriteProperty, space/kscience/dataforge/meta/descriptors/Described {
|
||||
}
|
||||
|
||||
public final class space/kscience/dataforge/meta/MutableMetaDelegateKt {
|
||||
public static final fun boolean (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/names/Name;)Lspace/kscience/dataforge/meta/MutableMetaDelegate;
|
||||
public static final fun boolean (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/names/Name;Lkotlin/jvm/functions/Function0;)Lspace/kscience/dataforge/meta/MutableMetaDelegate;
|
||||
public static final fun boolean (Lspace/kscience/dataforge/meta/MutableMetaProvider;ZLspace/kscience/dataforge/names/Name;)Lspace/kscience/dataforge/meta/MutableMetaDelegate;
|
||||
public static synthetic fun boolean$default (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lspace/kscience/dataforge/meta/MutableMetaDelegate;
|
||||
public static synthetic fun boolean$default (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/names/Name;Lkotlin/jvm/functions/Function0;ILjava/lang/Object;)Lspace/kscience/dataforge/meta/MutableMetaDelegate;
|
||||
public static synthetic fun boolean$default (Lspace/kscience/dataforge/meta/MutableMetaProvider;ZLspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lspace/kscience/dataforge/meta/MutableMetaDelegate;
|
||||
public static final fun convertable (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/meta/MetaConverter;Lspace/kscience/dataforge/names/Name;)Lspace/kscience/dataforge/meta/MutableMetaDelegate;
|
||||
public static synthetic fun convertable$default (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/meta/MetaConverter;Lspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lspace/kscience/dataforge/meta/MutableMetaDelegate;
|
||||
public static final fun double (Lspace/kscience/dataforge/meta/MutableMetaProvider;DLspace/kscience/dataforge/names/Name;)Lspace/kscience/dataforge/meta/MutableMetaDelegate;
|
||||
public static final fun double (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/names/Name;)Lspace/kscience/dataforge/meta/MutableMetaDelegate;
|
||||
public static synthetic fun double$default (Lspace/kscience/dataforge/meta/MutableMetaProvider;DLspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lspace/kscience/dataforge/meta/MutableMetaDelegate;
|
||||
public static synthetic fun double$default (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lspace/kscience/dataforge/meta/MutableMetaDelegate;
|
||||
public static final fun float (Lspace/kscience/dataforge/meta/MutableMetaProvider;FLspace/kscience/dataforge/names/Name;)Lspace/kscience/dataforge/meta/MutableMetaDelegate;
|
||||
public static final fun float (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/names/Name;)Lspace/kscience/dataforge/meta/MutableMetaDelegate;
|
||||
public static synthetic fun float$default (Lspace/kscience/dataforge/meta/MutableMetaProvider;FLspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lspace/kscience/dataforge/meta/MutableMetaDelegate;
|
||||
public static synthetic fun float$default (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lspace/kscience/dataforge/meta/MutableMetaDelegate;
|
||||
public static final fun int (Lspace/kscience/dataforge/meta/MutableMetaProvider;ILspace/kscience/dataforge/names/Name;)Lspace/kscience/dataforge/meta/MutableMetaDelegate;
|
||||
public static final fun int (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/names/Name;)Lspace/kscience/dataforge/meta/MutableMetaDelegate;
|
||||
public static synthetic fun int$default (Lspace/kscience/dataforge/meta/MutableMetaProvider;ILspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lspace/kscience/dataforge/meta/MutableMetaDelegate;
|
||||
public static synthetic fun int$default (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lspace/kscience/dataforge/meta/MutableMetaDelegate;
|
||||
public static final fun listOfConvertable (Lspace/kscience/dataforge/meta/MutableMeta;Lspace/kscience/dataforge/meta/MetaConverter;Lspace/kscience/dataforge/names/Name;)Lspace/kscience/dataforge/meta/MutableMetaDelegate;
|
||||
public static synthetic fun listOfConvertable$default (Lspace/kscience/dataforge/meta/MutableMeta;Lspace/kscience/dataforge/meta/MetaConverter;Lspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lspace/kscience/dataforge/meta/MutableMetaDelegate;
|
||||
public static final fun listValue (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/names/Name;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Lspace/kscience/dataforge/meta/MutableMetaDelegate;
|
||||
public static synthetic fun listValue$default (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/names/Name;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lspace/kscience/dataforge/meta/MutableMetaDelegate;
|
||||
public static final fun long (Lspace/kscience/dataforge/meta/MutableMetaProvider;JLspace/kscience/dataforge/names/Name;)Lspace/kscience/dataforge/meta/MutableMetaDelegate;
|
||||
public static final fun long (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/names/Name;)Lspace/kscience/dataforge/meta/MutableMetaDelegate;
|
||||
public static synthetic fun long$default (Lspace/kscience/dataforge/meta/MutableMetaProvider;JLspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lspace/kscience/dataforge/meta/MutableMetaDelegate;
|
||||
public static synthetic fun long$default (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lspace/kscience/dataforge/meta/MutableMetaDelegate;
|
||||
public static final fun node (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/names/Name;Lspace/kscience/dataforge/meta/MetaConverter;)Lspace/kscience/dataforge/meta/MutableMetaDelegate;
|
||||
public static final fun node (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/names/Name;Lspace/kscience/dataforge/meta/descriptors/MetaDescriptor;)Lspace/kscience/dataforge/meta/MutableMetaDelegate;
|
||||
public static synthetic fun node$default (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/names/Name;Lspace/kscience/dataforge/meta/MetaConverter;ILjava/lang/Object;)Lspace/kscience/dataforge/meta/MutableMetaDelegate;
|
||||
public static synthetic fun node$default (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/names/Name;Lspace/kscience/dataforge/meta/descriptors/MetaDescriptor;ILjava/lang/Object;)Lspace/kscience/dataforge/meta/MutableMetaDelegate;
|
||||
public static final fun number (Lspace/kscience/dataforge/meta/MutableMetaProvider;Ljava/lang/Number;Lspace/kscience/dataforge/names/Name;)Lspace/kscience/dataforge/meta/MutableMetaDelegate;
|
||||
public static final fun number (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/names/Name;)Lspace/kscience/dataforge/meta/MutableMetaDelegate;
|
||||
public static final fun number (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/names/Name;Lkotlin/jvm/functions/Function0;)Lspace/kscience/dataforge/meta/MutableMetaDelegate;
|
||||
public static synthetic fun number$default (Lspace/kscience/dataforge/meta/MutableMetaProvider;Ljava/lang/Number;Lspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lspace/kscience/dataforge/meta/MutableMetaDelegate;
|
||||
public static synthetic fun number$default (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lspace/kscience/dataforge/meta/MutableMetaDelegate;
|
||||
public static synthetic fun number$default (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/names/Name;Lkotlin/jvm/functions/Function0;ILjava/lang/Object;)Lspace/kscience/dataforge/meta/MutableMetaDelegate;
|
||||
public static final fun numberList (Lspace/kscience/dataforge/meta/MutableMetaProvider;[Ljava/lang/Number;Lspace/kscience/dataforge/names/Name;)Lspace/kscience/dataforge/meta/MutableMetaDelegate;
|
||||
public static synthetic fun numberList$default (Lspace/kscience/dataforge/meta/MutableMetaProvider;[Ljava/lang/Number;Lspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lspace/kscience/dataforge/meta/MutableMetaDelegate;
|
||||
public static final fun string (Lspace/kscience/dataforge/meta/MutableMetaProvider;Ljava/lang/String;Lspace/kscience/dataforge/names/Name;)Lspace/kscience/dataforge/meta/MutableMetaDelegate;
|
||||
public static final fun string (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/names/Name;)Lspace/kscience/dataforge/meta/MutableMetaDelegate;
|
||||
public static final fun string (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/names/Name;Lkotlin/jvm/functions/Function0;)Lspace/kscience/dataforge/meta/MutableMetaDelegate;
|
||||
public static synthetic fun string$default (Lspace/kscience/dataforge/meta/MutableMetaProvider;Ljava/lang/String;Lspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lspace/kscience/dataforge/meta/MutableMetaDelegate;
|
||||
public static synthetic fun string$default (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lspace/kscience/dataforge/meta/MutableMetaDelegate;
|
||||
public static synthetic fun string$default (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/names/Name;Lkotlin/jvm/functions/Function0;ILjava/lang/Object;)Lspace/kscience/dataforge/meta/MutableMetaDelegate;
|
||||
public static final fun stringList (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/names/Name;)Lspace/kscience/dataforge/meta/MutableMetaDelegate;
|
||||
public static final fun stringList (Lspace/kscience/dataforge/meta/MutableMetaProvider;[Ljava/lang/String;Lspace/kscience/dataforge/names/Name;)Lspace/kscience/dataforge/meta/MutableMetaDelegate;
|
||||
public static synthetic fun stringList$default (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lspace/kscience/dataforge/meta/MutableMetaDelegate;
|
||||
public static synthetic fun stringList$default (Lspace/kscience/dataforge/meta/MutableMetaProvider;[Ljava/lang/String;Lspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lspace/kscience/dataforge/meta/MutableMetaDelegate;
|
||||
public static final fun value (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/names/Name;Lkotlin/jvm/functions/Function1;Lspace/kscience/dataforge/meta/descriptors/MetaDescriptor;Lkotlin/jvm/functions/Function1;)Lspace/kscience/dataforge/meta/MutableMetaDelegate;
|
||||
public static final fun value (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/names/Name;Lspace/kscience/dataforge/meta/descriptors/MetaDescriptor;)Lspace/kscience/dataforge/meta/MutableMetaDelegate;
|
||||
public static synthetic fun value$default (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/names/Name;Lkotlin/jvm/functions/Function1;Lspace/kscience/dataforge/meta/descriptors/MetaDescriptor;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lspace/kscience/dataforge/meta/MutableMetaDelegate;
|
||||
public static synthetic fun value$default (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/names/Name;Lspace/kscience/dataforge/meta/descriptors/MetaDescriptor;ILjava/lang/Object;)Lspace/kscience/dataforge/meta/MutableMetaDelegate;
|
||||
public static final fun boolean (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/names/Name;)Lkotlin/properties/ReadWriteProperty;
|
||||
public static final fun boolean (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/names/Name;Lkotlin/jvm/functions/Function0;)Lkotlin/properties/ReadWriteProperty;
|
||||
public static final fun boolean (Lspace/kscience/dataforge/meta/MutableMetaProvider;ZLspace/kscience/dataforge/names/Name;)Lkotlin/properties/ReadWriteProperty;
|
||||
public static synthetic fun boolean$default (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lkotlin/properties/ReadWriteProperty;
|
||||
public static synthetic fun boolean$default (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/names/Name;Lkotlin/jvm/functions/Function0;ILjava/lang/Object;)Lkotlin/properties/ReadWriteProperty;
|
||||
public static synthetic fun boolean$default (Lspace/kscience/dataforge/meta/MutableMetaProvider;ZLspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lkotlin/properties/ReadWriteProperty;
|
||||
public static final fun convertable (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/meta/MetaConverter;Lspace/kscience/dataforge/names/Name;)Lkotlin/properties/ReadWriteProperty;
|
||||
public static synthetic fun convertable$default (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/meta/MetaConverter;Lspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lkotlin/properties/ReadWriteProperty;
|
||||
public static final fun double (Lspace/kscience/dataforge/meta/MutableMetaProvider;DLspace/kscience/dataforge/names/Name;)Lkotlin/properties/ReadWriteProperty;
|
||||
public static final fun double (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/names/Name;)Lkotlin/properties/ReadWriteProperty;
|
||||
public static synthetic fun double$default (Lspace/kscience/dataforge/meta/MutableMetaProvider;DLspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lkotlin/properties/ReadWriteProperty;
|
||||
public static synthetic fun double$default (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lkotlin/properties/ReadWriteProperty;
|
||||
public static final fun doubleArray (Lspace/kscience/dataforge/meta/MutableMetaProvider;[DLspace/kscience/dataforge/names/Name;)Lkotlin/properties/ReadWriteProperty;
|
||||
public static synthetic fun doubleArray$default (Lspace/kscience/dataforge/meta/MutableMetaProvider;[DLspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lkotlin/properties/ReadWriteProperty;
|
||||
public static final fun float (Lspace/kscience/dataforge/meta/MutableMetaProvider;FLspace/kscience/dataforge/names/Name;)Lkotlin/properties/ReadWriteProperty;
|
||||
public static final fun float (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/names/Name;)Lkotlin/properties/ReadWriteProperty;
|
||||
public static synthetic fun float$default (Lspace/kscience/dataforge/meta/MutableMetaProvider;FLspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lkotlin/properties/ReadWriteProperty;
|
||||
public static synthetic fun float$default (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lkotlin/properties/ReadWriteProperty;
|
||||
public static final fun int (Lspace/kscience/dataforge/meta/MutableMetaProvider;ILspace/kscience/dataforge/names/Name;)Lkotlin/properties/ReadWriteProperty;
|
||||
public static final fun int (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/names/Name;)Lkotlin/properties/ReadWriteProperty;
|
||||
public static synthetic fun int$default (Lspace/kscience/dataforge/meta/MutableMetaProvider;ILspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lkotlin/properties/ReadWriteProperty;
|
||||
public static synthetic fun int$default (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lkotlin/properties/ReadWriteProperty;
|
||||
public static final fun listOfConvertable (Lspace/kscience/dataforge/meta/MutableMeta;Lspace/kscience/dataforge/meta/MetaConverter;Lspace/kscience/dataforge/names/Name;)Lkotlin/properties/ReadWriteProperty;
|
||||
public static synthetic fun listOfConvertable$default (Lspace/kscience/dataforge/meta/MutableMeta;Lspace/kscience/dataforge/meta/MetaConverter;Lspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lkotlin/properties/ReadWriteProperty;
|
||||
public static final fun listValue (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/names/Name;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Lkotlin/properties/ReadWriteProperty;
|
||||
public static synthetic fun listValue$default (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/names/Name;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lkotlin/properties/ReadWriteProperty;
|
||||
public static final fun long (Lspace/kscience/dataforge/meta/MutableMetaProvider;JLspace/kscience/dataforge/names/Name;)Lkotlin/properties/ReadWriteProperty;
|
||||
public static final fun long (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/names/Name;)Lkotlin/properties/ReadWriteProperty;
|
||||
public static synthetic fun long$default (Lspace/kscience/dataforge/meta/MutableMetaProvider;JLspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lkotlin/properties/ReadWriteProperty;
|
||||
public static synthetic fun long$default (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lkotlin/properties/ReadWriteProperty;
|
||||
public static final fun node (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/names/Name;)Lkotlin/properties/ReadWriteProperty;
|
||||
public static final fun node (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/names/Name;Lspace/kscience/dataforge/meta/MetaConverter;)Lkotlin/properties/ReadWriteProperty;
|
||||
public static synthetic fun node$default (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lkotlin/properties/ReadWriteProperty;
|
||||
public static synthetic fun node$default (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/names/Name;Lspace/kscience/dataforge/meta/MetaConverter;ILjava/lang/Object;)Lkotlin/properties/ReadWriteProperty;
|
||||
public static final fun number (Lspace/kscience/dataforge/meta/MutableMetaProvider;Ljava/lang/Number;Lspace/kscience/dataforge/names/Name;)Lkotlin/properties/ReadWriteProperty;
|
||||
public static final fun number (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/names/Name;)Lkotlin/properties/ReadWriteProperty;
|
||||
public static final fun number (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/names/Name;Lkotlin/jvm/functions/Function0;)Lkotlin/properties/ReadWriteProperty;
|
||||
public static synthetic fun number$default (Lspace/kscience/dataforge/meta/MutableMetaProvider;Ljava/lang/Number;Lspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lkotlin/properties/ReadWriteProperty;
|
||||
public static synthetic fun number$default (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lkotlin/properties/ReadWriteProperty;
|
||||
public static synthetic fun number$default (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/names/Name;Lkotlin/jvm/functions/Function0;ILjava/lang/Object;)Lkotlin/properties/ReadWriteProperty;
|
||||
public static final fun numberList (Lspace/kscience/dataforge/meta/MutableMetaProvider;[Ljava/lang/Number;Lspace/kscience/dataforge/names/Name;)Lkotlin/properties/ReadWriteProperty;
|
||||
public static synthetic fun numberList$default (Lspace/kscience/dataforge/meta/MutableMetaProvider;[Ljava/lang/Number;Lspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lkotlin/properties/ReadWriteProperty;
|
||||
public static final fun string (Lspace/kscience/dataforge/meta/MutableMetaProvider;Ljava/lang/String;Lspace/kscience/dataforge/names/Name;)Lkotlin/properties/ReadWriteProperty;
|
||||
public static final fun string (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/names/Name;)Lkotlin/properties/ReadWriteProperty;
|
||||
public static final fun string (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/names/Name;Lkotlin/jvm/functions/Function0;)Lkotlin/properties/ReadWriteProperty;
|
||||
public static synthetic fun string$default (Lspace/kscience/dataforge/meta/MutableMetaProvider;Ljava/lang/String;Lspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lkotlin/properties/ReadWriteProperty;
|
||||
public static synthetic fun string$default (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lkotlin/properties/ReadWriteProperty;
|
||||
public static synthetic fun string$default (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/names/Name;Lkotlin/jvm/functions/Function0;ILjava/lang/Object;)Lkotlin/properties/ReadWriteProperty;
|
||||
public static final fun stringList (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/names/Name;)Lkotlin/properties/ReadWriteProperty;
|
||||
public static final fun stringList (Lspace/kscience/dataforge/meta/MutableMetaProvider;[Ljava/lang/String;Lspace/kscience/dataforge/names/Name;)Lkotlin/properties/ReadWriteProperty;
|
||||
public static synthetic fun stringList$default (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lkotlin/properties/ReadWriteProperty;
|
||||
public static synthetic fun stringList$default (Lspace/kscience/dataforge/meta/MutableMetaProvider;[Ljava/lang/String;Lspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lkotlin/properties/ReadWriteProperty;
|
||||
public static final fun value (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/names/Name;)Lkotlin/properties/ReadWriteProperty;
|
||||
public static final fun value (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/names/Name;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Lkotlin/properties/ReadWriteProperty;
|
||||
public static synthetic fun value$default (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/names/Name;ILjava/lang/Object;)Lkotlin/properties/ReadWriteProperty;
|
||||
public static synthetic fun value$default (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/names/Name;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lkotlin/properties/ReadWriteProperty;
|
||||
}
|
||||
|
||||
public final class space/kscience/dataforge/meta/MutableMetaKt {
|
||||
@ -477,7 +447,6 @@ public final class space/kscience/dataforge/meta/MutableMetaKt {
|
||||
public static final fun getOrCreate (Lspace/kscience/dataforge/meta/MutableTypedMeta;Ljava/lang/String;)Lspace/kscience/dataforge/meta/MutableTypedMeta;
|
||||
public static final fun remove (Lspace/kscience/dataforge/meta/MutableMetaProvider;Ljava/lang/String;)V
|
||||
public static final fun remove (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/names/Name;)V
|
||||
public static final fun reset (Lspace/kscience/dataforge/meta/MutableMeta;Lspace/kscience/dataforge/meta/Meta;)V
|
||||
public static final fun set (Lspace/kscience/dataforge/meta/MutableMetaProvider;Ljava/lang/String;Ljava/lang/Iterable;)V
|
||||
public static final fun set (Lspace/kscience/dataforge/meta/MutableMetaProvider;Ljava/lang/String;Lspace/kscience/dataforge/meta/Meta;)V
|
||||
public static final fun set (Lspace/kscience/dataforge/meta/MutableMetaProvider;Lspace/kscience/dataforge/names/Name;Ljava/lang/Iterable;)V
|
||||
@ -734,6 +703,7 @@ public final class space/kscience/dataforge/meta/Value$Companion {
|
||||
public final class space/kscience/dataforge/meta/ValueExtensionsKt {
|
||||
public static final fun getBoolean (Lspace/kscience/dataforge/meta/Value;)Z
|
||||
public static final fun getDouble (Lspace/kscience/dataforge/meta/Value;)D
|
||||
public static final fun getDoubleArray (Lspace/kscience/dataforge/meta/Value;)[D
|
||||
public static final fun getFloat (Lspace/kscience/dataforge/meta/Value;)F
|
||||
public static final fun getInt (Lspace/kscience/dataforge/meta/Value;)I
|
||||
public static final fun getLong (Lspace/kscience/dataforge/meta/Value;)J
|
||||
@ -752,6 +722,7 @@ public final class space/kscience/dataforge/meta/ValueKt {
|
||||
public static final fun asValue (Ljava/lang/Number;)Lspace/kscience/dataforge/meta/Value;
|
||||
public static final fun asValue (Ljava/lang/String;)Lspace/kscience/dataforge/meta/Value;
|
||||
public static final fun asValue (Z)Lspace/kscience/dataforge/meta/Value;
|
||||
public static final fun asValue ([B)Lspace/kscience/dataforge/meta/Value;
|
||||
public static final fun asValue ([F)Lspace/kscience/dataforge/meta/Value;
|
||||
public static final fun asValue ([I)Lspace/kscience/dataforge/meta/Value;
|
||||
public static final fun asValue ([J)Lspace/kscience/dataforge/meta/Value;
|
||||
@ -957,9 +928,6 @@ public final class space/kscience/dataforge/misc/NamedKt {
|
||||
public static final fun isAnonymous (Lspace/kscience/dataforge/misc/Named;)Z
|
||||
}
|
||||
|
||||
public abstract interface annotation class space/kscience/dataforge/misc/UnsafeKType : java/lang/annotation/Annotation {
|
||||
}
|
||||
|
||||
public final class space/kscience/dataforge/names/Name {
|
||||
public static final field Companion Lspace/kscience/dataforge/names/Name$Companion;
|
||||
public static final field NAME_SEPARATOR Ljava/lang/String;
|
||||
@ -977,16 +945,6 @@ public final class space/kscience/dataforge/names/Name$Companion {
|
||||
public final fun serializer ()Lkotlinx/serialization/KSerializer;
|
||||
}
|
||||
|
||||
public final class space/kscience/dataforge/names/NameIndexComparator : java/util/Comparator {
|
||||
public static final field INSTANCE Lspace/kscience/dataforge/names/NameIndexComparator;
|
||||
public synthetic fun compare (Ljava/lang/Object;Ljava/lang/Object;)I
|
||||
public fun compare (Ljava/lang/String;Ljava/lang/String;)I
|
||||
}
|
||||
|
||||
public final class space/kscience/dataforge/names/NameIndexComparatorKt {
|
||||
public static final fun getIndexedList (Lspace/kscience/dataforge/meta/Meta;Lspace/kscience/dataforge/names/Name;)Ljava/util/List;
|
||||
}
|
||||
|
||||
public final class space/kscience/dataforge/names/NameKt {
|
||||
public static final fun appendFirst (Lspace/kscience/dataforge/names/Name;Ljava/lang/String;)Lspace/kscience/dataforge/names/Name;
|
||||
public static final fun appendLeft (Lspace/kscience/dataforge/names/Name;Ljava/lang/String;)Lspace/kscience/dataforge/names/Name;
|
||||
|
@ -135,17 +135,16 @@ public interface MetaConverter<T>: MetaSpec<T> {
|
||||
@DFExperimental
|
||||
public inline fun <reified T> serializable(
|
||||
descriptor: MetaDescriptor? = null,
|
||||
jsonEncoder: Json = Json,
|
||||
): MetaConverter<T> = object : MetaConverter<T> {
|
||||
private val serializer: KSerializer<T> = serializer()
|
||||
|
||||
override fun readOrNull(source: Meta): T? {
|
||||
val json = source.toJson(descriptor)
|
||||
return jsonEncoder.decodeFromJsonElement(serializer, json)
|
||||
return Json.decodeFromJsonElement(serializer, json)
|
||||
}
|
||||
|
||||
override fun convert(obj: T): Meta {
|
||||
val json = jsonEncoder.encodeToJsonElement(obj)
|
||||
val json = Json.encodeToJsonElement(obj)
|
||||
return json.toMeta(descriptor)
|
||||
}
|
||||
|
||||
|
@ -1,27 +1,15 @@
|
||||
package space.kscience.dataforge.meta
|
||||
|
||||
import space.kscience.dataforge.meta.descriptors.Described
|
||||
import space.kscience.dataforge.meta.descriptors.MetaDescriptor
|
||||
import space.kscience.dataforge.misc.DFExperimental
|
||||
import space.kscience.dataforge.names.Name
|
||||
import space.kscience.dataforge.names.asName
|
||||
import kotlin.properties.ReadOnlyProperty
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
/* Meta delegates */
|
||||
|
||||
public interface MetaDelegate<T> : ReadOnlyProperty<Any?, T>, Described
|
||||
|
||||
|
||||
public fun MetaProvider.node(
|
||||
key: Name? = null,
|
||||
descriptor: MetaDescriptor? = null,
|
||||
): MetaDelegate<Meta?> = object : MetaDelegate<Meta?> {
|
||||
override val descriptor: MetaDescriptor? = descriptor
|
||||
|
||||
override fun getValue(thisRef: Any?, property: KProperty<*>): Meta? {
|
||||
return get(key ?: property.name.asName())
|
||||
}
|
||||
public fun MetaProvider.node(key: Name? = null): ReadOnlyProperty<Any?, Meta?> = ReadOnlyProperty { _, property ->
|
||||
get(key ?: property.name.asName())
|
||||
}
|
||||
|
||||
/**
|
||||
@ -30,12 +18,8 @@ public fun MetaProvider.node(
|
||||
public fun <T> MetaProvider.spec(
|
||||
metaSpec: MetaSpec<T>,
|
||||
key: Name? = null,
|
||||
): MetaDelegate<T?> = object : MetaDelegate<T?> {
|
||||
override val descriptor: MetaDescriptor? get() = metaSpec.descriptor
|
||||
|
||||
override fun getValue(thisRef: Any?, property: KProperty<*>): T? {
|
||||
return get(key ?: property.name.asName())?.let { metaSpec.read(it) }
|
||||
}
|
||||
): ReadOnlyProperty<Any?, T?> = ReadOnlyProperty { _, property ->
|
||||
get(key ?: property.name.asName())?.let { metaSpec.read(it) }
|
||||
}
|
||||
|
||||
/**
|
||||
@ -43,9 +27,9 @@ public fun <T> MetaProvider.spec(
|
||||
*/
|
||||
@DFExperimental
|
||||
public inline fun <reified T> MetaProvider.serializable(
|
||||
key: Name? = null,
|
||||
descriptor: MetaDescriptor? = null,
|
||||
): MetaDelegate<T?> = spec(MetaConverter.serializable(descriptor), key)
|
||||
key: Name? = null,
|
||||
): ReadOnlyProperty<Any?, T?> = spec(MetaConverter.serializable(descriptor), key)
|
||||
|
||||
@Deprecated("Use convertable", ReplaceWith("convertable(converter, key)"))
|
||||
public fun <T> MetaProvider.node(
|
||||
@ -59,90 +43,78 @@ public fun <T> MetaProvider.node(
|
||||
public fun <T> Meta.listOfSpec(
|
||||
converter: MetaSpec<T>,
|
||||
key: Name? = null,
|
||||
): MetaDelegate<List<T>> = object : MetaDelegate<List<T>> {
|
||||
override fun getValue(thisRef: Any?, property: KProperty<*>): List<T> {
|
||||
): ReadOnlyProperty<Any?, List<T>> = ReadOnlyProperty{_, property ->
|
||||
val name = key ?: property.name.asName()
|
||||
return getIndexed(name).values.map { converter.read(it) }
|
||||
}
|
||||
|
||||
override val descriptor: MetaDescriptor? = converter.descriptor?.copy(multiple = true)
|
||||
getIndexed(name).values.map { converter.read(it) }
|
||||
}
|
||||
|
||||
@DFExperimental
|
||||
public inline fun <reified T> Meta.listOfSerializable(
|
||||
key: Name? = null,
|
||||
descriptor: MetaDescriptor? = null,
|
||||
): MetaDelegate<List<T>> = listOfSpec(MetaConverter.serializable(descriptor), key)
|
||||
key: Name? = null,
|
||||
): ReadOnlyProperty<Any?, List<T>> = listOfSpec(MetaConverter.serializable(descriptor), key)
|
||||
|
||||
/**
|
||||
* A property delegate that uses custom key
|
||||
*/
|
||||
public fun MetaProvider.value(
|
||||
key: Name? = null,
|
||||
descriptor: MetaDescriptor? = null,
|
||||
): MetaDelegate<Value?> = object : MetaDelegate<Value?> {
|
||||
override fun getValue(thisRef: Any?, property: KProperty<*>): Value? = get(key ?: property.name.asName())?.value
|
||||
|
||||
override val descriptor: MetaDescriptor? = descriptor
|
||||
public fun MetaProvider.value(key: Name? = null): ReadOnlyProperty<Any?, Value?> = ReadOnlyProperty { _, property ->
|
||||
get(key ?: property.name.asName())?.value
|
||||
}
|
||||
|
||||
public fun <R> MetaProvider.value(
|
||||
key: Name? = null,
|
||||
descriptor: MetaDescriptor? = null,
|
||||
reader: (Value?) -> R,
|
||||
): MetaDelegate<R> = object : MetaDelegate<R> {
|
||||
override fun getValue(thisRef: Any?, property: KProperty<*>): R = reader(get(key ?: property.name.asName())?.value)
|
||||
|
||||
override val descriptor: MetaDescriptor? = descriptor
|
||||
): ReadOnlyProperty<Any?, R> = ReadOnlyProperty { _, property ->
|
||||
reader(get(key ?: property.name.asName())?.value)
|
||||
}
|
||||
|
||||
//TODO add caching for sealed nodes
|
||||
|
||||
/* Read-only delegates for [Meta] */
|
||||
|
||||
public fun MetaProvider.string(key: Name? = null): MetaDelegate<String?> = value(key = key) { it?.string }
|
||||
public fun MetaProvider.string(key: Name? = null): ReadOnlyProperty<Any?, String?> = value(key) { it?.string }
|
||||
|
||||
public fun MetaProvider.boolean(key: Name? = null): MetaDelegate<Boolean?> = value(key = key) { it?.boolean }
|
||||
public fun MetaProvider.boolean(key: Name? = null): ReadOnlyProperty<Any?, Boolean?> = value(key) { it?.boolean }
|
||||
|
||||
public fun MetaProvider.number(key: Name? = null): MetaDelegate<Number?> = value(key = key) { it?.numberOrNull }
|
||||
public fun MetaProvider.number(key: Name? = null): ReadOnlyProperty<Any?, Number?> = value(key) { it?.numberOrNull }
|
||||
|
||||
public fun MetaProvider.double(key: Name? = null): MetaDelegate<Double?> = value(key = key) { it?.double }
|
||||
public fun MetaProvider.double(key: Name? = null): ReadOnlyProperty<Any?, Double?> = value(key) { it?.double }
|
||||
|
||||
public fun MetaProvider.float(key: Name? = null): MetaDelegate<Float?> = value(key = key) { it?.float }
|
||||
public fun MetaProvider.float(key: Name? = null): ReadOnlyProperty<Any?, Float?> = value(key) { it?.float }
|
||||
|
||||
public fun MetaProvider.int(key: Name? = null): MetaDelegate<Int?> = value(key = key) { it?.int }
|
||||
public fun MetaProvider.int(key: Name? = null): ReadOnlyProperty<Any?, Int?> = value(key) { it?.int }
|
||||
|
||||
public fun MetaProvider.long(key: Name? = null): MetaDelegate<Long?> = value(key = key) { it?.long }
|
||||
public fun MetaProvider.long(key: Name? = null): ReadOnlyProperty<Any?, Long?> = value(key) { it?.long }
|
||||
|
||||
public fun MetaProvider.string(default: String, key: Name? = null): MetaDelegate<String> =
|
||||
value(key = key) { it?.string ?: default }
|
||||
public fun MetaProvider.string(default: String, key: Name? = null): ReadOnlyProperty<Any?, String> =
|
||||
value(key) { it?.string ?: default }
|
||||
|
||||
public fun MetaProvider.boolean(default: Boolean, key: Name? = null): MetaDelegate<Boolean> =
|
||||
value(key = key) { it?.boolean ?: default }
|
||||
public fun MetaProvider.boolean(default: Boolean, key: Name? = null): ReadOnlyProperty<Any?, Boolean> =
|
||||
value(key) { it?.boolean ?: default }
|
||||
|
||||
public fun MetaProvider.number(default: Number, key: Name? = null): MetaDelegate<Number> =
|
||||
value(key = key) { it?.numberOrNull ?: default }
|
||||
public fun MetaProvider.number(default: Number, key: Name? = null): ReadOnlyProperty<Any?, Number> =
|
||||
value(key) { it?.numberOrNull ?: default }
|
||||
|
||||
public fun MetaProvider.double(default: Double, key: Name? = null): MetaDelegate<Double> =
|
||||
value(key = key) { it?.double ?: default }
|
||||
public fun MetaProvider.double(default: Double, key: Name? = null): ReadOnlyProperty<Any?, Double> =
|
||||
value(key) { it?.double ?: default }
|
||||
|
||||
public fun MetaProvider.float(default: Float, key: Name? = null): MetaDelegate<Float> =
|
||||
value(key = key) { it?.float ?: default }
|
||||
public fun MetaProvider.float(default: Float, key: Name? = null): ReadOnlyProperty<Any?, Float> =
|
||||
value(key) { it?.float ?: default }
|
||||
|
||||
public fun MetaProvider.int(default: Int, key: Name? = null): MetaDelegate<Int> =
|
||||
value(key = key) { it?.int ?: default }
|
||||
public fun MetaProvider.int(default: Int, key: Name? = null): ReadOnlyProperty<Any?, Int> =
|
||||
value(key) { it?.int ?: default }
|
||||
|
||||
public fun MetaProvider.long(default: Long, key: Name? = null): MetaDelegate<Long> =
|
||||
value(key = key) { it?.long ?: default }
|
||||
public fun MetaProvider.long(default: Long, key: Name? = null): ReadOnlyProperty<Any?, Long> =
|
||||
value(key) { it?.long ?: default }
|
||||
|
||||
public inline fun <reified E : Enum<E>> MetaProvider.enum(default: E, key: Name? = null): MetaDelegate<E> =
|
||||
value<E>(key = key) { it?.enum<E>() ?: default }
|
||||
public inline fun <reified E : Enum<E>> MetaProvider.enum(default: E, key: Name? = null): ReadOnlyProperty<Any?, E> =
|
||||
value<E>(key) { it?.enum<E>() ?: default }
|
||||
|
||||
public fun MetaProvider.string(key: Name? = null, default: () -> String): MetaDelegate<String> =
|
||||
value(key = key) { it?.string ?: default() }
|
||||
public fun MetaProvider.string(key: Name? = null, default: () -> String): ReadOnlyProperty<Any?, String> =
|
||||
value(key) { it?.string ?: default() }
|
||||
|
||||
public fun MetaProvider.boolean(key: Name? = null, default: () -> Boolean): MetaDelegate<Boolean> =
|
||||
value(key = key) { it?.boolean ?: default() }
|
||||
public fun MetaProvider.boolean(key: Name? = null, default: () -> Boolean): ReadOnlyProperty<Any?, Boolean> =
|
||||
value(key) { it?.boolean ?: default() }
|
||||
|
||||
public fun MetaProvider.number(key: Name? = null, default: () -> Number): MetaDelegate<Number> =
|
||||
value(key = key) { it?.numberOrNull ?: default() }
|
||||
public fun MetaProvider.number(key: Name? = null, default: () -> Number): ReadOnlyProperty<Any?, Number> =
|
||||
value(key) { it?.numberOrNull ?: default() }
|
||||
|
@ -128,10 +128,6 @@ public interface MutableMeta : Meta, MutableMetaProvider {
|
||||
setValue(Name.parse(this), array.asValue())
|
||||
}
|
||||
|
||||
public infix fun String.put(array: ByteArray) {
|
||||
setValue(Name.parse(this), array.asValue())
|
||||
}
|
||||
|
||||
public infix fun String.put(repr: MetaRepr) {
|
||||
set(Name.parse(this), repr.toMeta())
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package space.kscience.dataforge.meta
|
||||
|
||||
import space.kscience.dataforge.meta.descriptors.Described
|
||||
import space.kscience.dataforge.meta.descriptors.MetaDescriptor
|
||||
import space.kscience.dataforge.misc.DFExperimental
|
||||
import space.kscience.dataforge.names.Name
|
||||
@ -9,18 +8,10 @@ import space.kscience.dataforge.names.getIndexedList
|
||||
import kotlin.properties.ReadWriteProperty
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
|
||||
/* Read-write delegates */
|
||||
|
||||
public interface MutableMetaDelegate<T> : ReadWriteProperty<Any?, T>, Described
|
||||
|
||||
public fun MutableMetaProvider.node(
|
||||
key: Name? = null,
|
||||
descriptor: MetaDescriptor? = null,
|
||||
): MutableMetaDelegate<Meta?> = object : MutableMetaDelegate<Meta?> {
|
||||
|
||||
override val descriptor: MetaDescriptor? = descriptor
|
||||
|
||||
public fun MutableMetaProvider.node(key: Name? = null): ReadWriteProperty<Any?, Meta?> =
|
||||
object : ReadWriteProperty<Any?, Meta?> {
|
||||
override fun getValue(thisRef: Any?, property: KProperty<*>): Meta? {
|
||||
return get(key ?: property.name.asName())
|
||||
}
|
||||
@ -29,7 +20,7 @@ public fun MutableMetaProvider.node(
|
||||
val name = key ?: property.name.asName()
|
||||
set(name, value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Use [converter] to transform an object to Meta and back.
|
||||
@ -38,11 +29,8 @@ public fun MutableMetaProvider.node(
|
||||
public fun <T> MutableMetaProvider.convertable(
|
||||
converter: MetaConverter<T>,
|
||||
key: Name? = null,
|
||||
): MutableMetaDelegate<T?> = object : MutableMetaDelegate<T?> {
|
||||
|
||||
override val descriptor: MetaDescriptor? get() = converter.descriptor
|
||||
|
||||
|
||||
): ReadWriteProperty<Any?, T?> =
|
||||
object : ReadWriteProperty<Any?, T?> {
|
||||
override fun getValue(thisRef: Any?, property: KProperty<*>): T? {
|
||||
val name = key ?: property.name.asName()
|
||||
return get(name)?.let { converter.read(it) }
|
||||
@ -52,10 +40,10 @@ public fun <T> MutableMetaProvider.convertable(
|
||||
val name = key ?: property.name.asName()
|
||||
set(name, value?.let { converter.convert(it) })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated("Use convertable", ReplaceWith("convertable(converter, key)"))
|
||||
public fun <T> MutableMetaProvider.node(key: Name? = null, converter: MetaConverter<T>): MutableMetaDelegate<T?> =
|
||||
public fun <T> MutableMetaProvider.node(key: Name? = null, converter: MetaConverter<T>): ReadWriteProperty<Any?, T?> =
|
||||
convertable(converter, key)
|
||||
|
||||
/**
|
||||
@ -66,7 +54,7 @@ public fun <T> MutableMetaProvider.node(key: Name? = null, converter: MetaConver
|
||||
public inline fun <reified T> MutableMetaProvider.serializable(
|
||||
descriptor: MetaDescriptor? = null,
|
||||
key: Name? = null,
|
||||
): MutableMetaDelegate<T?> = convertable(MetaConverter.serializable(descriptor), key)
|
||||
): ReadWriteProperty<Any?, T?> = convertable(MetaConverter.serializable(descriptor), key)
|
||||
|
||||
/**
|
||||
* Use [converter] to convert a list of same name siblings meta to object and back.
|
||||
@ -75,9 +63,7 @@ public inline fun <reified T> MutableMetaProvider.serializable(
|
||||
public fun <T> MutableMeta.listOfConvertable(
|
||||
converter: MetaConverter<T>,
|
||||
key: Name? = null,
|
||||
): MutableMetaDelegate<List<T>> = object : MutableMetaDelegate<List<T>> {
|
||||
override val descriptor: MetaDescriptor? = converter.descriptor?.copy(multiple = true)
|
||||
|
||||
): ReadWriteProperty<Any?, List<T>> = object : ReadWriteProperty<Any?, List<T>> {
|
||||
override fun getValue(thisRef: Any?, property: KProperty<*>): List<T> {
|
||||
val name = key ?: property.name.asName()
|
||||
return getIndexedList(name).map { converter.read(it) }
|
||||
@ -91,33 +77,26 @@ public fun <T> MutableMeta.listOfConvertable(
|
||||
|
||||
@DFExperimental
|
||||
public inline fun <reified T> MutableMeta.listOfSerializable(
|
||||
key: Name? = null,
|
||||
descriptor: MetaDescriptor? = null,
|
||||
): MutableMetaDelegate<List<T>> = listOfConvertable(MetaConverter.serializable(descriptor), key)
|
||||
|
||||
|
||||
public fun MutableMetaProvider.value(
|
||||
key: Name? = null,
|
||||
descriptor: MetaDescriptor? = null,
|
||||
): MutableMetaDelegate<Value?> = object : MutableMetaDelegate<Value?> {
|
||||
override val descriptor: MetaDescriptor? = descriptor
|
||||
): ReadWriteProperty<Any?, List<T>> = listOfConvertable(MetaConverter.serializable(descriptor), key)
|
||||
|
||||
|
||||
public fun MutableMetaProvider.value(key: Name? = null): ReadWriteProperty<Any?, Value?> =
|
||||
object : ReadWriteProperty<Any?, Value?> {
|
||||
override fun getValue(thisRef: Any?, property: KProperty<*>): Value? =
|
||||
get(key ?: property.name.asName())?.value
|
||||
|
||||
override fun setValue(thisRef: Any?, property: KProperty<*>, value: Value?) {
|
||||
setValue(key ?: property.name.asName(), value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public fun <T> MutableMetaProvider.value(
|
||||
key: Name? = null,
|
||||
writer: (T) -> Value? = { Value.of(it) },
|
||||
descriptor: MetaDescriptor? = null,
|
||||
reader: (Value?) -> T,
|
||||
): MutableMetaDelegate<T> = object : MutableMetaDelegate<T> {
|
||||
override val descriptor: MetaDescriptor? = descriptor
|
||||
|
||||
): ReadWriteProperty<Any?, T> = object : ReadWriteProperty<Any?, T> {
|
||||
override fun getValue(thisRef: Any?, property: KProperty<*>): T =
|
||||
reader(get(key ?: property.name.asName())?.value)
|
||||
|
||||
@ -128,65 +107,65 @@ public fun <T> MutableMetaProvider.value(
|
||||
|
||||
/* Read-write delegates for [MutableItemProvider] */
|
||||
|
||||
public fun MutableMetaProvider.string(key: Name? = null): MutableMetaDelegate<String?> =
|
||||
public fun MutableMetaProvider.string(key: Name? = null): ReadWriteProperty<Any?, String?> =
|
||||
value(key) { it?.string }
|
||||
|
||||
public fun MutableMetaProvider.boolean(key: Name? = null): MutableMetaDelegate<Boolean?> =
|
||||
public fun MutableMetaProvider.boolean(key: Name? = null): ReadWriteProperty<Any?, Boolean?> =
|
||||
value(key) { it?.boolean }
|
||||
|
||||
public fun MutableMetaProvider.number(key: Name? = null): MutableMetaDelegate<Number?> =
|
||||
public fun MutableMetaProvider.number(key: Name? = null): ReadWriteProperty<Any?, Number?> =
|
||||
value(key) { it?.number }
|
||||
|
||||
public fun MutableMetaProvider.string(default: String, key: Name? = null): MutableMetaDelegate<String> =
|
||||
public fun MutableMetaProvider.string(default: String, key: Name? = null): ReadWriteProperty<Any?, String> =
|
||||
value(key) { it?.string ?: default }
|
||||
|
||||
public fun MutableMetaProvider.boolean(default: Boolean, key: Name? = null): MutableMetaDelegate<Boolean> =
|
||||
public fun MutableMetaProvider.boolean(default: Boolean, key: Name? = null): ReadWriteProperty<Any?, Boolean> =
|
||||
value(key) { it?.boolean ?: default }
|
||||
|
||||
public fun MutableMetaProvider.number(default: Number, key: Name? = null): MutableMetaDelegate<Number> =
|
||||
public fun MutableMetaProvider.number(default: Number, key: Name? = null): ReadWriteProperty<Any?, Number> =
|
||||
value(key) { it?.number ?: default }
|
||||
|
||||
public fun MutableMetaProvider.string(key: Name? = null, default: () -> String): MutableMetaDelegate<String> =
|
||||
public fun MutableMetaProvider.string(key: Name? = null, default: () -> String): ReadWriteProperty<Any?, String> =
|
||||
value(key) { it?.string ?: default() }
|
||||
|
||||
public fun MutableMetaProvider.boolean(key: Name? = null, default: () -> Boolean): MutableMetaDelegate<Boolean> =
|
||||
public fun MutableMetaProvider.boolean(key: Name? = null, default: () -> Boolean): ReadWriteProperty<Any?, Boolean> =
|
||||
value(key) { it?.boolean ?: default() }
|
||||
|
||||
public fun MutableMetaProvider.number(key: Name? = null, default: () -> Number): MutableMetaDelegate<Number> =
|
||||
public fun MutableMetaProvider.number(key: Name? = null, default: () -> Number): ReadWriteProperty<Any?, Number> =
|
||||
value(key) { it?.number ?: default() }
|
||||
|
||||
public inline fun <reified E : Enum<E>> MutableMetaProvider.enum(
|
||||
default: E,
|
||||
key: Name? = null,
|
||||
): MutableMetaDelegate<E> = value(key) { value -> value?.string?.let { enumValueOf<E>(it) } ?: default }
|
||||
): ReadWriteProperty<Any?, E> = value(key) { value -> value?.string?.let { enumValueOf<E>(it) } ?: default }
|
||||
|
||||
/* Number delegates */
|
||||
|
||||
public fun MutableMetaProvider.int(key: Name? = null): MutableMetaDelegate<Int?> =
|
||||
public fun MutableMetaProvider.int(key: Name? = null): ReadWriteProperty<Any?, Int?> =
|
||||
value(key) { it?.int }
|
||||
|
||||
public fun MutableMetaProvider.double(key: Name? = null): MutableMetaDelegate<Double?> =
|
||||
public fun MutableMetaProvider.double(key: Name? = null): ReadWriteProperty<Any?, Double?> =
|
||||
value(key) { it?.double }
|
||||
|
||||
public fun MutableMetaProvider.long(key: Name? = null): MutableMetaDelegate<Long?> =
|
||||
public fun MutableMetaProvider.long(key: Name? = null): ReadWriteProperty<Any?, Long?> =
|
||||
value(key) { it?.long }
|
||||
|
||||
public fun MutableMetaProvider.float(key: Name? = null): MutableMetaDelegate<Float?> =
|
||||
public fun MutableMetaProvider.float(key: Name? = null): ReadWriteProperty<Any?, Float?> =
|
||||
value(key) { it?.float }
|
||||
|
||||
|
||||
/* Safe number delegates*/
|
||||
|
||||
public fun MutableMetaProvider.int(default: Int, key: Name? = null): MutableMetaDelegate<Int> =
|
||||
public fun MutableMetaProvider.int(default: Int, key: Name? = null): ReadWriteProperty<Any?, Int> =
|
||||
value(key) { it?.int ?: default }
|
||||
|
||||
public fun MutableMetaProvider.double(default: Double, key: Name? = null): MutableMetaDelegate<Double> =
|
||||
public fun MutableMetaProvider.double(default: Double, key: Name? = null): ReadWriteProperty<Any?, Double> =
|
||||
value(key) { it?.double ?: default }
|
||||
|
||||
public fun MutableMetaProvider.long(default: Long, key: Name? = null): MutableMetaDelegate<Long> =
|
||||
public fun MutableMetaProvider.long(default: Long, key: Name? = null): ReadWriteProperty<Any?, Long> =
|
||||
value(key) { it?.long ?: default }
|
||||
|
||||
public fun MutableMetaProvider.float(default: Float, key: Name? = null): MutableMetaDelegate<Float> =
|
||||
public fun MutableMetaProvider.float(default: Float, key: Name? = null): ReadWriteProperty<Any?, Float> =
|
||||
value(key) { it?.float ?: default }
|
||||
|
||||
|
||||
@ -195,7 +174,7 @@ public fun MutableMetaProvider.float(default: Float, key: Name? = null): Mutable
|
||||
public fun MutableMetaProvider.stringList(
|
||||
vararg default: String,
|
||||
key: Name? = null,
|
||||
): MutableMetaDelegate<List<String>> = value(
|
||||
): ReadWriteProperty<Any?, List<String>> = value(
|
||||
key,
|
||||
writer = { list -> list.map { str -> str.asValue() }.asValue() },
|
||||
reader = { it?.stringList ?: listOf(*default) },
|
||||
@ -203,7 +182,7 @@ public fun MutableMetaProvider.stringList(
|
||||
|
||||
public fun MutableMetaProvider.stringList(
|
||||
key: Name? = null,
|
||||
): MutableMetaDelegate<List<String>?> = value(
|
||||
): ReadWriteProperty<Any?, List<String>?> = value(
|
||||
key,
|
||||
writer = { it -> it?.map { str -> str.asValue() }?.asValue() },
|
||||
reader = { it?.stringList },
|
||||
@ -212,18 +191,29 @@ public fun MutableMetaProvider.stringList(
|
||||
public fun MutableMetaProvider.numberList(
|
||||
vararg default: Number,
|
||||
key: Name? = null,
|
||||
): MutableMetaDelegate<List<Number>> = value(
|
||||
): ReadWriteProperty<Any?, List<Number>> = value(
|
||||
key,
|
||||
writer = { it.map { num -> num.asValue() }.asValue() },
|
||||
reader = { it?.list?.map { value -> value.numberOrNull ?: Double.NaN } ?: listOf(*default) },
|
||||
)
|
||||
|
||||
/* A special delegate for double arrays */
|
||||
|
||||
|
||||
public fun MutableMetaProvider.doubleArray(
|
||||
vararg default: Double,
|
||||
key: Name? = null,
|
||||
): ReadWriteProperty<Any?, DoubleArray> = value(
|
||||
key,
|
||||
writer = { DoubleArrayValue(it) },
|
||||
reader = { it?.doubleArray ?: doubleArrayOf(*default) },
|
||||
)
|
||||
|
||||
public fun <T> MutableMetaProvider.listValue(
|
||||
key: Name? = null,
|
||||
writer: (T) -> Value = { Value.of(it) },
|
||||
reader: (Value) -> T,
|
||||
): MutableMetaDelegate<List<T>?> = value(
|
||||
): ReadWriteProperty<Any?, List<T>?> = value(
|
||||
key,
|
||||
writer = { it?.map(writer)?.asValue() },
|
||||
reader = { it?.list?.map(reader) }
|
||||
|
@ -122,7 +122,7 @@ public open class Scheme(
|
||||
override fun hashCode(): Int = Meta.hashCode(this)
|
||||
|
||||
override fun set(name: Name, node: Meta?) {
|
||||
target[pathName + name] = node
|
||||
target[name] = node
|
||||
invalidate(name)
|
||||
}
|
||||
|
||||
|
@ -256,6 +256,8 @@ public fun ShortArray.asValue(): Value = if (isEmpty()) Null else ListValue(map
|
||||
|
||||
public fun FloatArray.asValue(): Value = if (isEmpty()) Null else ListValue(map { NumberValue(it) })
|
||||
|
||||
public fun ByteArray.asValue(): Value = if (isEmpty()) Null else ListValue(map { NumberValue(it) })
|
||||
|
||||
public fun <E : Enum<E>> E.asValue(): Value = EnumValue(this)
|
||||
|
||||
|
||||
|
@ -1,9 +1,5 @@
|
||||
package space.kscience.dataforge.meta
|
||||
|
||||
import space.kscience.dataforge.names.Name
|
||||
import kotlin.properties.ReadOnlyProperty
|
||||
import kotlin.properties.ReadWriteProperty
|
||||
|
||||
|
||||
/**
|
||||
* A value built from string which content and type are parsed on-demand
|
||||
@ -48,79 +44,3 @@ public class DoubleArrayValue(override val value: DoubleArray) : Value, Iterable
|
||||
}
|
||||
|
||||
public fun DoubleArray.asValue(): Value = if (isEmpty()) Null else DoubleArrayValue(this)
|
||||
|
||||
public val Value.doubleArray: DoubleArray
|
||||
get() = if (this is DoubleArrayValue) {
|
||||
value
|
||||
} else {
|
||||
DoubleArray(list.size) { list[it].double }
|
||||
}
|
||||
|
||||
public val Meta?.doubleArray: DoubleArray? get() = this?.value?.doubleArray
|
||||
|
||||
public fun MetaProvider.doubleArray(
|
||||
vararg default: Double,
|
||||
key: Name? = null,
|
||||
): ReadOnlyProperty<Any?, DoubleArray> = value(
|
||||
key,
|
||||
reader = { it?.doubleArray ?: doubleArrayOf(*default) },
|
||||
)
|
||||
|
||||
public fun MutableMetaProvider.doubleArray(
|
||||
vararg default: Double,
|
||||
key: Name? = null,
|
||||
): ReadWriteProperty<Any?, DoubleArray> = value(
|
||||
key,
|
||||
writer = { DoubleArrayValue(it) },
|
||||
reader = { it?.doubleArray ?: doubleArrayOf(*default) },
|
||||
)
|
||||
|
||||
|
||||
public class ByteArrayValue(override val value: ByteArray) : Value, Iterable<Byte> {
|
||||
override val type: ValueType get() = ValueType.LIST
|
||||
override val list: List<Value> get() = value.map { NumberValue(it) }
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (other !is Value) return false
|
||||
|
||||
return when (other) {
|
||||
is ByteArrayValue -> value.contentEquals(other.value)
|
||||
else -> list == other.list
|
||||
}
|
||||
}
|
||||
|
||||
override fun hashCode(): Int = value.contentHashCode()
|
||||
|
||||
override fun toString(): String = list.joinToString(prefix = "[", postfix = "]")
|
||||
|
||||
override fun iterator(): Iterator<Byte> = value.iterator()
|
||||
}
|
||||
|
||||
public fun ByteArray.asValue(): Value = ByteArrayValue(this)
|
||||
|
||||
public val Value.byteArray: ByteArray
|
||||
get() = if (this is ByteArrayValue) {
|
||||
value
|
||||
} else {
|
||||
ByteArray(list.size) { list[it].number.toByte() }
|
||||
}
|
||||
|
||||
public val Meta?.byteArray: ByteArray? get() = this?.value?.byteArray
|
||||
|
||||
public fun MetaProvider.byteArray(
|
||||
vararg default: Byte,
|
||||
key: Name? = null,
|
||||
): ReadOnlyProperty<Any?, ByteArray> = value(
|
||||
key,
|
||||
reader = { it?.byteArray ?: byteArrayOf(*default) },
|
||||
)
|
||||
|
||||
public fun MutableMetaProvider.byteArray(
|
||||
vararg default: Byte,
|
||||
key: Name? = null,
|
||||
): ReadWriteProperty<Any?, ByteArray> = value(
|
||||
key,
|
||||
writer = { ByteArrayValue(it) },
|
||||
reader = { it?.byteArray ?: byteArrayOf(*default) },
|
||||
)
|
@ -31,5 +31,12 @@ public inline fun <reified E : Enum<E>> Value.enum(): E = if (this is EnumValue<
|
||||
|
||||
public val Value.stringList: List<String> get() = list.map { it.string }
|
||||
|
||||
public val Value.doubleArray: DoubleArray
|
||||
get() = if (this is DoubleArrayValue) {
|
||||
value
|
||||
} else {
|
||||
DoubleArray(list.size) { list[it].double }
|
||||
}
|
||||
|
||||
|
||||
public fun Value.toMeta(): Meta = Meta(this)
|
@ -19,10 +19,3 @@ public annotation class DFExperimental
|
||||
@RequiresOptIn(level = RequiresOptIn.Level.WARNING)
|
||||
@Retention(AnnotationRetention.BINARY)
|
||||
public annotation class DFInternal
|
||||
|
||||
/**
|
||||
* Annotation marks methods that explicitly use KType without checking that it corresponds to the type parameter
|
||||
*/
|
||||
@RequiresOptIn(level = RequiresOptIn.Level.WARNING)
|
||||
@Retention(AnnotationRetention.BINARY)
|
||||
public annotation class UnsafeKType
|
@ -69,7 +69,7 @@ public class NameToken(public val body: String, public val index: String? = null
|
||||
public fun parse(string: String): NameToken {
|
||||
val body = string.substringBefore('[')
|
||||
val index = string.substringAfter('[', "")
|
||||
if (index.isNotEmpty() && !index.endsWith(']')) error("NameToken with index must end with ']'")
|
||||
if (index.isNotEmpty() && index.endsWith(']')) error("NameToken with index must end with ']'")
|
||||
return NameToken(body, index.removeSuffix("]"))
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,70 @@
|
||||
package space.kscience.dataforge.meta
|
||||
|
||||
import space.kscience.dataforge.misc.DFExperimental
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertNotNull
|
||||
|
||||
|
||||
private class SchemeWithInit: Scheme(){
|
||||
init {
|
||||
set("initial", "initialValue")
|
||||
}
|
||||
|
||||
var initial by string()
|
||||
companion object: SchemeSpec<SchemeWithInit>(::SchemeWithInit)
|
||||
}
|
||||
|
||||
|
||||
|
||||
class SchemeTest {
|
||||
@Test
|
||||
fun testSchemeWrappingBeforeEdit() {
|
||||
val config = MutableMeta()
|
||||
val scheme = TestScheme.write(config)
|
||||
scheme.a = 29
|
||||
assertEquals(29, config["a"].int)
|
||||
}
|
||||
|
||||
@OptIn(DFExperimental::class)
|
||||
@Test
|
||||
fun testSchemeWrappingAfterEdit() {
|
||||
val scheme = TestScheme.empty()
|
||||
scheme.a = 29
|
||||
val config = MutableMeta()
|
||||
scheme.retarget(config)
|
||||
assertEquals(29, scheme.a)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testSchemeSubscription() {
|
||||
val scheme = TestScheme.empty()
|
||||
var flag: Int? = null
|
||||
scheme.useProperty(TestScheme::a) { a ->
|
||||
flag = a
|
||||
}
|
||||
scheme.a = 2
|
||||
assertEquals(2, flag)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testListSubscription(){
|
||||
val scheme = TestScheme.empty()
|
||||
var value: Value? = null
|
||||
scheme.v = ListValue(0.0,0.0,0.0)
|
||||
scheme.useProperty(TestScheme::v){
|
||||
value = it
|
||||
}
|
||||
scheme.v = ListValue(1.0, 2.0, 3.0)
|
||||
assertNotNull(value)
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
fun testSchemeWithInit(){
|
||||
val scheme = SchemeWithInit()
|
||||
assertEquals("initialValue", scheme.initial)
|
||||
scheme.initial = "none"
|
||||
assertEquals("none", scheme.initial)
|
||||
}
|
||||
}
|
@ -1,17 +1,7 @@
|
||||
package space.kscience.dataforge.meta
|
||||
|
||||
import space.kscience.dataforge.misc.DFExperimental
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertNotNull
|
||||
|
||||
|
||||
internal class SubScheme : Scheme() {
|
||||
|
||||
var subValue by string()
|
||||
|
||||
companion object : SchemeSpec<SubScheme>(::SubScheme)
|
||||
}
|
||||
|
||||
internal class TestScheme : Scheme() {
|
||||
var list by numberList(1, 2, 3)
|
||||
@ -21,23 +11,9 @@ internal class TestScheme : Scheme() {
|
||||
|
||||
var v by value()
|
||||
|
||||
var sub by scheme(SubScheme)
|
||||
|
||||
companion object : SchemeSpec<TestScheme>(::TestScheme)
|
||||
}
|
||||
|
||||
private class SchemeWithInit: Scheme(){
|
||||
init {
|
||||
set("initial", "initialValue")
|
||||
}
|
||||
|
||||
var initial by string()
|
||||
|
||||
companion object: SchemeSpec<SchemeWithInit>(::SchemeWithInit)
|
||||
}
|
||||
|
||||
|
||||
|
||||
class SpecificationTest {
|
||||
|
||||
// @Test
|
||||
@ -95,64 +71,4 @@ class SpecificationTest {
|
||||
assertEquals(22, config["child.a"].int)
|
||||
assertEquals("test", config["child.b"].string)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testSchemeWrappingBeforeEdit() {
|
||||
val config = MutableMeta()
|
||||
val scheme = TestScheme.write(config)
|
||||
scheme.a = 29
|
||||
assertEquals(29, config["a"].int)
|
||||
}
|
||||
|
||||
@OptIn(DFExperimental::class)
|
||||
@Test
|
||||
fun testSchemeWrappingAfterEdit() {
|
||||
val scheme = TestScheme.empty()
|
||||
scheme.a = 29
|
||||
val config = MutableMeta()
|
||||
scheme.retarget(config)
|
||||
assertEquals(29, scheme.a)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testSchemeSubscription() {
|
||||
val scheme = TestScheme.empty()
|
||||
var flag: Int? = null
|
||||
scheme.useProperty(TestScheme::a) { a ->
|
||||
flag = a
|
||||
}
|
||||
scheme.a = 2
|
||||
assertEquals(2, flag)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testListSubscription(){
|
||||
val scheme = TestScheme.empty()
|
||||
var value: Value? = null
|
||||
scheme.v = ListValue(0.0,0.0,0.0)
|
||||
scheme.useProperty(TestScheme::v){
|
||||
value = it
|
||||
}
|
||||
scheme.v = ListValue(1.0, 2.0, 3.0)
|
||||
assertNotNull(value)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testSubScheme(){
|
||||
val scheme = TestScheme.empty()
|
||||
|
||||
scheme.sub.subValue = "aaa"
|
||||
|
||||
assertEquals("aaa",scheme.sub.subValue)
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
fun testSchemeWithInit(){
|
||||
val scheme = SchemeWithInit()
|
||||
assertEquals("initialValue", scheme.initial)
|
||||
scheme.initial = "none"
|
||||
assertEquals("none", scheme.initial)
|
||||
}
|
||||
|
||||
}
|
@ -1,6 +1,9 @@
|
||||
package space.kscience.dataforge.names
|
||||
|
||||
import kotlin.test.*
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFalse
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
class NameTest {
|
||||
@Test
|
||||
@ -47,19 +50,4 @@ class NameTest {
|
||||
val name = Name.parse("a.b.c")
|
||||
assertEquals("a.b".parseAsName(), name.cutLast())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun tokenParseTest(){
|
||||
val token1 = NameToken.parse("token[index]")
|
||||
assertEquals("token", token1.body)
|
||||
assertEquals("index", token1.index)
|
||||
|
||||
val token2 = NameToken.parse("token-body")
|
||||
assertEquals("token-body", token2.body)
|
||||
assertEquals("", token2.index)
|
||||
|
||||
assertFails {
|
||||
NameToken.parse("token[22")
|
||||
}
|
||||
}
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
package space.kscience.dataforge.values
|
||||
|
||||
import space.kscience.dataforge.meta.DoubleArrayValue
|
||||
import space.kscience.dataforge.meta.Meta
|
||||
import space.kscience.dataforge.meta.doubleArray
|
||||
import space.kscience.dataforge.meta.get
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
class DoubleArrayValue {
|
||||
@Test
|
||||
fun doubleArrayWriteRead(){
|
||||
val meta = Meta{
|
||||
"doubleArray" put doubleArrayOf(1.0,2.0,3.0)
|
||||
}
|
||||
|
||||
assertTrue {
|
||||
meta["doubleArray"]?.value is DoubleArrayValue
|
||||
}
|
||||
|
||||
assertEquals(2.0, meta["doubleArray"].doubleArray?.get(1))
|
||||
}
|
||||
}
|
@ -10,7 +10,6 @@ import space.kscience.dataforge.meta.MetaSpec
|
||||
import space.kscience.dataforge.meta.descriptors.Described
|
||||
import space.kscience.dataforge.meta.descriptors.MetaDescriptor
|
||||
import space.kscience.dataforge.misc.DfType
|
||||
import space.kscience.dataforge.misc.UnsafeKType
|
||||
import space.kscience.dataforge.names.Name
|
||||
import space.kscience.dataforge.workspace.Task.Companion.TYPE
|
||||
import kotlin.reflect.KType
|
||||
@ -91,8 +90,7 @@ public fun <T : Any> Task(
|
||||
taskMeta: Meta,
|
||||
): TaskResult<T> {
|
||||
//TODO use safe builder and check for external data on add and detects cycles
|
||||
@OptIn(UnsafeKType::class)
|
||||
val dataset = MutableDataTree<T>(resultType).apply {
|
||||
val dataset = MutableDataTree<T>(resultType, workspace.context).apply {
|
||||
TaskResultBuilder(workspace, taskName, taskMeta, this).apply {
|
||||
withContext(GoalExecutionRestriction() + workspace.goalLogger) {
|
||||
builder()
|
||||
@ -100,6 +98,7 @@ public fun <T : Any> Task(
|
||||
}
|
||||
}
|
||||
return workspace.wrapResult(dataset, taskName, taskMeta)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -118,7 +117,6 @@ public inline fun <reified T : Any> Task(
|
||||
* @param builder for resulting data set
|
||||
*/
|
||||
|
||||
|
||||
@Suppress("FunctionName")
|
||||
public fun <T : Any, C : MetaRepr> Task(
|
||||
resultType: KType,
|
||||
@ -134,8 +132,7 @@ public fun <T : Any, C : MetaRepr> Task(
|
||||
): TaskResult<T> = withContext(GoalExecutionRestriction() + workspace.goalLogger) {
|
||||
//TODO use safe builder and check for external data on add and detects cycles
|
||||
val taskMeta = configuration.toMeta()
|
||||
@OptIn(UnsafeKType::class)
|
||||
val dataset = MutableDataTree<T>(resultType).apply {
|
||||
val dataset = MutableDataTree<T>(resultType, this).apply {
|
||||
TaskResultBuilder(workspace, taskName, taskMeta, this).apply { builder(configuration) }
|
||||
}
|
||||
workspace.wrapResult(dataset, taskName, taskMeta)
|
||||
|
@ -4,7 +4,7 @@ import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.joinAll
|
||||
import kotlinx.coroutines.launch
|
||||
import space.kscience.dataforge.data.DataTree
|
||||
import space.kscience.dataforge.data.ObservableDataTree
|
||||
import space.kscience.dataforge.data.asSequence
|
||||
import space.kscience.dataforge.data.launch
|
||||
import space.kscience.dataforge.meta.Meta
|
||||
@ -17,16 +17,16 @@ import space.kscience.dataforge.names.Name
|
||||
* @param taskMeta The configuration of the task that produced the result
|
||||
*/
|
||||
public data class TaskResult<T>(
|
||||
public val content: DataTree<T>,
|
||||
public val content: ObservableDataTree<T>,
|
||||
public val workspace: Workspace,
|
||||
public val taskName: Name,
|
||||
public val taskMeta: Meta,
|
||||
) : DataTree<T> by content
|
||||
) : ObservableDataTree<T> by content
|
||||
|
||||
/**
|
||||
* Wrap data into [TaskResult]
|
||||
*/
|
||||
public fun <T> Workspace.wrapResult(data: DataTree<T>, taskName: Name, taskMeta: Meta): TaskResult<T> =
|
||||
public fun <T> Workspace.wrapResult(data: ObservableDataTree<T>, taskName: Name, taskMeta: Meta): TaskResult<T> =
|
||||
TaskResult(data, this, taskName, taskMeta)
|
||||
|
||||
/**
|
||||
|
@ -2,10 +2,7 @@ package space.kscience.dataforge.workspace
|
||||
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import space.kscience.dataforge.context.ContextAware
|
||||
import space.kscience.dataforge.data.Data
|
||||
import space.kscience.dataforge.data.DataTree
|
||||
import space.kscience.dataforge.data.asSequence
|
||||
import space.kscience.dataforge.data.get
|
||||
import space.kscience.dataforge.data.*
|
||||
import space.kscience.dataforge.meta.Meta
|
||||
import space.kscience.dataforge.meta.MutableMeta
|
||||
import space.kscience.dataforge.misc.DfType
|
||||
@ -29,7 +26,7 @@ public interface Workspace : ContextAware, Provider, CoroutineScope {
|
||||
/**
|
||||
* The whole data node for current workspace
|
||||
*/
|
||||
public val data: DataTree<*>
|
||||
public val data: ObservableDataTree<*>
|
||||
|
||||
/**
|
||||
* All targets associated with the workspace
|
||||
|
@ -1,5 +1,6 @@
|
||||
package space.kscience.dataforge.workspace
|
||||
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import space.kscience.dataforge.actions.Action
|
||||
import space.kscience.dataforge.context.Context
|
||||
import space.kscience.dataforge.context.ContextBuilder
|
||||
@ -11,7 +12,6 @@ import space.kscience.dataforge.meta.*
|
||||
import space.kscience.dataforge.meta.descriptors.MetaDescriptor
|
||||
import space.kscience.dataforge.meta.descriptors.MetaDescriptorBuilder
|
||||
import space.kscience.dataforge.misc.DFBuilder
|
||||
import space.kscience.dataforge.misc.UnsafeKType
|
||||
import space.kscience.dataforge.names.Name
|
||||
import space.kscience.dataforge.names.asName
|
||||
import kotlin.collections.set
|
||||
@ -98,19 +98,19 @@ public inline fun <reified T : Any> TaskContainer.task(
|
||||
public inline fun <T : Any, reified R : Any> TaskContainer.action(
|
||||
selector: DataSelector<T>,
|
||||
action: Action<T, R>,
|
||||
noinline metaTransform: MutableMeta.() -> Unit = {},
|
||||
noinline metaTransform: MutableMeta.()-> Unit = {},
|
||||
noinline descriptorBuilder: MetaDescriptorBuilder.() -> Unit = {},
|
||||
): PropertyDelegateProvider<Any?, ReadOnlyProperty<Any?, TaskReference<R>>> =
|
||||
task(MetaDescriptor(descriptorBuilder)) {
|
||||
result(action.execute(from(selector), taskMeta.copy(metaTransform), workspace))
|
||||
result(action.execute(from(selector), taskMeta.copy(metaTransform)))
|
||||
}
|
||||
|
||||
public class WorkspaceBuilder(
|
||||
private val parentContext: Context = Global,
|
||||
private val coroutineScope: CoroutineScope = parentContext,
|
||||
) : TaskContainer {
|
||||
private var context: Context? = null
|
||||
@OptIn(UnsafeKType::class)
|
||||
private val data = MutableDataTree<Any?>(typeOf<Any?>())
|
||||
private val data = MutableDataTree<Any?>(typeOf<Any?>(), coroutineScope)
|
||||
private val targets: HashMap<String, Meta> = HashMap()
|
||||
private val tasks = HashMap<Name, Task<*>>()
|
||||
private var cache: WorkspaceCache? = null
|
||||
|
@ -2,14 +2,14 @@ package space.kscience.dataforge.workspace
|
||||
|
||||
import space.kscience.dataforge.context.Context
|
||||
import space.kscience.dataforge.context.gather
|
||||
import space.kscience.dataforge.data.DataTree
|
||||
import space.kscience.dataforge.data.ObservableDataTree
|
||||
import space.kscience.dataforge.meta.Meta
|
||||
import space.kscience.dataforge.names.Name
|
||||
|
||||
|
||||
internal class WorkspaceImpl internal constructor(
|
||||
override val context: Context,
|
||||
override val data: DataTree<*>,
|
||||
override val data: ObservableDataTree<*>,
|
||||
override val targets: Map<String, Meta>,
|
||||
tasks: Map<Name, Task<*>>,
|
||||
private val postProcess: suspend (TaskResult<*>) -> TaskResult<*>,
|
||||
|
@ -3,14 +3,14 @@ package space.kscience.dataforge.workspace
|
||||
import space.kscience.dataforge.data.Data
|
||||
import space.kscience.dataforge.data.await
|
||||
import space.kscience.dataforge.io.*
|
||||
import space.kscience.dataforge.misc.UnsafeKType
|
||||
import space.kscience.dataforge.misc.DFInternal
|
||||
import kotlin.reflect.typeOf
|
||||
|
||||
|
||||
/**
|
||||
* Convert an [Envelope] to a data via given format. The actual parsing is done lazily.
|
||||
*/
|
||||
@OptIn(UnsafeKType::class)
|
||||
@OptIn(DFInternal::class)
|
||||
public inline fun <reified T : Any> Envelope.toData(format: IOReader<T>): Data<T> = Data(typeOf<T>(), meta) {
|
||||
data?.readWith(format) ?: error("Can't convert envelope without data to Data")
|
||||
}
|
||||
|
@ -113,7 +113,7 @@ public suspend inline fun <T, reified R> TaskResultBuilder<R>.actionFrom(
|
||||
action: Action<T, R>,
|
||||
dependencyMeta: Meta = defaultDependencyMeta,
|
||||
) {
|
||||
putAll(action.execute(from(selector, dependencyMeta), dependencyMeta, workspace))
|
||||
this.putAll(action.execute(from(selector, dependencyMeta), dependencyMeta))
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,19 +0,0 @@
|
||||
package space.kscience.dataforge.workspace
|
||||
|
||||
import space.kscience.dataforge.actions.AbstractAction
|
||||
import space.kscience.dataforge.data.*
|
||||
import space.kscience.dataforge.meta.Meta
|
||||
import kotlin.reflect.KType
|
||||
|
||||
internal class CachingAction<T>(type: KType, private val caching: (NamedData<T>) -> NamedData<T>) :
|
||||
AbstractAction<T, T>(type) {
|
||||
override fun DataSink<T>.generate(source: DataTree<T>, meta: Meta) {
|
||||
source.forEach {
|
||||
put(caching(it))
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun DataSink<T>.update(source: DataTree<T>, meta: Meta, updatedData: DataUpdate<T>) {
|
||||
put(updatedData.name, updatedData.data?.named(updatedData.name)?.let(caching))
|
||||
}
|
||||
}
|
@ -1,22 +1,19 @@
|
||||
package space.kscience.dataforge.workspace
|
||||
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.io.*
|
||||
import kotlinx.serialization.ExperimentalSerializationApi
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.json.Json
|
||||
import kotlinx.serialization.protobuf.ProtoBuf
|
||||
import kotlinx.serialization.serializer
|
||||
import space.kscience.dataforge.actions.Action
|
||||
import space.kscience.dataforge.actions.invoke
|
||||
import space.kscience.dataforge.context.error
|
||||
import space.kscience.dataforge.context.logger
|
||||
import space.kscience.dataforge.context.request
|
||||
import space.kscience.dataforge.data.Data
|
||||
import space.kscience.dataforge.data.await
|
||||
import space.kscience.dataforge.data.named
|
||||
import space.kscience.dataforge.data.*
|
||||
import space.kscience.dataforge.io.*
|
||||
import space.kscience.dataforge.misc.DFExperimental
|
||||
import space.kscience.dataforge.misc.UnsafeKType
|
||||
import space.kscience.dataforge.misc.DFInternal
|
||||
import space.kscience.dataforge.names.withIndex
|
||||
import java.nio.file.Path
|
||||
import kotlin.io.path.deleteIfExists
|
||||
@ -54,8 +51,7 @@ public class FileWorkspaceCache(public val cacheDirectory: Path) : WorkspaceCach
|
||||
|
||||
// private fun <T : Any> TaskData<*>.checkType(taskType: KType): TaskData<T> = this as TaskData<T>
|
||||
|
||||
|
||||
@OptIn(DFExperimental::class, UnsafeKType::class)
|
||||
@OptIn(DFExperimental::class, DFInternal::class)
|
||||
override suspend fun <T> cache(result: TaskResult<T>): TaskResult<T> {
|
||||
val io = result.workspace.context.request(IOPlugin)
|
||||
|
||||
@ -63,8 +59,8 @@ public class FileWorkspaceCache(public val cacheDirectory: Path) : WorkspaceCach
|
||||
?: ProtobufIOFormat(result.dataType)
|
||||
?: error("Can't resolve IOFormat for ${result.dataType}")
|
||||
|
||||
fun cacheOne(data: NamedData<T>): NamedData<T> {
|
||||
|
||||
val cachingAction: Action<T, T> = CachingAction(result.dataType) { data ->
|
||||
val path = cacheDirectory /
|
||||
result.taskName.withIndex(result.taskMeta.hashCode().toString(16)).toString() /
|
||||
data.name.toString()
|
||||
@ -83,7 +79,7 @@ public class FileWorkspaceCache(public val cacheDirectory: Path) : WorkspaceCach
|
||||
}
|
||||
}
|
||||
|
||||
//waiting for data in the current scope because Envelope is synchronous
|
||||
//waiting for data in current scope because Envelope is synchronous
|
||||
return@Data data.await().also { result ->
|
||||
val envelope = Envelope {
|
||||
meta = data.meta
|
||||
@ -95,10 +91,12 @@ public class FileWorkspaceCache(public val cacheDirectory: Path) : WorkspaceCach
|
||||
}
|
||||
|
||||
}
|
||||
datum.named(data.name)
|
||||
return datum.named(data.name)
|
||||
}
|
||||
|
||||
val cachedTree = cachingAction(result)
|
||||
|
||||
val cachedTree = result.asSequence().map { cacheOne(it) }
|
||||
.toObservableTree(result.dataType, result.workspace, result.updates().map { cacheOne(it) })
|
||||
|
||||
return result.workspace.wrapResult(cachedTree, result.taskName, result.taskMeta)
|
||||
}
|
||||
|
@ -1,11 +1,8 @@
|
||||
package space.kscience.dataforge.workspace
|
||||
|
||||
import space.kscience.dataforge.actions.Action
|
||||
import space.kscience.dataforge.actions.invoke
|
||||
import space.kscience.dataforge.data.Data
|
||||
import space.kscience.dataforge.data.named
|
||||
import kotlinx.coroutines.flow.map
|
||||
import space.kscience.dataforge.data.*
|
||||
import space.kscience.dataforge.meta.Meta
|
||||
import space.kscience.dataforge.misc.DFExperimental
|
||||
import space.kscience.dataforge.names.Name
|
||||
import kotlin.reflect.KType
|
||||
import kotlin.reflect.full.isSubtypeOf
|
||||
@ -22,18 +19,19 @@ public class InMemoryWorkspaceCache : WorkspaceCache {
|
||||
if (type.isSubtypeOf(taskType)) this as Data<T>
|
||||
else error("Cached data type mismatch: expected $taskType but got $type")
|
||||
|
||||
@OptIn(DFExperimental::class)
|
||||
override suspend fun <T> cache(result: TaskResult<T>): TaskResult<T> {
|
||||
val cachingAction: Action<T, T> = CachingAction(result.dataType) { data ->
|
||||
fun cacheOne(data: NamedData<T>): NamedData<T> {
|
||||
val cachedData = cache.getOrPut(TaskResultId(result.taskName, result.taskMeta)){
|
||||
HashMap()
|
||||
}.getOrPut(data.name){
|
||||
data.data
|
||||
}
|
||||
cachedData.checkType<T>(result.dataType).named(data.name)
|
||||
return cachedData.checkType<T>(result.dataType).named(data.name)
|
||||
}
|
||||
|
||||
val cachedTree = cachingAction(result)
|
||||
|
||||
val cachedTree = result.asSequence().map { cacheOne(it) }
|
||||
.toObservableTree(result.dataType, result.workspace, result.updates().map { cacheOne(it) })
|
||||
|
||||
return result.workspace.wrapResult(cachedTree, result.taskName, result.taskMeta)
|
||||
}
|
||||
|
@ -7,12 +7,14 @@ import space.kscience.dataforge.data.StaticData
|
||||
import space.kscience.dataforge.io.*
|
||||
import space.kscience.dataforge.meta.Meta
|
||||
import space.kscience.dataforge.meta.copy
|
||||
import space.kscience.dataforge.misc.DFExperimental
|
||||
import space.kscience.dataforge.names.Name
|
||||
import space.kscience.dataforge.names.NameToken
|
||||
import space.kscience.dataforge.names.asName
|
||||
import space.kscience.dataforge.names.plus
|
||||
import java.nio.file.*
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
import java.nio.file.StandardWatchEventKinds
|
||||
import java.nio.file.WatchEvent
|
||||
import java.nio.file.attribute.BasicFileAttributes
|
||||
import java.nio.file.spi.FileSystemProvider
|
||||
import kotlin.io.path.*
|
||||
@ -164,25 +166,15 @@ public fun DataSink<Binary>.monitorFiles(
|
||||
* @param resources The names of the resources to read.
|
||||
* @param classLoader The class loader to use for loading the resources. By default, it uses the current thread's context class loader.
|
||||
*/
|
||||
@DFExperimental
|
||||
public fun DataSink<Binary>.resources(
|
||||
io: IOPlugin,
|
||||
resource: String,
|
||||
vararg otherResources: String,
|
||||
vararg resources: String,
|
||||
classLoader: ClassLoader = Thread.currentThread().contextClassLoader,
|
||||
) {
|
||||
//create a file system if necessary
|
||||
val uri = Thread.currentThread().contextClassLoader.getResource("common")!!.toURI()
|
||||
try {
|
||||
uri.toPath()
|
||||
} catch (e: FileSystemNotFoundException) {
|
||||
FileSystems.newFileSystem(uri, mapOf("create" to "true"))
|
||||
}
|
||||
|
||||
listOf(resource,*otherResources).forEach { r ->
|
||||
val path = classLoader.getResource(r)?.toURI()?.toPath() ?: error(
|
||||
"Resource with name $r is not resolved"
|
||||
resources.forEach { resource ->
|
||||
val path = classLoader.getResource(resource)?.toURI()?.toPath() ?: error(
|
||||
"Resource with name $resource is not resolved"
|
||||
)
|
||||
files(io, r.asName(), path)
|
||||
files(io, resource.asName(), path)
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ package space.kscience.dataforge.workspace
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.jupiter.api.Test
|
||||
import space.kscience.dataforge.data.putValue
|
||||
import space.kscience.dataforge.data.wrap
|
||||
import space.kscience.dataforge.meta.Meta
|
||||
import space.kscience.dataforge.meta.boolean
|
||||
import space.kscience.dataforge.meta.get
|
||||
@ -22,7 +22,7 @@ internal class CachingWorkspaceTest {
|
||||
data {
|
||||
//statically initialize data
|
||||
repeat(5) {
|
||||
putValue("myData[$it]", it)
|
||||
wrap("myData[$it]", it)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,7 @@ class DataPropagationTest {
|
||||
}
|
||||
data {
|
||||
repeat(100) {
|
||||
putValue("myData[$it]", it)
|
||||
wrap("myData[$it]", it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,11 +24,11 @@ import kotlin.test.assertEquals
|
||||
class FileDataTest {
|
||||
val dataNode = DataTree<String> {
|
||||
putAll("dir") {
|
||||
putValue("a", "Some string") {
|
||||
wrap("a", "Some string") {
|
||||
"content" put "Some string"
|
||||
}
|
||||
}
|
||||
putValue("b", "root data")
|
||||
wrap("b", "root data")
|
||||
// meta {
|
||||
// "content" put "This is root meta node"
|
||||
// }
|
||||
|
@ -3,11 +3,11 @@ package space.kscience.dataforge.workspace
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.jupiter.api.Test
|
||||
import space.kscience.dataforge.data.putValue
|
||||
import space.kscience.dataforge.data.wrap
|
||||
import space.kscience.dataforge.misc.DFExperimental
|
||||
import java.nio.file.Files
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class, DFExperimental::class)
|
||||
@OptIn(ExperimentalCoroutinesApi::class,DFExperimental::class)
|
||||
class FileWorkspaceCacheTest {
|
||||
|
||||
@Test
|
||||
@ -16,7 +16,7 @@ class FileWorkspaceCacheTest {
|
||||
data {
|
||||
//statically initialize data
|
||||
repeat(5) {
|
||||
putValue("myData[$it]", it)
|
||||
wrap("myData[$it]", it)
|
||||
}
|
||||
}
|
||||
fileCache(Files.createTempDirectory("dataforge-temporary-cache"))
|
||||
|
@ -6,6 +6,7 @@ package space.kscience.dataforge.workspace
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.jupiter.api.Timeout
|
||||
import space.kscience.dataforge.context.*
|
||||
import space.kscience.dataforge.data.*
|
||||
import space.kscience.dataforge.meta.*
|
||||
@ -15,7 +16,6 @@ import space.kscience.dataforge.names.plus
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertTrue
|
||||
import kotlin.time.Duration.Companion.milliseconds
|
||||
|
||||
|
||||
/**
|
||||
@ -62,7 +62,7 @@ internal class SimpleWorkspaceTest {
|
||||
data {
|
||||
//statically initialize data
|
||||
repeat(100) {
|
||||
putValue("myData[$it]", it)
|
||||
wrap("myData[$it]", it)
|
||||
}
|
||||
}
|
||||
|
||||
@ -148,16 +148,18 @@ internal class SimpleWorkspaceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testWorkspace() = runTest(timeout = 100.milliseconds) {
|
||||
@Timeout(1)
|
||||
fun testWorkspace() = runTest {
|
||||
val node = workspace.produce("sum")
|
||||
val res = node.asSequence().single()
|
||||
assertEquals(328350, res.await())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testMetaPropagation() = runTest(timeout = 100.milliseconds) {
|
||||
@Timeout(1)
|
||||
fun testMetaPropagation() = runTest {
|
||||
val node = workspace.produce("sum") { "testFlag" put true }
|
||||
val res = node["sum"]!!.await()
|
||||
val res = node.single().await()
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -186,7 +188,7 @@ internal class SimpleWorkspaceTest {
|
||||
val node = workspace.produce("filterOne") {
|
||||
"name" put "myData[12]"
|
||||
}
|
||||
assertEquals(12, node.asSequence().first().await())
|
||||
assertEquals(12, node.single().await())
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user