Compare commits

..

No commits in common. "261c415d3dee09d2628e00ff6e408eba0cac8a41" and "706521a6b6072517ee6d070e821e5d000b69a782" have entirely different histories.

5 changed files with 20 additions and 29 deletions

View File

@ -6,7 +6,6 @@
- Added separate `Meta`, `SealedMeta` and `ObservableMutableMeta` builders.
### Changed
- Meta converter `metaToObject` returns a non-nullable type. Additional method `metaToObjectOrNull` for nullable return.
- Kotlin 1.9.20.
- Migrated from ktor-io to kotlinx-io.
- `MutableMeta` builder now returns a simplified version of meta that does not hold listeners.

View File

@ -8,7 +8,7 @@ plugins {
allprojects {
group = "space.kscience"
version = "0.7.0-dev-1"
version = "0.6.3-dev-1"
}
subprojects {

View File

@ -6,77 +6,74 @@ import space.kscience.dataforge.meta.*
* A converter of generic object to and from [Meta]
*/
public interface MetaConverter<T> {
/**
* Attempt conversion of [meta] to an object or return null if conversion failed
*/
public fun metaToObjectOrNull(meta: Meta): T?
public fun metaToObject(meta: Meta): T =
metaToObjectOrNull(meta) ?: error("Meta $meta could not be interpreted by $this")
public fun metaToObject(meta: Meta): T?
public fun objectToMeta(obj: T): Meta
public companion object {
public val meta: MetaConverter<Meta> = object : MetaConverter<Meta> {
override fun metaToObjectOrNull(meta: Meta): Meta = meta
override fun metaToObject(meta: Meta): Meta = meta
override fun objectToMeta(obj: Meta): Meta = obj
}
public val value: MetaConverter<Value> = object : MetaConverter<Value> {
override fun metaToObjectOrNull(meta: Meta): Value? = meta.value
override fun metaToObject(meta: Meta): Value? = meta.value
override fun objectToMeta(obj: Value): Meta = Meta(obj)
}
public val string: MetaConverter<String> = object : MetaConverter<String> {
override fun metaToObjectOrNull(meta: Meta): String? = meta.string
override fun metaToObject(meta: Meta): String? = meta.string
override fun objectToMeta(obj: String): Meta = Meta(obj.asValue())
}
public val boolean: MetaConverter<Boolean> = object : MetaConverter<Boolean> {
override fun metaToObjectOrNull(meta: Meta): Boolean? = meta.boolean
override fun metaToObject(meta: Meta): Boolean? = meta.boolean
override fun objectToMeta(obj: Boolean): Meta = Meta(obj.asValue())
}
public val number: MetaConverter<Number> = object : MetaConverter<Number> {
override fun metaToObjectOrNull(meta: Meta): Number? = meta.number
override fun metaToObject(meta: Meta): Number? = meta.number
override fun objectToMeta(obj: Number): Meta = Meta(obj.asValue())
}
public val double: MetaConverter<Double> = object : MetaConverter<Double> {
override fun metaToObjectOrNull(meta: Meta): Double? = meta.double
override fun metaToObject(meta: Meta): Double? = meta.double
override fun objectToMeta(obj: Double): Meta = Meta(obj.asValue())
}
public val float: MetaConverter<Float> = object : MetaConverter<Float> {
override fun metaToObjectOrNull(meta: Meta): Float? = meta.float
override fun metaToObject(meta: Meta): Float? = meta.float
override fun objectToMeta(obj: Float): Meta = Meta(obj.asValue())
}
public val int: MetaConverter<Int> = object : MetaConverter<Int> {
override fun metaToObjectOrNull(meta: Meta): Int? = meta.int
override fun metaToObject(meta: Meta): Int? = meta.int
override fun objectToMeta(obj: Int): Meta = Meta(obj.asValue())
}
public val long: MetaConverter<Long> = object : MetaConverter<Long> {
override fun metaToObjectOrNull(meta: Meta): Long? = meta.long
override fun metaToObject(meta: Meta): Long? = meta.long
override fun objectToMeta(obj: Long): Meta = Meta(obj.asValue())
}
public inline fun <reified E : Enum<E>> enum(): MetaConverter<E> = object : MetaConverter<E> {
@Suppress("USELESS_CAST")
override fun metaToObjectOrNull(meta: Meta): E = meta.enum<E>() as? E ?: error("The Item is not a Enum")
override fun metaToObject(meta: Meta): E = meta.enum<E>() as? E ?: error("The Item is not a Enum")
override fun objectToMeta(obj: E): Meta = Meta(obj.asValue())
}
public fun <T> valueList(
writer: (T) -> Value = { Value.of(it) },
reader: (Value) -> T,
reader: (Value) -> T
): MetaConverter<List<T>> =
object : MetaConverter<List<T>> {
override fun metaToObjectOrNull(meta: Meta): List<T>? = meta.value?.list?.map(reader)
override fun metaToObject(meta: Meta): List<T> =
meta.value?.list?.map(reader) ?: error("The item is not a value list")
override fun objectToMeta(obj: List<T>): Meta = Meta(obj.map(writer).asValue())
}

View File

@ -134,11 +134,6 @@ public val Name.length: Int get() = tokens.size
*/
public fun Name.lastOrNull(): NameToken? = tokens.lastOrNull()
/**
* Last token or throw exception
*/
public fun Name.last(): NameToken = tokens.last()
/**
* First token of the name or null if it is empty
*/

View File

@ -6,5 +6,5 @@ kotlin.mpp.stability.nowarn=true
kotlin.incremental.js.ir=true
kotlin.native.ignoreDisabledTargets=true
toolsVersion=0.15.0-kotlin-1.9.20-RC2
toolsVersion=0.15.0-kotlin-1.9.20-RC
#kotlin.experimental.tryK2=true