From 3f166aced0acd189040904c983b8bb5f07e55961 Mon Sep 17 00:00:00 2001 From: Adrian Kuta Date: Sun, 19 Jan 2020 22:55:18 +0100 Subject: [PATCH] Renamed functions. --- README.md | 38 ++++++++++++++----- treedatastructure/build.gradle | 2 +- .../tree/ChildDeclarationInterface.kt | 14 +++---- .../adriankuta/datastructure/tree/TreeNode.kt | 2 +- .../datastructure/tree/TreeNodeExt.kt | 9 +++-- 5 files changed, 43 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 6fb40d7..1240248 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ Simple implementation to store object in tree structure. Method `toString()` is ## Usage +**Kotlin** ```kotlin val root = TreeNode("World") val northA = TreeNode("North America") @@ -24,18 +25,37 @@ europe.addChild(france) println(root) ``` -Or in more Kotlin like style: +**Pretty Kotlin** ```kotlin -val root = treeNode("World") { - treeNode("North America") { - treeNode("USA") - } - treeNode("Europe") { - treeNode("Poland") - treeNode("Germany") - } +val root = + tree("World") { + child("North America") { + child("USA") } + child("Europe") { + child("Poland") + child("Germany") + } + } +``` + +**Java** +```java +TreeNode root = new TreeNode<>("World"); +TreeNode northA = new TreeNode<>("North America"); +TreeNode europe = new TreeNode<>("Europe"); +root.addChild(northA); +root.addChild(europe); + +TreeNode usa = new TreeNode<>("USA"); +northA.addChild(usa); + +TreeNode poland = new TreeNode<>("Poland"); +TreeNode france = new TreeNode<>("France"); +europe.addChild(poland); +europe.addChild(france); +System.out.println(root); ``` *Output:* diff --git a/treedatastructure/build.gradle b/treedatastructure/build.gradle index 0794f72..02add4f 100644 --- a/treedatastructure/build.gradle +++ b/treedatastructure/build.gradle @@ -15,7 +15,7 @@ android { minSdkVersion 15 targetSdkVersion 29 versionCode 1 - versionName "1.1.0" + versionName "1.2.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" consumerProguardFiles 'consumer-rules.pro' diff --git a/treedatastructure/src/main/java/com/github/adriankuta/datastructure/tree/ChildDeclarationInterface.kt b/treedatastructure/src/main/java/com/github/adriankuta/datastructure/tree/ChildDeclarationInterface.kt index beb9a36..8d31cd9 100644 --- a/treedatastructure/src/main/java/com/github/adriankuta/datastructure/tree/ChildDeclarationInterface.kt +++ b/treedatastructure/src/main/java/com/github/adriankuta/datastructure/tree/ChildDeclarationInterface.kt @@ -5,17 +5,17 @@ interface ChildDeclarationInterface { /** * This method is used to easily create child in node. * ``` - * val root = treeNode("World") { - * treeNode("North America") { - * treeNode("USA") + * val root = tree("World") { + * child("North America") { + * child("USA") * } - * treeNode("Europe") { - * treeNode("Poland") - * treeNode("Germany") + * child("Europe") { + * child("Poland") + * child("Germany") * } * } * ``` */ @JvmSynthetic - fun treeNode(value: T, childDeclaration: ChildDeclaration? = null) + fun child(value: T, childDeclaration: ChildDeclaration? = null) } \ No newline at end of file diff --git a/treedatastructure/src/main/java/com/github/adriankuta/datastructure/tree/TreeNode.kt b/treedatastructure/src/main/java/com/github/adriankuta/datastructure/tree/TreeNode.kt index ccb7783..f8cbe1c 100644 --- a/treedatastructure/src/main/java/com/github/adriankuta/datastructure/tree/TreeNode.kt +++ b/treedatastructure/src/main/java/com/github/adriankuta/datastructure/tree/TreeNode.kt @@ -27,7 +27,7 @@ open class TreeNode(val value: T) : Iterable>, ChildDeclarationIn } @JvmSynthetic - override fun treeNode(value: T, childDeclaration: ChildDeclaration?) { + override fun child(child: T, childDeclaration: ChildDeclaration?) { val newChild = TreeNode(value) if(childDeclaration != null) newChild.childDeclaration() diff --git a/treedatastructure/src/main/java/com/github/adriankuta/datastructure/tree/TreeNodeExt.kt b/treedatastructure/src/main/java/com/github/adriankuta/datastructure/tree/TreeNodeExt.kt index 7f32ab4..866df4e 100644 --- a/treedatastructure/src/main/java/com/github/adriankuta/datastructure/tree/TreeNodeExt.kt +++ b/treedatastructure/src/main/java/com/github/adriankuta/datastructure/tree/TreeNodeExt.kt @@ -5,13 +5,14 @@ typealias ChildDeclaration = ChildDeclarationInterface.() -> Unit /** * This method can be used to initialize new tree. * ``` - * val root = treeNode("World") { ... } + * val root = tree("World") { ... } * ``` - * @see [ChildDeclarationInterface.treeNode] + * @param root Root element of new tree. + * @see [ChildDeclarationInterface.child] */ @JvmSynthetic -inline fun treeNode(value: T, childDeclaration: ChildDeclaration): TreeNode { - val treeNode = TreeNode(value) +inline fun tree(root: T, childDeclaration: ChildDeclaration): TreeNode { + val treeNode = TreeNode(root) treeNode.childDeclaration() return treeNode } \ No newline at end of file