Skip to content

Commit f085cc3

Browse files
committed
feat(bulk-model-sync): allow the IModelMask to filter the result of getAllChildren
1 parent 6a3fd4c commit f085cc3

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

bulk-model-sync-lib/src/commonMain/kotlin/org/modelix/model/sync/bulk/IModelMask.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ interface IModelMask {
1212
.toSet()
1313
return children.filter { included.contains(it) }
1414
}
15+
16+
fun <T : IReadableNode> getFilteredChildren(parent: T): List<T> {
17+
return filterChildren(parent, parent.getAllChildren() as List<T>)
18+
}
1519
}
1620

1721
class UnfilteredModelMask : IModelMask {

bulk-model-sync-lib/src/commonMain/kotlin/org/modelix/model/sync/bulk/ModelSynchronizer.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class ModelSynchronizer(
119119
syncChildren(sourceNode, conceptCorrectedTargetNode, forceSyncDescendants)
120120
}
121121
} else if (filter.needsDescentIntoSubtree(sourceNode)) {
122-
for (sourceChild in sourceMask.filterChildren(sourceNode, sourceNode.getAllChildren())) {
122+
for (sourceChild in sourceMask.getFilteredChildren(sourceNode)) {
123123
runSafe {
124124
val targetChild = nodeAssociation.resolveTarget(sourceChild)
125125
?: error("Expected target node was not found. sourceChild=${sourceChild.getNodeReference()}, originalId=${sourceChild.getOriginalReference()}")
@@ -173,8 +173,8 @@ class ModelSynchronizer(
173173

174174
private fun syncChildren(sourceParent: IReadableNode, targetParent: IWritableNode, forceSyncDescendants: Boolean) {
175175
iterateMergedRoles(
176-
sourceParent.getAllChildren().map { it.getContainmentLink() }.distinct(),
177-
targetParent.getAllChildren().map { it.getContainmentLink() }.distinct(),
176+
sourceMask.getFilteredChildren(sourceParent).map { it.getContainmentLink() }.distinct(),
177+
targetMask.getFilteredChildren(targetParent).map { it.getContainmentLink() }.distinct(),
178178
) { role ->
179179
runSafe {
180180
syncChildrenInRole(sourceParent, role, targetParent, forceSyncDescendants)

0 commit comments

Comments
 (0)