Skip to content

Commit 64e4645

Browse files
authored
Merge pull request #94 from modelix/docs/model-api
MODELIX-419 Add documentation for model api reference
2 parents b82344e + afd15cd commit 64e4645

23 files changed

+1032
-3
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
*/
1414
package org.modelix.model.api
1515

16+
/**
17+
* Returns this concept and all of its super-concepts.
18+
*
19+
* @return list of this concept and all its super-concepts
20+
*/
1621
fun IConcept.getAllConcepts(): List<IConcept> {
1722
val acc = LinkedHashSet<IConcept>()
1823
collectConcepts(this, acc)

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

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,35 +15,140 @@
1515

1616
package org.modelix.model.api
1717

18+
/**
19+
* Representation of a branch.
20+
*/
1821
interface IBranch {
22+
/**
23+
* Returns the id of this branch.
24+
*
25+
* @return branch id
26+
*/
1927
fun getId(): String
28+
29+
/**
30+
* Performs a read operation on this branch.
31+
*
32+
* @param runnable read operation to be performed
33+
*/
2034
fun runRead(runnable: () -> Unit)
35+
36+
/**
37+
* Performs a function in a read transaction on this branch.
38+
*
39+
* @param f function to be performed
40+
*/
2141
fun runReadT(f: (IReadTransaction) -> Unit) {
2242
runRead { f(readTransaction) }
2343
}
44+
45+
/**
46+
* Performs a computable read operation, which returns a value, on this branch.
47+
*
48+
* @param computable operation to be performed
49+
*/
2450
fun <T> computeRead(computable: () -> T): T
51+
52+
/**
53+
* Performs a computable read operation, which returns a value, in a read transaction on this branch.
54+
*/
2555
fun <T> computeReadT(computable: (IReadTransaction) -> T): T {
2656
return computeRead { computable(readTransaction) }
2757
}
58+
59+
/**
60+
* Performs a write operation on this branch.
61+
*
62+
* @param runnable operation to be performed
63+
*/
2864
fun runWrite(runnable: () -> Unit)
65+
66+
/**
67+
* Performs a function in a write transaction on this branch.
68+
*
69+
* @param f function to be performed
70+
*/
2971
fun runWriteT(f: (IWriteTransaction) -> Unit) {
3072
runWrite { f(writeTransaction) }
3173
}
74+
75+
/**
76+
* Performs a computable write operation, which returns a value, on this branch.
77+
*
78+
* @param computable operation to be performed
79+
*/
3280
fun <T> computeWrite(computable: () -> T): T
81+
82+
/**
83+
* Performs a computable write operation, which returns a value, in a write transaction on this branch.
84+
*/
3385
fun <T> computeWriteT(computable: (IWriteTransaction) -> T): T {
3486
return computeWrite { computable(writeTransaction) }
3587
}
88+
89+
/**
90+
* Checks if read operations can be performed on this branch.
91+
*
92+
* @return true if read operations can be performed, false otherwise
93+
*/
3694
fun canRead(): Boolean
95+
96+
/**
97+
* Checks if write operations can be performed on this branch.
98+
*
99+
* @return true if write operations can be performed, false otherwise
100+
*/
37101
fun canWrite(): Boolean
102+
103+
/**
104+
* Transaction for this branch.
105+
*/
38106
val transaction: ITransaction
107+
108+
/**
109+
* Read transaction for this branch.
110+
*/
39111
val readTransaction: IReadTransaction
112+
113+
/**
114+
* Write transaction for this branch.
115+
*/
40116
val writeTransaction: IWriteTransaction
117+
118+
/**
119+
* Adds the given branch listener to this branch.
120+
*
121+
* The branch listener will listen to changes on this branch.
122+
*
123+
* @param l branch listener to be added
124+
*/
41125
fun addListener(l: IBranchListener)
126+
127+
/**
128+
* Removes the given branch listener from this branch.
129+
*
130+
* @param l branch listener to be removed
131+
*/
42132
fun removeListener(l: IBranchListener)
43133
}
44134

135+
/**
136+
* Wrapper for [IBranch]
137+
*/
45138
interface IBranchWrapper : IBranch {
139+
/**
140+
* Unwraps the branch.
141+
*
142+
* @return unwrapped branch
143+
*/
46144
fun unwrapBranch(): IBranch
47145
}
48146

147+
/**
148+
* Recursively unwraps a branch.
149+
*
150+
* If the receiver is an [IBranchWrapper] it will be unwrapped else the branch will be returned.
151+
*
152+
* @return deep unwrapped branch
153+
*/
49154
fun IBranch.deepUnwrap(): IBranch = if (this is IBranchWrapper) unwrapBranch().deepUnwrap() else this

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@
1515

1616
package org.modelix.model.api
1717

18+
/**
19+
* Listener, that listens for changes on a branch.
20+
*/
1821
interface IBranchListener {
22+
/**
23+
* Informs the branch listener about tree changes.
24+
*
25+
* @param oldTree the original tree state
26+
* @param newTree the new tree state
27+
*/
1928
fun treeChanged(oldTree: ITree?, newTree: ITree)
2029
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@
1515

1616
package org.modelix.model.api
1717

18+
/**
19+
* Representation of a parent-child relationship between [IConcept]s.
20+
*/
1821
interface IChildLink : ILink {
22+
/**
23+
* Specifies if the parent-child relation ship is 1:n.
24+
*/
1925
val isMultiple: Boolean
2026

2127
@Deprecated("use .targetConcept")

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

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,162 @@
1515

1616
package org.modelix.model.api
1717

18+
/**
19+
* Representation of a language concept.
20+
*/
1821
interface IConcept {
22+
23+
/**
24+
* Returns a reference to this concept.
25+
*
26+
* @return concept reference
27+
*/
1928
fun getReference(): IConceptReference
29+
30+
/**
31+
* The language this concept is part of.
32+
*/
2033
val language: ILanguage?
2134

35+
/**
36+
* Returns unique concept id of this concept.
37+
*
38+
* @return unique concept id
39+
*/
2240
fun getUID(): String
41+
42+
/**
43+
* Returns the name of this concept.
44+
*
45+
* @return short concept name
46+
*/
2347
fun getShortName(): String
48+
49+
/**
50+
* Returns the name of this concept prefixed by the language name.
51+
*
52+
* @return long concept name
53+
*/
2454
fun getLongName(): String
55+
56+
/**
57+
* Checks if this concept is abstract.
58+
*
59+
* @return true if the concept is abstract, false otherwise
60+
*/
2561
fun isAbstract(): Boolean
2662

63+
/**
64+
* Checks if this concept is a sub-concept of the given concept.
65+
*
66+
* @param superConcept the potential super-concept
67+
* @return true if the given concept is a super-concept of this concept, false otherwise
68+
*/
2769
fun isSubConceptOf(superConcept: IConcept?): Boolean
70+
71+
/**
72+
* Returns the direct super concepts of this concept.
73+
*
74+
* @return list of direct super concepts
75+
*/
2876
fun getDirectSuperConcepts(): List<IConcept>
77+
78+
/**
79+
* Checks if the given concept is equal to this concept.
80+
*
81+
* @return true if this concept is equal to the given concept, false otherwise
82+
*/
2983
fun isExactly(concept: IConcept?): Boolean
3084

85+
/**
86+
* Returns the properties, which are directly defined in this concept.
87+
*
88+
* @return list of own properties
89+
*
90+
* @see getAllProperties
91+
*/
3192
fun getOwnProperties(): List<IProperty>
93+
94+
/**
95+
* Returns the child links, which are directly defined in this concept.
96+
*
97+
* @return list of own child links
98+
*
99+
* @see getAllChildLinks
100+
*/
32101
fun getOwnChildLinks(): List<IChildLink>
102+
103+
/**
104+
* Returns the reference links, which are directly defined in this concept.
105+
*
106+
* @return list of reference links
107+
*
108+
* @see getAllChildLinks
109+
*/
33110
fun getOwnReferenceLinks(): List<IReferenceLink>
34111

112+
/**
113+
* Returns all properties of this concept.
114+
*
115+
* This includes properties, that are directly defined in the concept itself,
116+
* and properties, which are defined in the super-concepts of this concept.
117+
*
118+
* @return list of all properties
119+
*
120+
* @see getOwnProperties
121+
*/
35122
fun getAllProperties(): List<IProperty>
123+
124+
/**
125+
* Returns all child links of this concept.
126+
*
127+
* This includes child links, that are directly defined in the concept itself,
128+
* and child links, which are defined in the super-concepts of this concept.
129+
*
130+
* @return list of all child links
131+
*
132+
* @see getOwnChildLinks
133+
*/
36134
fun getAllChildLinks(): List<IChildLink>
135+
136+
/**
137+
* Returns all reference links of this concepts.
138+
*
139+
* This includes reference links, that are directly defined in the concept itself,
140+
* and reference links, which are defined in the super-concepts of this concept.
141+
*
142+
* @return list of all reference links
143+
*
144+
* @see getOwnReferenceLinks
145+
*/
37146
fun getAllReferenceLinks(): List<IReferenceLink>
38147

148+
/**
149+
* Returns the property with the given name.
150+
*
151+
* @param name name of the property
152+
* @return property
153+
*/
39154
fun getProperty(name: String): IProperty
155+
156+
/**
157+
* Returns the child link with the given name.
158+
*
159+
* @param name name of the child link
160+
* @return child link
161+
*/
40162
fun getChildLink(name: String): IChildLink
163+
164+
/**
165+
* Returns the reference link with the given name.
166+
*
167+
* @param name name of the reference link
168+
* @return reference link
169+
*/
41170
fun getReferenceLink(name: String): IReferenceLink
42171
}
43172

173+
/**
174+
* @see IConcept.isSubConceptOf
175+
*/
44176
fun IConcept?.isSubConceptOf(superConcept: IConcept?) = this?.isSubConceptOf(superConcept) == true

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ package org.modelix.model.api
1515

1616
import org.modelix.model.area.IArea
1717

18+
/**
19+
* Reference to an [IConcept].
20+
*/
1821
interface IConceptReference {
1922
companion object {
2023
private var deserializers: Map<Any, ((String) -> IConceptReference?)> = LinkedHashMap()
@@ -41,6 +44,11 @@ interface IConceptReference {
4144
}
4245
}
4346

47+
/**
48+
* Returns the unique id of this concept reference.
49+
*
50+
* @return uid of this concept reference
51+
*/
4452
fun getUID(): String
4553

4654
@Deprecated("use ILanguageRepository.resolveConcept")
@@ -50,5 +58,25 @@ interface IConceptReference {
5058
fun serialize(): String
5159
}
5260

61+
/**
62+
* Resolves the receiver concept reference within all registered language repositories.
63+
*
64+
* @receiver concept reference to be resolved
65+
* @return resolved concept
66+
* @throws RuntimeException if the concept could not be found
67+
* or multiple concepts were found for this concept reference
68+
*
69+
* @see ILanguageRepository.resolveConcept
70+
*/
5371
fun IConceptReference.resolve(): IConcept = ILanguageRepository.resolveConcept(this)
72+
73+
/**
74+
* Tries to resolve the receiver concept reference within all registered language repositories.
75+
*
76+
* @receiver concept reference to be resolved
77+
* @return resolved concept or null, if the concept could not be found
78+
* @throws RuntimeException if multiple concepts were found for this concept reference
79+
*
80+
* @see ILanguageRepository.tryResolveConcept
81+
*/
5482
fun IConceptReference.tryResolve(): IConcept? = ILanguageRepository.tryResolveConcept(this)

0 commit comments

Comments
 (0)