File tree Expand file tree Collapse file tree 7 files changed +25
-9
lines changed
main/kotlin/com/javiersc/kotlin/stdlib/tree
test/kotlin/com/javiersc/kotlin/stdlib Expand file tree Collapse file tree 7 files changed +25
-9
lines changed Original file line number Diff line number Diff line change 4
4
5
5
### Added
6
6
7
+ - ` root: TreeNode<T> ` to ` TreeNode<T> `
8
+
7
9
### Changed
8
10
9
11
### Deprecated
Original file line number Diff line number Diff line change @@ -234,6 +234,7 @@ public class com/javiersc/kotlin/stdlib/tree/TreeNode : com/javiersc/kotlin/stdl
234
234
public final fun getHeight ()I
235
235
public final fun getNodeCount ()I
236
236
public final fun getParent ()Lcom/javiersc/kotlin/stdlib/tree/TreeNode;
237
+ public final fun getRoot ()Lcom/javiersc/kotlin/stdlib/tree/TreeNode;
237
238
public final fun getValue ()Ljava/lang/Object;
238
239
public final fun isRoot ()Z
239
240
public fun iterator ()Ljava/util/Iterator;
Original file line number Diff line number Diff line change @@ -240,6 +240,7 @@ public class com/javiersc/kotlin/stdlib/tree/TreeNode : com/javiersc/kotlin/stdl
240
240
public final fun getHeight ()I
241
241
public final fun getNodeCount ()I
242
242
public final fun getParent ()Lcom/javiersc/kotlin/stdlib/tree/TreeNode;
243
+ public final fun getRoot ()Lcom/javiersc/kotlin/stdlib/tree/TreeNode;
243
244
public final fun getValue ()Ljava/lang/Object;
244
245
public final fun isRoot ()Z
245
246
public fun iterator ()Ljava/util/Iterator;
Original file line number Diff line number Diff line change @@ -240,6 +240,7 @@ public class com/javiersc/kotlin/stdlib/tree/TreeNode : com/javiersc/kotlin/stdl
240
240
public final fun getHeight ()I
241
241
public final fun getNodeCount ()I
242
242
public final fun getParent ()Lcom/javiersc/kotlin/stdlib/tree/TreeNode;
243
+ public final fun getRoot ()Lcom/javiersc/kotlin/stdlib/tree/TreeNode;
243
244
public final fun getValue ()Ljava/lang/Object;
244
245
public final fun isRoot ()Z
245
246
public fun iterator ()Ljava/util/Iterator;
@@ -264,3 +265,4 @@ public final class com/javiersc/kotlin/stdlib/tree/TreeNodeIterators : java/lang
264
265
public static fun valueOf (Ljava/lang/String;)Lcom/javiersc/kotlin/stdlib/tree/TreeNodeIterators;
265
266
public static fun values ()[Lcom/javiersc/kotlin/stdlib/tree/TreeNodeIterators;
266
267
}
268
+
Original file line number Diff line number Diff line change @@ -20,6 +20,10 @@ public open class TreeNode<T>(
20
20
public val children: List <TreeNode <T >>
21
21
get() = _children
22
22
23
+ /* * The root of the tree. */
24
+ public val root: TreeNode <T >
25
+ get() = parent?.root ? : this
26
+
23
27
/* *
24
28
* Checks whether the current tree node is the root of the tree
25
29
*
Original file line number Diff line number Diff line change @@ -225,13 +225,18 @@ internal class TreeNodeTest {
225
225
assertContentEquals(expectedOrder, tree.toList().map(TreeNode <Int >::value))
226
226
}
227
227
228
- // @Test
229
- // fun given_a_tree_with_delegation_when_accessing_to_value_implicitly_then_casting_works() {
230
- // val bar: Foo = Bar()
231
- // val barFooTree: FooTree<Foo> = FooTree(bar)
232
- // println(barFooTree)
233
- // println(barFooTree.value)
234
- // // assertTrue { barFooTree is Bar }
235
- // // assertTrue { barFooTree.value is Bar }
236
- // }
228
+ @Test
229
+ fun testRoot () {
230
+ val tree =
231
+ tree(1 ) {
232
+ child(2 ) {
233
+ child(4 )
234
+ child(5 )
235
+ }
236
+ child(3 )
237
+ }
238
+ assertEquals(1 , tree.root.value)
239
+ assertEquals(1 , tree.children.first().root.value)
240
+ assertEquals(1 , tree.children.first().children.first().root.value)
241
+ }
237
242
}
Original file line number Diff line number Diff line change @@ -69,3 +69,4 @@ public abstract interface annotation class com/javiersc/kotlin/test/IgnoreWatcho
69
69
70
70
public abstract interface annotation class com/javiersc/kotlin/test/IgnoreWatchosX64 : java/lang/annotation/Annotation {
71
71
}
72
+
You can’t perform that action at this time.
0 commit comments