mirror of
https://github.com/AdrianKuta/Tree-Data-Structure.git
synced 2025-07-01 15:27:58 +02:00
Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
c2ebd5dfe4 | |||
c320411a40 | |||
3c3d418aa2 | |||
f00ab975dc |
@ -15,7 +15,7 @@ android {
|
|||||||
minSdkVersion 15
|
minSdkVersion 15
|
||||||
targetSdkVersion 29
|
targetSdkVersion 29
|
||||||
versionCode 1
|
versionCode 1
|
||||||
versionName "1.2.1"
|
versionName "1.2.3"
|
||||||
|
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
consumerProguardFiles 'consumer-rules.pro'
|
consumerProguardFiles 'consumer-rules.pro'
|
||||||
|
@ -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>
|
||||||
}
|
}
|
@ -27,11 +27,12 @@ open class TreeNode<T>(val value: T) : Iterable<TreeNode<T>>, ChildDeclarationIn
|
|||||||
}
|
}
|
||||||
|
|
||||||
@JvmSynthetic
|
@JvmSynthetic
|
||||||
override fun child(child: 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
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -128,18 +128,15 @@ class TreeNodeTest {
|
|||||||
europe.addChild(poland)
|
europe.addChild(poland)
|
||||||
europe.addChild(france)
|
europe.addChild(france)
|
||||||
|
|
||||||
val rootExt = treeNode("World") {
|
val rootExt = tree("World") {
|
||||||
treeNode("North America") {
|
child("North America") {
|
||||||
treeNode("USA")
|
child("USA")
|
||||||
}
|
}
|
||||||
treeNode("Europe") {
|
child("Europe") {
|
||||||
treeNode("Poland")
|
child("Poland")
|
||||||
treeNode("France")
|
child("France")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
println(root)
|
assertEquals(root.prettyString(), rootExt.prettyString())
|
||||||
assertEquals(root.toString(), rootExt.toString())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
Reference in New Issue
Block a user