Skip to content

Commit

Permalink
feat(mps-model-adapters): full support for recreating an MPS project
Browse files Browse the repository at this point in the history
The bulk sync so far could only synchronize existing models, but not create new ones.
  • Loading branch information
slisson committed Jan 22, 2025
1 parent 3d57f9a commit 16f4e25
Showing 1 changed file with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.modelix.model.persistent

import org.modelix.model.api.IPropertyReference
import org.modelix.model.api.IReferenceLinkReference
import org.modelix.model.lazy.COWArrays.copy
import org.modelix.model.lazy.COWArrays.insert
import org.modelix.model.lazy.COWArrays.remove
Expand Down Expand Up @@ -68,12 +70,14 @@ class CPNode private constructor(
}

fun getPropertyValue(role: String?): String? {
val index = propertyRoles.asList().binarySearch(role)
if (role == null) return null
val index = propertyRoles.indexOfFirst { IPropertyReference.fromUnclassifiedString(it).matches(IPropertyReference.fromUnclassifiedString(role)) }
return if (index < 0) null else propertyValues[index]
}

fun getReferenceTarget(role: String?): CPNodeRef? {
val index = referenceRoles.asList().binarySearch(role)
if (role == null) return null
val index = referenceRoles.indexOfFirst { IReferenceLinkReference.fromUnclassifiedString(it).matches(IReferenceLinkReference.fromUnclassifiedString(role)) }
return if (index < 0) null else referenceTargets[index]
}

Expand Down Expand Up @@ -108,7 +112,7 @@ class CPNode private constructor(
}

fun withPropertyValue(role: String, value: String?): CPNode {
var index = propertyRoles.asList().binarySearch(role)
var index = propertyRoles.indexOf(role)
return if (value == null) {
if (index < 0) {
this
Expand All @@ -127,15 +131,14 @@ class CPNode private constructor(
}
} else {
if (index < 0) {
index = -(index + 1)
create(
id,
concept,
parentId,
roleInParent,
childrenIds,
insert(propertyRoles, index, role),
insert(propertyValues, index, value),
insert(propertyRoles, propertyRoles.size, role),
insert(propertyValues, propertyValues.size, value),
referenceRoles,
referenceTargets,
)
Expand All @@ -156,7 +159,7 @@ class CPNode private constructor(
}

fun withReferenceTarget(role: String, target: CPNodeRef?): CPNode {
var index = referenceRoles.asList().binarySearch(role)
var index = referenceRoles.indexOf(role)
return if (target == null) {
if (index < 0) {
this
Expand All @@ -169,7 +172,6 @@ class CPNode private constructor(
}
} else {
if (index < 0) {
index = -(index + 1)
create(
id,
concept,
Expand All @@ -178,8 +180,8 @@ class CPNode private constructor(
childrenIds,
propertyRoles,
propertyValues,
insert(referenceRoles, index, role),
insert(referenceTargets, index, target),
insert(referenceRoles, referenceRoles.size, role),
insert(referenceTargets, referenceTargets.size, target),
)
} else {
create(
Expand All @@ -190,7 +192,7 @@ class CPNode private constructor(
childrenIds,
propertyRoles,
propertyValues,
referenceRoles,
set(referenceRoles, index, referenceRoles[index]),
set(referenceTargets, index, target),
)
}
Expand Down

0 comments on commit 16f4e25

Please sign in to comment.