Skip to content

Commit

Permalink
fix: 🐛 avoid jvm method conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
Xanonymous-GitHub committed Jul 17, 2024
1 parent 7afa5ba commit 7494945
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
17 changes: 6 additions & 11 deletions core/src/main/kotlin/tw/xcc/gumtree/model/BasicTree.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,8 @@ abstract class BasicTree<T> : Tree<T> where T : BasicTree<T> {
protected abstract val self: T

private val _parent = AtomicReference<T?>()
final override var parent: T?
final override val parent: T?
get() = synchronized(this) { _parent.get() }
private set(value) {
synchronized(this) {
_parent.set(value)
}
}

protected val childrenMap = AtomicReference(sortedMapOf<Int, T>())
final override val children: List<T>
Expand All @@ -25,25 +20,25 @@ abstract class BasicTree<T> : Tree<T> where T : BasicTree<T> {
fun addChild(child: T) {
synchronized(this) {
val newChildrenMap = childrenMap.get()
newChildrenMap[newChildrenMap.size] = child.also { it.parent = self }
newChildrenMap[newChildrenMap.size] = child.also { it.setParentTo(self) }
childrenMap.set(newChildrenMap)
}
}

fun setChildren(children: List<T>) =
fun setChildrenTo(children: List<T>) =
with(childrenMap) {
synchronized(this) {
val newChildrenMap = sortedMapOf<Int, T>()
children.forEachIndexed { i, child ->
newChildrenMap[i] = child.also { it.parent = self }
newChildrenMap[i] = child.also { it.setParentTo(self) }
}
this.set(newChildrenMap)
}
}

fun setParent(parent: T?) {
fun setParentTo(parent: T?) {
synchronized(this) {
this.parent = parent
_parent.set(parent)
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/kotlin/tw/xcc/gumtree/model/GumTree.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class GumTree : BasicTree<GumTree>(), Traversable<GumTree>, Comparable<GumTree>
}

val newChildrenMap = childrenMap.get()
newChildrenMap[pos] = child.also { it.setParent(this) }
newChildrenMap[pos] = child.also { it.setParentTo(this) }
childrenMap.set(newChildrenMap)
}
}
Expand Down

0 comments on commit 7494945

Please sign in to comment.