refactor MutableMeta set method to accept wider range of receivers
This commit is contained in:
parent
6ca76cff17
commit
81e2ad06cc
@ -1,12 +1,12 @@
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
|
||||
plugins {
|
||||
id("ru.mipt.npm.gradle.project")
|
||||
id("space.kscience.gradle.project")
|
||||
}
|
||||
|
||||
allprojects {
|
||||
group = "space.kscience"
|
||||
version = "0.6.0-dev-10"
|
||||
version = "0.6.0-dev-12"
|
||||
}
|
||||
|
||||
subprojects {
|
||||
|
@ -1,6 +1,6 @@
|
||||
plugins {
|
||||
id("ru.mipt.npm.gradle.mpp")
|
||||
id("ru.mipt.npm.gradle.native")
|
||||
id("space.kscience.gradle.mpp")
|
||||
id("space.kscience.gradle.native")
|
||||
}
|
||||
|
||||
description = "Context and provider definitions"
|
||||
@ -31,5 +31,5 @@ kotlin {
|
||||
}
|
||||
|
||||
readme {
|
||||
maturity = ru.mipt.npm.gradle.Maturity.DEVELOPMENT
|
||||
maturity = space.kscience.gradle.Maturity.DEVELOPMENT
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
plugins {
|
||||
id("ru.mipt.npm.gradle.mpp")
|
||||
id("ru.mipt.npm.gradle.native")
|
||||
id("space.kscience.gradle.mpp")
|
||||
id("space.kscience.gradle.native")
|
||||
}
|
||||
|
||||
kscience{
|
||||
@ -19,5 +19,5 @@ kotlin {
|
||||
}
|
||||
|
||||
readme{
|
||||
maturity = ru.mipt.npm.gradle.Maturity.EXPERIMENTAL
|
||||
maturity = space.kscience.gradle.Maturity.EXPERIMENTAL
|
||||
}
|
||||
|
@ -1,14 +1,14 @@
|
||||
import ru.mipt.npm.gradle.KScienceVersions
|
||||
import space.kscience.gradle.KScienceVersions
|
||||
|
||||
plugins {
|
||||
id("ru.mipt.npm.gradle.mpp")
|
||||
id("ru.mipt.npm.gradle.native")
|
||||
id("space.kscience.gradle.mpp")
|
||||
id("space.kscience.gradle.native")
|
||||
}
|
||||
|
||||
description = "IO module"
|
||||
|
||||
kscience {
|
||||
useSerialization(sourceSet = ru.mipt.npm.gradle.DependencySourceSet.TEST) {
|
||||
useSerialization(sourceSet = space.kscience.gradle.DependencySourceSet.TEST) {
|
||||
cbor()
|
||||
}
|
||||
}
|
||||
@ -27,5 +27,5 @@ kotlin {
|
||||
}
|
||||
|
||||
readme{
|
||||
maturity = ru.mipt.npm.gradle.Maturity.PROTOTYPE
|
||||
maturity = space.kscience.gradle.Maturity.PROTOTYPE
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
plugins {
|
||||
id("ru.mipt.npm.gradle.mpp")
|
||||
// id("ru.mipt.npm.gradle.native")
|
||||
id("space.kscience.gradle.mpp")
|
||||
// id("space.kscience.gradle.native")
|
||||
}
|
||||
|
||||
description = "YAML meta IO"
|
||||
@ -26,7 +26,7 @@ kotlin {
|
||||
}
|
||||
|
||||
readme{
|
||||
maturity = ru.mipt.npm.gradle.Maturity.PROTOTYPE
|
||||
maturity = space.kscience.gradle.Maturity.PROTOTYPE
|
||||
description ="""
|
||||
YAML meta converters and Front Matter envelope format
|
||||
""".trimIndent()
|
||||
|
@ -2,8 +2,8 @@ package space.kscience.dataforge.io
|
||||
|
||||
import space.kscience.dataforge.context.ContextBuilder
|
||||
import space.kscience.dataforge.meta.get
|
||||
import space.kscience.dataforge.meta.set
|
||||
import space.kscience.dataforge.meta.string
|
||||
import space.kscience.dataforge.values.set
|
||||
import java.nio.file.Path
|
||||
import kotlin.io.path.Path
|
||||
|
||||
@ -23,6 +23,6 @@ public fun ContextBuilder.workDirectory(path: String) {
|
||||
}
|
||||
}
|
||||
|
||||
public fun ContextBuilder.workDirectory(path: Path){
|
||||
public fun ContextBuilder.workDirectory(path: Path) {
|
||||
workDirectory(path.toAbsolutePath().toString())
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
plugins {
|
||||
id("ru.mipt.npm.gradle.mpp")
|
||||
id("ru.mipt.npm.gradle.native")
|
||||
id("space.kscience.gradle.mpp")
|
||||
id("space.kscience.gradle.native")
|
||||
}
|
||||
|
||||
kscience {
|
||||
@ -12,5 +12,5 @@ kscience {
|
||||
description = "Meta definition and basic operations on meta"
|
||||
|
||||
readme{
|
||||
maturity = ru.mipt.npm.gradle.Maturity.DEVELOPMENT
|
||||
maturity = space.kscience.gradle.Maturity.DEVELOPMENT
|
||||
}
|
@ -109,7 +109,7 @@ public operator fun Meta.get(name: Name): Meta? = this.getMeta(name)
|
||||
/**
|
||||
* Parse [Name] from [key] using full name notation and pass it to [Meta.get]
|
||||
*/
|
||||
public operator fun Meta.get(key: String): Meta? = this.get(Name.parse(key))
|
||||
public operator fun Meta.get(key: String): Meta? = this[Name.parse(key)]
|
||||
|
||||
/**
|
||||
* Get all items matching given name. The index of the last element, if present is used as a [Regex],
|
||||
|
@ -23,9 +23,7 @@ public annotation class MetaBuilder
|
||||
public interface MutableMetaProvider : MetaProvider, MutableValueProvider {
|
||||
override fun getMeta(name: Name): MutableMeta?
|
||||
public fun setMeta(name: Name, node: Meta?)
|
||||
override fun setValue(name: Name, value: Value?) {
|
||||
getMeta(name)?.value = value
|
||||
}
|
||||
override fun setValue(name: Name, value: Value?)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -144,12 +142,12 @@ public interface MutableMeta : Meta, MutableMetaProvider {
|
||||
/**
|
||||
* Set or replace node at given [name]
|
||||
*/
|
||||
public operator fun MutableMeta.set(name: Name, meta: Meta): Unit = setMeta(name, meta)
|
||||
public operator fun MutableMetaProvider.set(name: Name, meta: Meta): Unit = setMeta(name, meta)
|
||||
|
||||
/**
|
||||
* Set or replace value at given [name]
|
||||
*/
|
||||
public operator fun MutableMeta.set(name: Name, value: Value?): Unit = setValue(name, value)
|
||||
public operator fun MutableValueProvider.set(name: Name, value: Value?): Unit = setValue(name, value)
|
||||
|
||||
public fun MutableMeta.getOrCreate(key: String): MutableMeta = getOrCreate(Name.parse(key))
|
||||
|
||||
@ -179,26 +177,6 @@ public fun MutableMetaProvider.remove(key: String) {
|
||||
public operator fun MutableMetaProvider.set(Key: NameToken, value: Meta): Unit = setMeta(Key.asName(), value)
|
||||
public operator fun MutableMetaProvider.set(key: String, value: Meta): Unit = setMeta(Name.parse(key), value)
|
||||
|
||||
//value setters
|
||||
|
||||
public operator fun MutableMeta.set(name: NameToken, value: Value?): Unit = set(name.asName(), value)
|
||||
public operator fun MutableMeta.set(key: String, value: Value?): Unit = set(Name.parse(key), value)
|
||||
|
||||
public operator fun MutableMeta.set(name: Name, value: String): Unit = set(name, value.asValue())
|
||||
public operator fun MutableMeta.set(name: NameToken, value: String): Unit = set(name.asName(), value.asValue())
|
||||
public operator fun MutableMeta.set(key: String, value: String): Unit = set(Name.parse(key), value.asValue())
|
||||
|
||||
public operator fun MutableMeta.set(name: Name, value: Boolean): Unit = set(name, value.asValue())
|
||||
public operator fun MutableMeta.set(name: NameToken, value: Boolean): Unit = set(name.asName(), value.asValue())
|
||||
public operator fun MutableMeta.set(key: String, value: Boolean): Unit = set(Name.parse(key), value.asValue())
|
||||
|
||||
public operator fun MutableMeta.set(name: Name, value: Number): Unit = set(name, value.asValue())
|
||||
public operator fun MutableMeta.set(name: NameToken, value: Number): Unit = set(name.asName(), value.asValue())
|
||||
public operator fun MutableMeta.set(key: String, value: Number): Unit = set(Name.parse(key), value.asValue())
|
||||
|
||||
public operator fun MutableMeta.set(name: Name, value: List<Value>): Unit = set(name, value.asValue())
|
||||
public operator fun MutableMeta.set(name: NameToken, value: List<Value>): Unit = set(name.asName(), value.asValue())
|
||||
public operator fun MutableMeta.set(key: String, value: List<Value>): Unit = set(Name.parse(key), value.asValue())
|
||||
|
||||
//public fun MutableMeta.set(key: String, index: String, value: Value?): Unit =
|
||||
// set(key.toName().withIndex(index), value)
|
||||
@ -207,7 +185,7 @@ public operator fun MutableMeta.set(key: String, value: List<Value>): Unit = set
|
||||
/* Same name siblings generation */
|
||||
|
||||
|
||||
public fun MutableMeta.setIndexed(
|
||||
public fun MutableMetaProvider.setIndexed(
|
||||
name: Name,
|
||||
metas: Iterable<Meta>,
|
||||
indexFactory: (Meta, index: Int) -> String = { _, index -> index.toString() },
|
||||
@ -221,10 +199,10 @@ public fun MutableMeta.setIndexed(
|
||||
}
|
||||
}
|
||||
|
||||
public operator fun MutableMeta.set(name: Name, metas: Iterable<Meta>): Unit =
|
||||
public operator fun MutableMetaProvider.set(name: Name, metas: Iterable<Meta>): Unit =
|
||||
setIndexed(name, metas)
|
||||
|
||||
public operator fun MutableMeta.set(key: String, metas: Iterable<Meta>): Unit =
|
||||
public operator fun MutableMetaProvider.set(key: String, metas: Iterable<Meta>): Unit =
|
||||
setIndexed(Name.parse(key), metas)
|
||||
|
||||
|
||||
@ -234,7 +212,7 @@ public operator fun MutableMeta.set(key: String, metas: Iterable<Meta>): Unit =
|
||||
* * node updates node and replaces anything but node
|
||||
* * node list updates node list if number of nodes in the list is the same and replaces anything otherwise
|
||||
*/
|
||||
public fun MutableMeta.update(meta: Meta) {
|
||||
public fun MutableMetaProvider.update(meta: Meta) {
|
||||
meta.valueSequence().forEach { (name, value) ->
|
||||
set(name, value)
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import space.kscience.dataforge.names.length
|
||||
import space.kscience.dataforge.values.Value
|
||||
import space.kscience.dataforge.values.ValueType
|
||||
import space.kscience.dataforge.values.asValue
|
||||
import space.kscience.dataforge.values.set
|
||||
import kotlin.collections.set
|
||||
|
||||
public class MetaDescriptorBuilder @PublishedApi internal constructor() {
|
||||
|
@ -6,6 +6,7 @@ import space.kscience.dataforge.misc.DFExperimental
|
||||
import space.kscience.dataforge.names.Name
|
||||
import space.kscience.dataforge.values.ListValue
|
||||
import space.kscience.dataforge.values.Value
|
||||
import space.kscience.dataforge.values.setValue
|
||||
|
||||
/**
|
||||
* Convert meta to map of maps
|
||||
@ -43,7 +44,7 @@ public fun Map<String, Any?>.toMeta(@Suppress("UNUSED_PARAMETER") descriptor: Me
|
||||
if (value is List<*>) {
|
||||
val items = value.map { toMeta(it) }
|
||||
if (items.all { it.isLeaf }) {
|
||||
set(key, ListValue(items.map { it.value!! }))
|
||||
setValue(key, ListValue(items.map { it.value!! }))
|
||||
} else {
|
||||
setIndexed(Name.parse(key), value.map { toMeta(it) })
|
||||
}
|
||||
|
@ -1,6 +1,9 @@
|
||||
package space.kscience.dataforge.values
|
||||
|
||||
import space.kscience.dataforge.meta.set
|
||||
import space.kscience.dataforge.names.Name
|
||||
import space.kscience.dataforge.names.NameToken
|
||||
import space.kscience.dataforge.names.asName
|
||||
|
||||
/**
|
||||
* An object that could provide values
|
||||
@ -21,3 +24,24 @@ public interface MutableValueProvider : ValueProvider {
|
||||
public fun MutableValueProvider.setValue(key: String, value: Value?) {
|
||||
setValue(Name.parse(key), value)
|
||||
}
|
||||
|
||||
//value setters
|
||||
|
||||
public operator fun MutableValueProvider.set(name: NameToken, value: Value?): Unit = set(name.asName(), value)
|
||||
public operator fun MutableValueProvider.set(key: String, value: Value?): Unit = set(Name.parse(key), value)
|
||||
|
||||
public operator fun MutableValueProvider.set(name: Name, value: String): Unit = set(name, value.asValue())
|
||||
public operator fun MutableValueProvider.set(name: NameToken, value: String): Unit = set(name.asName(), value.asValue())
|
||||
public operator fun MutableValueProvider.set(key: String, value: String): Unit = set(Name.parse(key), value.asValue())
|
||||
|
||||
public operator fun MutableValueProvider.set(name: Name, value: Boolean): Unit = set(name, value.asValue())
|
||||
public operator fun MutableValueProvider.set(name: NameToken, value: Boolean): Unit = set(name.asName(), value.asValue())
|
||||
public operator fun MutableValueProvider.set(key: String, value: Boolean): Unit = set(Name.parse(key), value.asValue())
|
||||
|
||||
public operator fun MutableValueProvider.set(name: Name, value: Number): Unit = set(name, value.asValue())
|
||||
public operator fun MutableValueProvider.set(name: NameToken, value: Number): Unit = set(name.asName(), value.asValue())
|
||||
public operator fun MutableValueProvider.set(key: String, value: Number): Unit = set(Name.parse(key), value.asValue())
|
||||
|
||||
public operator fun MutableValueProvider.set(name: Name, value: List<Value>): Unit = set(name, value.asValue())
|
||||
public operator fun MutableValueProvider.set(name: NameToken, value: List<Value>): Unit = set(name.asName(), value.asValue())
|
||||
public operator fun MutableValueProvider.set(key: String, value: List<Value>): Unit = set(Name.parse(key), value.asValue())
|
||||
|
@ -1,5 +1,6 @@
|
||||
package space.kscience.dataforge.meta
|
||||
|
||||
import space.kscience.dataforge.values.set
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
|
@ -2,6 +2,7 @@ package space.kscience.dataforge.meta
|
||||
|
||||
import space.kscience.dataforge.values.Value
|
||||
import space.kscience.dataforge.values.asValue
|
||||
import space.kscience.dataforge.values.set
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
@ -25,9 +26,9 @@ class MetaBuilderTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testSNS(){
|
||||
fun testSNS() {
|
||||
val meta = Meta {
|
||||
repeat(10){
|
||||
repeat(10) {
|
||||
"b.a[$it]" put it
|
||||
}
|
||||
}.seal()
|
||||
|
@ -1,5 +1,6 @@
|
||||
package space.kscience.dataforge.meta
|
||||
|
||||
import space.kscience.dataforge.values.set
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
|
@ -4,6 +4,7 @@ import space.kscience.dataforge.misc.DFExperimental
|
||||
import space.kscience.dataforge.values.NumberValue
|
||||
import space.kscience.dataforge.values.True
|
||||
import space.kscience.dataforge.values.Value
|
||||
import space.kscience.dataforge.values.set
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
plugins {
|
||||
id("ru.mipt.npm.gradle.mpp")
|
||||
id("ru.mipt.npm.gradle.native")
|
||||
id("space.kscience.gradle.mpp")
|
||||
id("space.kscience.gradle.native")
|
||||
}
|
||||
|
||||
kotlin {
|
||||
|
@ -1,5 +1,5 @@
|
||||
plugins {
|
||||
id("ru.mipt.npm.gradle.mpp")
|
||||
id("space.kscience.gradle.mpp")
|
||||
}
|
||||
|
||||
kotlin {
|
||||
@ -25,5 +25,5 @@ kotlin {
|
||||
}
|
||||
|
||||
readme{
|
||||
maturity = ru.mipt.npm.gradle.Maturity.PROTOTYPE
|
||||
maturity = space.kscience.gradle.Maturity.PROTOTYPE
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
plugins {
|
||||
id("ru.mipt.npm.gradle.mpp")
|
||||
id("ru.mipt.npm.gradle.native")
|
||||
id("space.kscience.gradle.mpp")
|
||||
id("space.kscience.gradle.native")
|
||||
}
|
||||
|
||||
kscience{
|
||||
@ -20,5 +20,5 @@ kotlin {
|
||||
}
|
||||
|
||||
readme{
|
||||
maturity = ru.mipt.npm.gradle.Maturity.EXPERIMENTAL
|
||||
maturity = space.kscience.gradle.Maturity.EXPERIMENTAL
|
||||
}
|
@ -3,6 +3,6 @@ org.gradle.jvmargs=-Xmx4096m
|
||||
|
||||
kotlin.code.style=official
|
||||
kotlin.mpp.stability.nowarn=true
|
||||
#kotlin.incremental.js.ir=true
|
||||
kotlin.incremental.js.ir=true
|
||||
|
||||
toolsVersion=0.11.7-kotlin-1.7.0
|
||||
toolsVersion=0.12.0-kotlin-1.7.20-Beta
|
||||
|
@ -15,10 +15,10 @@ pluginManagement {
|
||||
}
|
||||
|
||||
plugins {
|
||||
id("ru.mipt.npm.gradle.project") version toolsVersion
|
||||
id("ru.mipt.npm.gradle.mpp") version toolsVersion
|
||||
id("ru.mipt.npm.gradle.jvm") version toolsVersion
|
||||
id("ru.mipt.npm.gradle.js") version toolsVersion
|
||||
id("space.kscience.gradle.project") version toolsVersion
|
||||
id("space.kscience.gradle.mpp") version toolsVersion
|
||||
id("space.kscience.gradle.jvm") version toolsVersion
|
||||
id("space.kscience.gradle.js") version toolsVersion
|
||||
}
|
||||
}
|
||||
|
||||
@ -34,7 +34,7 @@ dependencyResolutionManagement {
|
||||
|
||||
versionCatalogs {
|
||||
create("npmlibs") {
|
||||
from("ru.mipt.npm:version-catalog:$toolsVersion")
|
||||
from("space.kscience:version-catalog:$toolsVersion")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user