Skip to content

Commit 74a063f

Browse files
authored
Merge pull request #751 from modelix/chore/reduce-warnings
chore: reduce warnings
2 parents 45ddc26 + d819c5b commit 74a063f

File tree

27 files changed

+196
-214
lines changed

27 files changed

+196
-214
lines changed

model-client/src/commonMain/kotlin/org/modelix/model/ModelFacade.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ object ModelFacade {
5050
}
5151

5252
fun loadCurrentModel(client: IModelClient, branch: BranchReference): ITree? {
53-
return loadCurrentVersion(client, branch)?.tree
53+
return loadCurrentVersion(client, branch)?.getTree()
5454
}
5555

5656
fun toLocalBranch(tree: ITree): IBranch = TreePointer(tree, IdGenerator.getInstance(1))
@@ -74,11 +74,11 @@ object ModelFacade {
7474
fun createRepositoryId(id: String): RepositoryId = RepositoryId(id)
7575

7676
fun mergeUpdate(client: IModelClient, branch: BranchReference, baseVersionHash: String? = null, userName: String?, body: (IWriteTransaction) -> Unit): CLVersion {
77-
val baseVersionHash: String = baseVersionHash
77+
val actualBaseVersionHash: String = baseVersionHash
7878
?: client.get(branch.getKey())
7979
?: throw RuntimeException("$branch doesn't exist")
80-
val baseVersionData: CPVersion = client.storeCache.get(baseVersionHash, { CPVersion.deserialize(it) })
81-
?: throw RuntimeException("version not found: $baseVersionHash")
80+
val baseVersionData: CPVersion = client.storeCache.get(actualBaseVersionHash) { CPVersion.deserialize(it) }
81+
?: throw RuntimeException("version not found: $actualBaseVersionHash")
8282
val baseVersion = CLVersion(baseVersionData, client.storeCache)
8383
return applyUpdate(client, baseVersion, branch, userName, body)
8484
}
@@ -90,10 +90,10 @@ object ModelFacade {
9090
userId: String?,
9191
body: (IWriteTransaction) -> Unit,
9292
): CLVersion {
93-
val otBranch = OTBranch(PBranch(baseVersion.tree, client.idGenerator), client.idGenerator, client.storeCache)
93+
val otBranch = OTBranch(PBranch(baseVersion.getTree(), client.idGenerator), client.idGenerator, client.storeCache)
9494
otBranch.computeWriteT { t -> body(t) }
9595

96-
val operationsAndTree = otBranch.operationsAndTree
96+
val operationsAndTree = otBranch.getPendingChanges()
9797
val newVersion = CLVersion.createRegularVersion(
9898
client.idGenerator.generate(),
9999
Clock.System.now().epochSeconds.toString(),
@@ -106,7 +106,7 @@ object ModelFacade {
106106
?: throw RuntimeException("$branch doesn't exist")
107107
val mergedVersion = VersionMerger(client.storeCache, client.idGenerator)
108108
.mergeChange(currentVersion, newVersion)
109-
client.asyncStore.put(branch.getKey(), mergedVersion.hash)
109+
client.asyncStore.put(branch.getKey(), mergedVersion.getContentHash())
110110
// TODO handle concurrent write to the branchKey, otherwise versions might get lost. See ReplicatedRepository.
111111
return mergedVersion
112112
}

model-client/src/commonMain/kotlin/org/modelix/model/client2/ModelClientV2.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ class ModelClientV2(
280280
takeFrom(baseUrl)
281281
appendPathSegmentsEncodingSlash("repositories", branch.repositoryId.id, "branches", branch.branchName)
282282
if (lastKnownVersion != null) {
283-
parameters["lastKnown"] = lastKnownVersion.hash
283+
parameters["lastKnown"] = lastKnownVersion.getContentHash()
284284
}
285285
}
286286
useVersionStreamFormat()
@@ -347,7 +347,7 @@ class ModelClientV2(
347347
takeFrom(baseUrl)
348348
appendPathSegmentsEncodingSlash("repositories", branch.repositoryId.id, "branches", branch.branchName, "poll")
349349
if (lastKnownVersion != null) {
350-
parameters["lastKnown"] = lastKnownVersion.hash
350+
parameters["lastKnown"] = lastKnownVersion.getContentHash()
351351
}
352352
}
353353
useVersionStreamFormat()
@@ -366,10 +366,10 @@ class ModelClientV2(
366366
return ModelQLClient.builder().httpClient(httpClient).url(url.buildString()).build().query(body)
367367
}
368368

369-
override suspend fun <R> query(repository: RepositoryId, versionHash: String, body: (IMonoStep<INode>) -> IMonoStep<R>): R {
369+
override suspend fun <R> query(repositoryId: RepositoryId, versionHash: String, body: (IMonoStep<INode>) -> IMonoStep<R>): R {
370370
val url = URLBuilder().apply {
371371
takeFrom(baseUrl)
372-
appendPathSegmentsEncodingSlash("repositories", repository.id, "versions", versionHash, "query")
372+
appendPathSegmentsEncodingSlash("repositories", repositoryId.id, "versions", versionHash, "query")
373373
}
374374
return ModelQLClient.builder().httpClient(httpClient).url(url.buildString()).build().query(body)
375375
}

model-client/src/commonMain/kotlin/org/modelix/model/metameta/MetaModelSynchronizer.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class MetaModelSynchronizer(val branch: IBranch) {
112112
id = getIndex().getPropertyId(property)
113113
if (id != null) return id
114114
val pendingReferences: MutableList<(MetaModelIndex) -> Unit> = ArrayList()
115-
id = storeProperty(getConceptId(property.getConcept()), property, pendingReferences)
115+
id = storeProperty(getConceptId(property.getConcept()), property)
116116
processPendingReferences(getIndex(), pendingReferences)
117117
return id
118118
}
@@ -194,7 +194,7 @@ class MetaModelSynchronizer(val branch: IBranch) {
194194
}
195195

196196
for (property in concept.getOwnProperties()) {
197-
storeProperty(id, property, pendingReferences)
197+
storeProperty(id, property)
198198
}
199199

200200
for (childLink in concept.getOwnChildLinks()) {
@@ -208,7 +208,7 @@ class MetaModelSynchronizer(val branch: IBranch) {
208208
return id
209209
}
210210

211-
private fun storeProperty(conceptId: Long, property: IProperty, pendingReferences: MutableList<(MetaModelIndex) -> Unit>): Long {
211+
private fun storeProperty(conceptId: Long, property: IProperty): Long {
212212
val t = branch.transaction
213213
var id = t.getChildren(conceptId, MetaMetaLanguage.childLink_Concept_properties.name)
214214
.find { t.getProperty(it, MetaMetaLanguage.property_IHasUID_uid.name) == property.getUID() }

model-client/src/commonMain/kotlin/org/modelix/model/metameta/PersistedConcept.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,12 @@ data class PersistedConcept(val id: Long, val uid: String?) : IConcept, IConcept
6969
throw UnsupportedOperationException()
7070
}
7171

72+
@Deprecated("use ILanguageRepository.resolveConcept")
7273
override fun resolve(area: IArea?): IConcept? {
7374
throw UnsupportedOperationException()
7475
}
7576

77+
@Deprecated("use getUID()")
7678
override fun serialize(): String {
7779
TODO("Not yet implemented")
7880
}

model-client/src/commonTest/kotlin/org/modelix/model/api/CompositeAreaTest.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@file:Suppress("DEPRECATION")
2+
13
package org.modelix.model.api
24

35
import org.modelix.model.area.AbstractArea
@@ -8,11 +10,13 @@ import kotlin.test.Test
810
import kotlin.test.assertEquals
911

1012
class MyNodeReference : INodeReference {
13+
@Deprecated("use .resolveIn(INodeResolutionScope)", replaceWith = ReplaceWith("resolveIn(area!!)"))
1114
override fun resolveNode(area: IArea?): INode? {
1215
TODO("Not yet implemented")
1316
}
1417
}
1518

19+
@Suppress("OVERRIDE_DEPRECATION")
1620
class MyNode(val name: String) : INode {
1721
override fun getArea(): IArea {
1822
TODO("Not yet implemented")
@@ -40,7 +44,7 @@ class MyNode(val name: String) : INode {
4044
override val allChildren: Iterable<INode>
4145
get() = TODO("Not yet implemented")
4246

43-
override fun moveChild(role: String?, index: Int, node: INode) {
47+
override fun moveChild(role: String?, index: Int, child: INode) {
4448
TODO("Not yet implemented")
4549
}
4650

@@ -94,6 +98,7 @@ class MyArea(val knownResolutions: Map<INodeReference, INode>) : AbstractArea(),
9498
return this
9599
}
96100

101+
@Deprecated("use ILanguageRepository.resolveConcept")
97102
override fun resolveConcept(ref: IConceptReference): IConcept? {
98103
return null
99104
}

model-client/src/commonTest/kotlin/org/modelix/model/api/NodeUtilTest.kt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import org.modelix.model.area.IArea
44
import kotlin.test.Test
55
import kotlin.test.assertEquals
66

7+
@Suppress("DEPRECATION")
78
class SimpleTestConcept : IConcept {
89
override val language: ILanguage?
910
get() = TODO("Not yet implemented")
@@ -77,6 +78,7 @@ class SimpleTestConcept : IConcept {
7778
}
7879
}
7980

81+
@Suppress("OVERRIDE_DEPRECATION")
8082
class SimpleTestNode(override val concept: IConcept? = null) : INode {
8183
override fun getArea(): IArea {
8284
TODO("Not yet implemented")
@@ -103,15 +105,15 @@ class SimpleTestNode(override val concept: IConcept? = null) : INode {
103105
override val allChildren: Iterable<INode>
104106
get() = childrenByRole.values.flatten()
105107

106-
override fun moveChild(role: String?, index: Int, node: INode) {
108+
override fun moveChild(role: String?, index: Int, child: INode) {
107109
val l = childrenByRole.getOrPut(role) { mutableListOf() }
108-
l.add(index, node)
109-
if (node is SimpleTestNode) {
110-
node.parent = this
111-
node.roleInParent = role
110+
l.add(index, child)
111+
if (child is SimpleTestNode) {
112+
child.parent = this
113+
child.roleInParent = role
112114
}
113-
require(node.parent == this)
114-
require(node.roleInParent == role)
115+
require(child.parent == this)
116+
require(child.roleInParent == role)
115117
}
116118

117119
override fun addNewChild(role: String?, index: Int, concept: IConcept?): INode {

model-client/src/jvmMain/kotlin/org/modelix/model/KeyValueStoreCache.kt

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package org.modelix.model
1818
import org.apache.commons.collections4.map.LRUMap
1919
import org.modelix.model.persistent.HashUtil
2020
import org.modelix.model.util.StreamUtils.toStream
21-
import java.util.Arrays
2221
import java.util.Collections
2322
import java.util.concurrent.CompletableFuture
2423
import java.util.stream.Collectors
@@ -27,21 +26,21 @@ class KeyValueStoreCache(private val store: IKeyValueStore) : IKeyValueStoreWrap
2726
private val cache = Collections.synchronizedMap(LRUMap<String, String?>(300000))
2827
private val pendingPrefetches: MutableSet<String> = HashSet()
2928
private val activeRequests: MutableList<GetRequest> = ArrayList()
30-
override fun prefetch(rootKey: String) {
29+
override fun prefetch(key: String) {
3130
val processedKeys: MutableSet<String?> = HashSet()
32-
processedKeys.add(rootKey)
33-
var newKeys: MutableList<String> = Arrays.asList(rootKey).toMutableList()
34-
while (!newKeys.isEmpty() && processedKeys.size + newKeys.size <= 100000) {
31+
processedKeys.add(key)
32+
var newKeys: MutableList<String> = mutableListOf(key)
33+
while (newKeys.isNotEmpty() && processedKeys.size + newKeys.size <= 100000) {
3534
synchronized(pendingPrefetches) { newKeys.removeAll(pendingPrefetches) }
3635
val currentKeys = newKeys
3736
newKeys = ArrayList()
3837
var loadedEntries: Map<String, String?>?
3938
synchronized(pendingPrefetches) { pendingPrefetches.addAll(currentKeys) }
4039
try {
4140
loadedEntries = getAll(currentKeys)
42-
for ((key, value) in loadedEntries) {
43-
processedKeys.add(key)
44-
for (childKey in HashUtil.extractSha256(value)) {
41+
for ((loadedKey, loadedValue) in loadedEntries) {
42+
processedKeys.add(loadedKey)
43+
for (childKey in HashUtil.extractSha256(loadedValue)) {
4544
if (processedKeys.contains(childKey)) {
4645
continue
4746
}
@@ -62,8 +61,8 @@ class KeyValueStoreCache(private val store: IKeyValueStore) : IKeyValueStoreWrap
6261
return getAll(setOf(key))[key]
6362
}
6463

65-
override fun getAll(keys_: Iterable<String>): Map<String, String?> {
66-
val remainingKeys = toStream(keys_).collect(Collectors.toList())
64+
override fun getAll(keys: Iterable<String>): Map<String, String?> {
65+
val remainingKeys = toStream(keys).collect(Collectors.toList())
6766
val result: MutableMap<String, String?> = LinkedHashMap(16, 0.75.toFloat(), false)
6867
synchronized(cache) {
6968
val itr = remainingKeys.iterator()

model-client/src/jvmMain/kotlin/org/modelix/model/client/AsyncStore.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ class AsyncStore(private val store: IKeyValueStore) : IKeyValueStoreWrapper {
4949
putAll(mapOf(key to value))
5050
}
5151

52-
override fun getAll(keys_: Iterable<String>): Map<String, String?> {
53-
val keys = keys_.toMutableList()
52+
override fun getAll(keys: Iterable<String>): Map<String, String?> {
53+
val mutableKeys = keys.toMutableList()
5454
val result: MutableMap<String, String?> = LinkedHashMap()
5555
synchronized(pendingWrites) {
56-
val itr: MutableIterator<String> = keys.iterator()
56+
val itr: MutableIterator<String> = mutableKeys.iterator()
5757
while (itr.hasNext()) {
5858
val key: String = itr.next()
5959
// always put even if null to have the same order in the linked hash map as in the input
@@ -63,8 +63,8 @@ class AsyncStore(private val store: IKeyValueStore) : IKeyValueStoreWrapper {
6363
}
6464
}
6565
}
66-
if (!keys.isEmpty()) {
67-
result.putAll(store.getAll(keys))
66+
if (mutableKeys.isNotEmpty()) {
67+
result.putAll(store.getAll(mutableKeys))
6868
}
6969
return result
7070
}

model-client/src/jvmMain/kotlin/org/modelix/model/client/ReplicatedRepository.kt

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ actual open class ReplicatedRepository actual constructor(
117117
var remoteBase: CLVersion?
118118
var newLocalVersion: CLVersion
119119
synchronized(mergeLock) {
120-
opsAndTree = localOTBranch.operationsAndTree
120+
opsAndTree = localOTBranch.getPendingChanges()
121121
localBase = localVersion
122122
remoteBase = remoteVersion
123123
val ops: Array<IOperation> = opsAndTree.first.map { it.getOriginalOp() }.toTypedArray()
@@ -179,18 +179,18 @@ actual open class ReplicatedRepository actual constructor(
179179
synchronized(mergeLock) {
180180
if (remoteVersion!!.hash != newVersion.hash) {
181181
remoteVersion = newVersion
182-
client.asyncStore!!.put(branchReference.getKey(), newVersion.hash)
182+
client.asyncStore.put(branchReference.getKey(), newVersion.getContentHash())
183183
}
184184
}
185185
}
186186

187187
protected fun writeLocalVersion(newVersion: CLVersion?) {
188188
synchronized(mergeLock) {
189-
if (newVersion!!.hash != this.localVersion!!.hash) {
189+
if (newVersion!!.getContentHash() != this.localVersion!!.getContentHash()) {
190190
this.localVersion = newVersion
191191
divergenceTime = 0
192192
localBranch.runWrite {
193-
val newTree = newVersion.tree
193+
val newTree = newVersion.getTree()
194194
val currentTree = localBranch.transaction.tree as CLTree?
195195
if (getHash(newTree) != getHash(currentTree)) {
196196
localBranch.writeTransaction.tree = newTree
@@ -236,7 +236,7 @@ actual open class ReplicatedRepository actual constructor(
236236
companion object {
237237
private val LOG = mu.KotlinLogging.logger {}
238238
private fun getHash(v: CLVersion?): String? {
239-
return v?.hash
239+
return v?.getContentHash()
240240
}
241241

242242
private fun getHash(v: CLTree?): String? {
@@ -246,13 +246,13 @@ actual open class ReplicatedRepository actual constructor(
246246

247247
init {
248248
val versionHash = client[branchReference.getKey()]
249-
val store = client.storeCache!!
249+
val store = client.storeCache
250250
var initialVersion = if (versionHash.isNullOrEmpty()) null else loadFromHash(versionHash, store)
251251
val initialTree = MutableObject<CLTree>()
252252
if (initialVersion == null) {
253253
initialTree.setValue(CLTree.builder(store).repositoryId(branchReference.repositoryId).build())
254254
initialVersion = createVersion(initialTree.value, arrayOf(), null)
255-
client.asyncStore!!.put(branchReference.getKey(), initialVersion.hash)
255+
client.asyncStore.put(branchReference.getKey(), initialVersion.getContentHash())
256256
} else {
257257
initialTree.setValue(CLTree(initialVersion.treeHash?.getValue(store), store))
258258
}
@@ -265,20 +265,20 @@ actual open class ReplicatedRepository actual constructor(
265265
localOTBranch = OTBranch(localBranch, client.idGenerator, store)
266266
merger = VersionMerger(store, client.idGenerator)
267267
versionChangeDetector = object : VersionChangeDetector(client, branchReference.getKey(), coroutineScope) {
268-
override fun processVersionChange(oldVersionHash: String?, newVersionHash: String?) {
268+
override fun processVersionChange(oldVersion: String?, newVersion: String?) {
269269
if (disposed) {
270270
return
271271
}
272-
if (newVersionHash == null || newVersionHash.length == 0) {
272+
if (newVersion.isNullOrEmpty()) {
273273
return
274274
}
275-
if (newVersionHash == getHash(remoteVersion)) {
275+
if (newVersion == getHash(remoteVersion)) {
276276
return
277277
}
278-
val newRemoteVersion = loadFromHash(newVersionHash, store)
278+
val newRemoteVersion = loadFromHash(newVersion, store)
279279
val localBase = MutableObject<CLVersion?>()
280280
synchronized(mergeLock) {
281-
localBase.setValue(localVersion)
281+
localBase.value = localVersion
282282
remoteVersion = newRemoteVersion
283283
}
284284
val doMerge = object : Supplier<Boolean> {
@@ -300,7 +300,7 @@ actual open class ReplicatedRepository actual constructor(
300300
LOG.error(ex) { "" }
301301
mergedVersion = newRemoteVersion
302302
}
303-
val mergedTree = mergedVersion.tree
303+
val mergedTree = mergedVersion.getTree()
304304
synchronized(mergeLock) {
305305
remoteVersion = mergedVersion
306306
if (localVersion == localBase.value) {
@@ -346,8 +346,8 @@ actual open class ReplicatedRepository actual constructor(
346346
convergenceWatchdog = fixDelay(
347347
1000,
348348
Runnable {
349-
val localHash = if (localVersion == null) null else localVersion!!.hash
350-
val remoteHash = if (remoteVersion == null) null else remoteVersion!!.hash
349+
val localHash = if (localVersion == null) null else localVersion!!.getContentHash()
350+
val remoteHash = if (remoteVersion == null) null else remoteVersion!!.getContentHash()
351351
if (localHash == remoteHash) {
352352
divergenceTime = 0
353353
} else {

model-client/src/jvmMain/kotlin/org/modelix/model/client/RestWebModelClient.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -530,8 +530,8 @@ class RestWebModelClient @JvmOverloads constructor(
530530
return sorted
531531
}
532532

533-
override fun putAll(entries_: Map<String, String?>) {
534-
runBlocking { putAllA(entries_) }
533+
override fun putAll(entries: Map<String, String?>) {
534+
runBlocking { putAllA(entries) }
535535
}
536536

537537
suspend fun putAllA(entries_: Map<String, String?>) {

0 commit comments

Comments
 (0)