Extracted prettyString from toString() method to new method prettyString()

This commit is contained in:
Adrian Kuta 2020-01-20 15:42:15 +01:00
parent 3f166aced0
commit eb2d5f07be
3 changed files with 7 additions and 3 deletions

View File

@ -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:*

View File

@ -15,7 +15,7 @@ android {
minSdkVersion 15 minSdkVersion 15
targetSdkVersion 29 targetSdkVersion 29
versionCode 1 versionCode 1
versionName "1.2.0" versionName "1.2.1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'consumer-rules.pro' consumerProguardFiles 'consumer-rules.pro'

View File

@ -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()