Indexed access test
This commit is contained in:
parent
417c292507
commit
e0aab57953
@ -6,7 +6,6 @@ import hep.dataforge.values.Value
|
||||
/**
|
||||
* Convert meta to map of maps
|
||||
*/
|
||||
@DFExperimental
|
||||
fun Meta.toMap(descriptor: NodeDescriptor? = null): Map<String, Any?> {
|
||||
return items.entries.associate { (token, item) ->
|
||||
token.toString() to when (item) {
|
||||
@ -19,7 +18,6 @@ fun Meta.toMap(descriptor: NodeDescriptor? = null): Map<String, Any?> {
|
||||
/**
|
||||
* Convert map of maps to meta
|
||||
*/
|
||||
@DFExperimental
|
||||
fun Map<String, Any?>.toMeta(descriptor: NodeDescriptor? = null): Meta = Meta {
|
||||
entries.forEach { (key, value) ->
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
|
@ -4,7 +4,8 @@ import hep.dataforge.names.Name
|
||||
import hep.dataforge.names.toName
|
||||
|
||||
/**
|
||||
* Get all items matching given name.
|
||||
* Get all items matching given name. The index of the last element, if present is used as a [Regex],
|
||||
* against which indexes of elements are matched.
|
||||
*/
|
||||
fun Meta.getIndexed(name: Name): Map<String, MetaItem<*>> {
|
||||
val root = when (name.length) {
|
||||
|
@ -49,4 +49,17 @@ class MetaTest {
|
||||
|
||||
assertEquals(meta, reconstructed)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun indexed() {
|
||||
val meta = Meta {
|
||||
(0..20).forEach {
|
||||
set("a[$it]", it)
|
||||
}
|
||||
}
|
||||
val indexed = meta.getIndexed("a[1.]")
|
||||
assertEquals(10, indexed.size)
|
||||
assertEquals(null, indexed["8"])
|
||||
assertEquals(12, indexed["12"].int)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user