diff --git a/build.gradle.kts b/build.gradle.kts index b24c5a70..2dcf5b24 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,4 +1,4 @@ -val dataforgeVersion by extra("0.1.3-dev-3") +val dataforgeVersion by extra("0.1.3-dev-4") allprojects { repositories { diff --git a/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/MutableMeta.kt b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/MutableMeta.kt index aebb18d6..2be5c1a0 100644 --- a/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/MutableMeta.kt +++ b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/MutableMeta.kt @@ -50,7 +50,9 @@ abstract class AbstractMutableMeta> : AbstractMetaNode(), protected open fun replaceItem(key: NameToken, oldItem: MetaItem?, newItem: MetaItem?) { if (newItem == null) { _items.remove(key) - oldItem?.node?.removeListener(this) + if(oldItem!= null && oldItem is MetaItem.NodeItem) { + oldItem.node.removeListener(this) + } } else { _items[key] = newItem if (newItem is MetaItem.NodeItem) { @@ -65,8 +67,8 @@ abstract class AbstractMutableMeta> : AbstractMetaNode(), @Suppress("UNCHECKED_CAST") protected fun wrapItem(item: MetaItem<*>?): MetaItem? = when (item) { null -> null - is MetaItem.ValueItem -> item as MetaItem - is MetaItem.NodeItem<*> -> MetaItem.NodeItem(wrapNode(item.node)) + is MetaItem.ValueItem -> item + is MetaItem.NodeItem -> MetaItem.NodeItem(wrapNode(item.node)) } /** @@ -98,8 +100,11 @@ abstract class AbstractMutableMeta> : AbstractMetaNode(), } } -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) = set(name, MetaItem.ValueItem(value)) diff --git a/dataforge-meta/src/commonMain/kotlin/hep/dataforge/values/Value.kt b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/values/Value.kt index 20f86779..5753512b 100644 --- a/dataforge-meta/src/commonMain/kotlin/hep/dataforge/values/Value.kt +++ b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/values/Value.kt @@ -97,7 +97,7 @@ object True : Value { override val value: Any? get() = true override val type: ValueType get() = ValueType.BOOLEAN override val number: Number get() = 1.0 - override val string: String get() = "+" + override val string: String get() = "true" override fun toString(): String = value.toString() } @@ -109,7 +109,7 @@ object False : Value { override val value: Any? get() = false override val type: ValueType get() = ValueType.BOOLEAN 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()) diff --git a/dataforge-meta/src/commonTest/kotlin/hep/dataforge/meta/MutableMetaTest.kt b/dataforge-meta/src/commonTest/kotlin/hep/dataforge/meta/MutableMetaTest.kt new file mode 100644 index 00000000..5ab75fd4 --- /dev/null +++ b/dataforge-meta/src/commonTest/kotlin/hep/dataforge/meta/MutableMetaTest.kt @@ -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) + } +} \ No newline at end of file