Skip to content

Commit a0d90ea

Browse files
committed
docs(model-sync-lib): added documentation
1 parent 030fc83 commit a0d90ea

File tree

5 files changed

+43
-1
lines changed

5 files changed

+43
-1
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,15 @@ import org.modelix.model.api.serialize
55
import org.modelix.model.data.NodeData
66
import org.modelix.model.data.associateWithNotNull
77

8+
/**
9+
* A ModelExporter exports a node and its subtree in bulk.
10+
*/
811
expect class ModelExporter(root: INode)
912

13+
/**
14+
* Returns a [NodeData] representation of the receiver node as it would be exported by a [ModelExporter].
15+
* This function is recursively called on the node's children.
16+
*/
1017
fun INode.asExported() : NodeData {
1118
val idKey = NodeData.idPropertyKey
1219
return NodeData(

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,27 @@ import org.modelix.model.api.*
44
import org.modelix.model.data.ModelData
55
import org.modelix.model.data.NodeData
66

7+
/**
8+
* A ModelImporter updates an existing [INode] and its subtree based on a [ModelData] specification.
9+
*
10+
* The import is incremental.
11+
* Instead of simply overwriting the existing model, only a minimal amount of operations is used.
12+
*
13+
* Properties, references, and child links are synchronized for this node and all of its (in-)direct children.
14+
*
15+
* @param root the root node to be updated
16+
*/
717
class ModelImporter(private val root: INode) {
818

919
private val originalIdToExisting: MutableMap<String, INode> = mutableMapOf()
1020
private val postponedReferences = ArrayList<() -> Unit>()
1121
private val nodesToRemove = HashSet<INode>()
12-
22+
23+
/**
24+
* Incrementally updates this importers root based on the provided [ModelData] specification.
25+
*
26+
* @param data the model specification
27+
*/
1328
fun import(data: ModelData) {
1429
originalIdToExisting.clear()
1530
postponedReferences.clear()

model-sync-lib/src/jsMain/kotlin/org/modelix/model/sync/ModelExporter.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,11 @@ package org.modelix.model.sync
33
import org.modelix.model.api.INode
44

55
actual class ModelExporter actual constructor(private val root: INode) {
6+
7+
/**
8+
* Triggers a bulk export of this ModelExporter's root node and its (in-)direct children.
9+
*
10+
* @return exported node
11+
*/
612
fun export() = root.asExported()
713
}

model-sync-lib/src/jvmMain/kotlin/org/modelix/model/sync/ModelExporter.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ import org.modelix.model.data.ModelData
55
import java.io.File
66

77
actual class ModelExporter actual constructor(private val root: INode) {
8+
9+
/**
10+
* Triggers a bulk export of this ModelExporter's root node and its (in-)direct children into the specified file.
11+
*
12+
* @param outputFile target file of the export
13+
*/
814
fun export(outputFile: File) {
915
val modelData = ModelData(root = root.asExported())
1016
outputFile.parentFile.mkdirs()

model-sync-lib/src/jvmMain/kotlin/org/modelix/model/sync/PlatformSpecific.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ package org.modelix.model.sync
33
import org.modelix.model.data.ModelData
44
import java.io.File
55

6+
/**
7+
* Incrementally updates the root of the receiver [ModelImporter]
8+
* based on the [ModelData] specification contained in the given file.
9+
*
10+
* @param jsonFile json file containing the model specification
11+
*
12+
* @throws IllegalArgumentException if the file is not a json file or the file does not exist.
13+
*/
614
fun ModelImporter.import(jsonFile: File) {
715
require(jsonFile.exists())
816
require(jsonFile.extension == "json")

0 commit comments

Comments
 (0)