Fixed bug with meta value removal
This commit is contained in:
parent
4bb95ca793
commit
c6c4509d6c
@ -1,4 +1,4 @@
|
|||||||
val dataforgeVersion by extra("0.1.3-dev-3")
|
val dataforgeVersion by extra("0.1.3-dev-4")
|
||||||
|
|
||||||
allprojects {
|
allprojects {
|
||||||
repositories {
|
repositories {
|
||||||
|
@ -50,7 +50,9 @@ abstract class AbstractMutableMeta<M : MutableMeta<M>> : AbstractMetaNode<M>(),
|
|||||||
protected open fun replaceItem(key: NameToken, oldItem: MetaItem<M>?, newItem: MetaItem<M>?) {
|
protected open fun replaceItem(key: NameToken, oldItem: MetaItem<M>?, newItem: MetaItem<M>?) {
|
||||||
if (newItem == null) {
|
if (newItem == null) {
|
||||||
_items.remove(key)
|
_items.remove(key)
|
||||||
oldItem?.node?.removeListener(this)
|
if(oldItem!= null && oldItem is MetaItem.NodeItem<M>) {
|
||||||
|
oldItem.node.removeListener(this)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
_items[key] = newItem
|
_items[key] = newItem
|
||||||
if (newItem is MetaItem.NodeItem) {
|
if (newItem is MetaItem.NodeItem) {
|
||||||
@ -65,8 +67,8 @@ abstract class AbstractMutableMeta<M : MutableMeta<M>> : AbstractMetaNode<M>(),
|
|||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
protected fun wrapItem(item: MetaItem<*>?): MetaItem<M>? = when (item) {
|
protected fun wrapItem(item: MetaItem<*>?): MetaItem<M>? = when (item) {
|
||||||
null -> null
|
null -> null
|
||||||
is MetaItem.ValueItem -> item as MetaItem<M>
|
is MetaItem.ValueItem -> item
|
||||||
is MetaItem.NodeItem<*> -> MetaItem.NodeItem(wrapNode(item.node))
|
is MetaItem.NodeItem -> MetaItem.NodeItem(wrapNode(item.node))
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -98,8 +100,11 @@ abstract class AbstractMutableMeta<M : MutableMeta<M>> : AbstractMetaNode<M>(),
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun MutableMeta<*>.remove(name: Name) = set(name, null)
|
|
||||||
fun MutableMeta<*>.remove(name: String) = remove(name.toName())
|
@Suppress("NOTHING_TO_INLINE")
|
||||||
|
inline fun MutableMeta<*>.remove(name: Name) = set(name, null)
|
||||||
|
@Suppress("NOTHING_TO_INLINE")
|
||||||
|
inline fun MutableMeta<*>.remove(name: String) = remove(name.toName())
|
||||||
|
|
||||||
fun MutableMeta<*>.setValue(name: Name, value: Value) =
|
fun MutableMeta<*>.setValue(name: Name, value: Value) =
|
||||||
set(name, MetaItem.ValueItem(value))
|
set(name, MetaItem.ValueItem(value))
|
||||||
|
@ -97,7 +97,7 @@ object True : Value {
|
|||||||
override val value: Any? get() = true
|
override val value: Any? get() = true
|
||||||
override val type: ValueType get() = ValueType.BOOLEAN
|
override val type: ValueType get() = ValueType.BOOLEAN
|
||||||
override val number: Number get() = 1.0
|
override val number: Number get() = 1.0
|
||||||
override val string: String get() = "+"
|
override val string: String get() = "true"
|
||||||
|
|
||||||
override fun toString(): String = value.toString()
|
override fun toString(): String = value.toString()
|
||||||
}
|
}
|
||||||
@ -109,7 +109,7 @@ object False : Value {
|
|||||||
override val value: Any? get() = false
|
override val value: Any? get() = false
|
||||||
override val type: ValueType get() = ValueType.BOOLEAN
|
override val type: ValueType get() = ValueType.BOOLEAN
|
||||||
override val number: Number get() = -1.0
|
override val number: Number get() = -1.0
|
||||||
override val string: String get() = "-"
|
override val string: String get() = "false"
|
||||||
}
|
}
|
||||||
|
|
||||||
val Value.boolean get() = this == True || this.list.firstOrNull() == True || (type == ValueType.STRING && string.toBoolean())
|
val Value.boolean get() = this == True || this.list.firstOrNull() == True || (type == ValueType.STRING && string.toBoolean())
|
||||||
|
@ -0,0 +1,22 @@
|
|||||||
|
package hep.dataforge.meta
|
||||||
|
|
||||||
|
import kotlin.test.Test
|
||||||
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
|
class MutableMetaTest{
|
||||||
|
@Test
|
||||||
|
fun testRemove(){
|
||||||
|
val meta = buildMeta {
|
||||||
|
"aNode" to {
|
||||||
|
"innerNode" to {
|
||||||
|
"innerValue" to true
|
||||||
|
}
|
||||||
|
"b" to 22
|
||||||
|
"c" to "StringValue"
|
||||||
|
}
|
||||||
|
}.toConfig()
|
||||||
|
|
||||||
|
meta.remove("aNode.c")
|
||||||
|
assertEquals(meta["aNode.c"], null)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user