Add listOfSpec delegate to Scheme
This commit is contained in:
parent
946ac88480
commit
a32cbe95dc
@ -7,7 +7,7 @@ import space.kscience.dataforge.names.asName
|
|||||||
import kotlin.properties.ReadWriteProperty
|
import kotlin.properties.ReadWriteProperty
|
||||||
import kotlin.reflect.KProperty
|
import kotlin.reflect.KProperty
|
||||||
|
|
||||||
public interface ReadOnlySpecification<out T : Any>: Described {
|
public interface ReadOnlySpecification<out T : Any> : Described {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read generic read-only meta with this [Specification] producing instance of desired type.
|
* Read generic read-only meta with this [Specification] producing instance of desired type.
|
||||||
@ -128,3 +128,10 @@ public fun <T : Scheme> MutableMeta.listOfSpec(
|
|||||||
setIndexed(name, value.map { it.toMeta() })
|
setIndexed(name, value.map { it.toMeta() })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@DFExperimental
|
||||||
|
public fun <T : Scheme> Scheme.listOfSpec(
|
||||||
|
spec: Specification<T>,
|
||||||
|
key: Name? = null,
|
||||||
|
): ReadWriteProperty<Any?, List<T>> = meta.listOfSpec(spec, key)
|
||||||
|
@ -16,13 +16,11 @@ public class Name(public val tokens: List<NameToken>) {
|
|||||||
|
|
||||||
override fun toString(): String = tokens.joinToString(separator = NAME_SEPARATOR) { it.toString() }
|
override fun toString(): String = tokens.joinToString(separator = NAME_SEPARATOR) { it.toString() }
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
override fun equals(other: Any?): Boolean = when (other) {
|
||||||
return when (other) {
|
|
||||||
is Name -> this.tokens == other.tokens
|
is Name -> this.tokens == other.tokens
|
||||||
is NameToken -> this.length == 1 && this.tokens.first() == other
|
is NameToken -> this.length == 1 && this.tokens.first() == other
|
||||||
else -> false
|
else -> false
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private val cachedHashCode = if (tokens.size == 1) {
|
private val cachedHashCode = if (tokens.size == 1) {
|
||||||
tokens.first().hashCode()
|
tokens.first().hashCode()
|
||||||
|
Loading…
Reference in New Issue
Block a user