child function is now returning TreeNode

This commit is contained in:
Adrian Kuta 2020-01-21 15:38:44 +01:00
parent 3c3d418aa2
commit c320411a40
3 changed files with 4 additions and 18 deletions

View File

@ -15,7 +15,8 @@ interface ChildDeclarationInterface<T> {
* } * }
* } * }
* ``` * ```
* @return New created TreeNode.
*/ */
@JvmSynthetic @JvmSynthetic
fun child(value: T, childDeclaration: ChildDeclaration<T>? = null) fun child(value: T, childDeclaration: ChildDeclaration<T>? = null): TreeNode<T>
} }

View File

@ -27,11 +27,12 @@ open class TreeNode<T>(val value: T) : Iterable<TreeNode<T>>, ChildDeclarationIn
} }
@JvmSynthetic @JvmSynthetic
override fun child(value: T, childDeclaration: ChildDeclaration<T>?) { override fun child(value: T, childDeclaration: ChildDeclaration<T>?): TreeNode<T> {
val newChild = TreeNode(value) val newChild = TreeNode(value)
if(childDeclaration != null) if(childDeclaration != null)
newChild.childDeclaration() newChild.childDeclaration()
_children.add(newChild) _children.add(newChild)
return newChild
} }
/** /**

View File

@ -139,20 +139,4 @@ class TreeNodeTest {
} }
assertEquals(root.prettyString(), rootExt.prettyString()) assertEquals(root.prettyString(), rootExt.prettyString())
} }
// @Test
// fun getVisibleNodes() {
// val root = tree("World") {
// child("Level 1") {
// child("Level 2") {
// child("Level 3") {
// child("Level 4")
// }
// }
// }
// }
//
// print(root.prettyString())
// }
} }