Skip to content

Commit 6fcc489

Browse files
author
Oleksandr Dzhychko
committed
feat(model-api): Introduce property to specify whether a child link is ordered
1 parent 56a1e02 commit 6fcc489

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

model-api/src/commonMain/kotlin/org/modelix/model/api/IChildLink.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ interface IChildLink : ILink {
3030
companion object {
3131
fun fromName(name: String): IChildLink = ChildLinkFromName(name)
3232
}
33+
34+
/**
35+
* Whether children with this role are returned in a meaningful order and whether they are allowed to be reordered.
36+
*
37+
* Children returned for an unordered role might be returned in a different order in subsequent request.
38+
* If a child role is not ordered, implementations of [[INode.moveChild]] are allowed to fail
39+
* when instructed to move a node in between existing nodes.
40+
*/
41+
val isOrdered
42+
get() = true
3343
}
3444

3545
data class ChildLinkFromName(override val name: String) : LinkFromName(), IChildLink {

model-api/src/commonMain/kotlin/org/modelix/model/api/INode.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,21 @@ fun INode.tryResolveProperty(role: String): IProperty? {
380380
?: allLinks.find { it.getSimpleName() == role }
381381
?: allLinks.find { it.getUID() == role }
382382
}
383+
384+
/**
385+
* Resolves whether the child link is ordered or not.
386+
*
387+
* Assume children to be ordered by default.
388+
* Unordered children are the special case that can be declared by setting [[IChildLink.isOrdered]] to `false`.
389+
*/
390+
fun INode.isChildRoleOrdered(role: String?): Boolean {
391+
return if (role == null) {
392+
true
393+
} else {
394+
this.tryResolveChildLink(role)?.isOrdered ?: true
395+
}
396+
}
397+
383398
fun INode.resolvePropertyOrFallback(role: String): IProperty {
384399
return tryResolveProperty(role) ?: IProperty.fromName(role)
385400
}

model-api/src/commonMain/kotlin/org/modelix/model/api/SimpleChildLink.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class SimpleChildLink(
1919
override val isOptional: Boolean,
2020
override val targetConcept: IConcept,
2121
private val uid: String? = null,
22+
override val isOrdered: Boolean = true,
2223
) : IChildLink {
2324
var owner: SimpleConcept? = null
2425
override val childConcept: IConcept = targetConcept

0 commit comments

Comments
 (0)