Skip to content

Commit 1ab627a

Browse files
author
Oleksandr Dzhychko
committed
fix(model-datastructure): detect changed children in a node if a child node changes its role
1 parent 528a6a0 commit 1ab627a

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

model-datastructure/src/commonMain/kotlin/org/modelix/model/lazy/CLTree.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,9 +450,14 @@ class CLTree : ITree, IBulkTree {
450450
if (oldElement!!::class != newElement!!::class) {
451451
throw RuntimeException("Unsupported type change of node " + key + "from " + oldElement::class.simpleName + " to " + newElement::class.simpleName)
452452
}
453-
if (oldElement.parentId != newElement.parentId || oldElement.roleInParent != newElement.roleInParent) {
453+
if (oldElement.parentId != newElement.parentId) {
454454
visitor.containmentChanged(key)
455455
}
456+
if (oldElement.parentId == newElement.parentId && oldElement.roleInParent != newElement.roleInParent) {
457+
visitor.containmentChanged(key)
458+
visitor.childrenChanged(oldElement.parentId, oldElement.roleInParent)
459+
visitor.childrenChanged(newElement.parentId, newElement.roleInParent)
460+
}
456461
oldElement.propertyRoles.asSequence()
457462
.plus(newElement.propertyRoles.asSequence())
458463
.distinct()

model-datastructure/src/commonMain/kotlin/org/modelix/model/persistent/CPHamtNode.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ import org.modelix.model.persistent.SerializationUtil.intFromHex
2323
import org.modelix.model.persistent.SerializationUtil.longFromHex
2424
import kotlin.jvm.JvmStatic
2525

26+
/**
27+
* Implementation of a hash array mapped trie.
28+
*/
2629
abstract class CPHamtNode : IKVValue {
2730
override var isWritten: Boolean = false
2831

model-datastructure/src/commonTest/kotlin/DiffTest.kt

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,41 @@ class DiffTest {
7070
}
7171
}
7272

73+
@Test
74+
fun moveChildOutsideNode() {
75+
runTest(
76+
setOf(
77+
TreeChangeCollector.ChildrenChangedEvent(ITree.ROOT_ID, "children1"),
78+
TreeChangeCollector.ChildrenChangedEvent(200, "children1"),
79+
TreeChangeCollector.ContainmentChangedEvent(100),
80+
),
81+
{
82+
it.addNewChild(ITree.ROOT_ID, "children1", -1, 100, null as ConceptReference?)
83+
.addNewChild(ITree.ROOT_ID, "children2", -1, 200, null as ConceptReference?)
84+
},
85+
{
86+
it.moveChild(200, "children1", -1, 100)
87+
},
88+
)
89+
}
90+
91+
@Test
92+
fun moveChildInsideNode() {
93+
runTest(
94+
setOf(
95+
TreeChangeCollector.ChildrenChangedEvent(ITree.ROOT_ID, "children1"),
96+
TreeChangeCollector.ChildrenChangedEvent(ITree.ROOT_ID, "children2"),
97+
TreeChangeCollector.ContainmentChangedEvent(100),
98+
),
99+
{
100+
it.addNewChild(ITree.ROOT_ID, "children1", -1, 100, null as ConceptReference?)
101+
},
102+
{
103+
it.moveChild(ITree.ROOT_ID, "children2", -1, 100)
104+
},
105+
)
106+
}
107+
73108
@Test
74109
fun removeChild() {
75110
runTest(
@@ -90,7 +125,11 @@ class DiffTest {
90125
runTest(expectedEvents, { it }, mutator)
91126
}
92127

93-
private fun runTest(expectedEvents: Set<TreeChangeCollector.ChangeEvent>, initialMutator: (ITree) -> ITree, mutator: (ITree) -> ITree) {
128+
private fun runTest(
129+
expectedEvents: Set<TreeChangeCollector.ChangeEvent>,
130+
initialMutator: (ITree) -> ITree,
131+
mutator: (ITree) -> ITree,
132+
) {
94133
val tree1 = initialMutator(CLTree.builder(ObjectStoreCache(MapBaseStore())).build())
95134
val tree2 = mutator(tree1)
96135
val collector = TreeChangeCollector()

0 commit comments

Comments
 (0)