mirror of
https://github.com/AdrianKuta/Tree-Data-Structure.git
synced 2025-07-01 23:27:59 +02:00
Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
3c3d418aa2 | |||
f00ab975dc | |||
eb2d5f07be |
@ -22,7 +22,7 @@ val poland = TreeNode("Poland")
|
|||||||
val france = TreeNode("France")
|
val france = TreeNode("France")
|
||||||
europe.addChild(poland)
|
europe.addChild(poland)
|
||||||
europe.addChild(france)
|
europe.addChild(france)
|
||||||
println(root)
|
println(root.prettyString())
|
||||||
```
|
```
|
||||||
|
|
||||||
**Pretty Kotlin**
|
**Pretty Kotlin**
|
||||||
@ -55,7 +55,7 @@ TreeNode<String> poland = new TreeNode<>("Poland");
|
|||||||
TreeNode<String> france = new TreeNode<>("France");
|
TreeNode<String> france = new TreeNode<>("France");
|
||||||
europe.addChild(poland);
|
europe.addChild(poland);
|
||||||
europe.addChild(france);
|
europe.addChild(france);
|
||||||
System.out.println(root);
|
System.out.println(root.prettyString());
|
||||||
```
|
```
|
||||||
|
|
||||||
*Output:*
|
*Output:*
|
||||||
|
@ -15,7 +15,7 @@ android {
|
|||||||
minSdkVersion 15
|
minSdkVersion 15
|
||||||
targetSdkVersion 29
|
targetSdkVersion 29
|
||||||
versionCode 1
|
versionCode 1
|
||||||
versionName "1.2.0"
|
versionName "1.2.2"
|
||||||
|
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
consumerProguardFiles 'consumer-rules.pro'
|
consumerProguardFiles 'consumer-rules.pro'
|
||||||
|
@ -27,7 +27,7 @@ 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>?) {
|
||||||
val newChild = TreeNode(value)
|
val newChild = TreeNode(value)
|
||||||
if(childDeclaration != null)
|
if(childDeclaration != null)
|
||||||
newChild.childDeclaration()
|
newChild.childDeclaration()
|
||||||
@ -91,6 +91,10 @@ open class TreeNode<T>(val value: T) : Iterable<TreeNode<T>>, ChildDeclarationIn
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
|
return value.toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun prettyString(): String {
|
||||||
val stringBuilder = StringBuilder()
|
val stringBuilder = StringBuilder()
|
||||||
print(stringBuilder, "", "")
|
print(stringBuilder, "", "")
|
||||||
return stringBuilder.toString()
|
return stringBuilder.toString()
|
||||||
|
@ -128,18 +128,31 @@ 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())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @Test
|
||||||
|
// fun getVisibleNodes() {
|
||||||
|
// val root = tree("World") {
|
||||||
|
// child("Level 1") {
|
||||||
|
// child("Level 2") {
|
||||||
|
// child("Level 3") {
|
||||||
|
// child("Level 4")
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// print(root.prettyString())
|
||||||
|
// }
|
||||||
|
|
||||||
}
|
}
|
Reference in New Issue
Block a user