public class Tree<A> extends Object
| Constructor and Description |
|---|
Tree(@Nullable Tree<A> parent,
A value) |
| Modifier and Type | Method and Description |
|---|---|
Tree<A> |
addChild(A value) |
Tree<A> |
addChild(Tree<A> child) |
List<Tree<A>> |
getChildren() |
@Nullable Tree<A> |
getParent() |
A |
getValue() |
<B> Tree<B> |
map(Function<A,B> f)
Map this tree into a new tree using the transformation
f. |
void |
traverse(Consumer<A> c)
Traverse this tree consuming the
value at each node. |
void |
traverseNodes(Consumer<Tree<A>> c)
Traverse this tree consuming each
Tree node. |
void |
traverseWithDepth(BiConsumer<A,Integer> c)
Traverse this tree consuming the
value and current depth at each node. |
void |
traverseWithParent(BiConsumer<A,A> c)
Traverse this tree consuming pairs of (
value, parent.value). |
public A getValue()
public void traverse(Consumer<A> c)
value at each node.c - the value Consumer.public void traverseNodes(Consumer<Tree<A>> c)
Tree node.c - the node Consumer.public void traverseWithDepth(BiConsumer<A,Integer> c)
value and current depth at each node.c - the value and depth BiConsumer.public void traverseWithParent(BiConsumer<A,A> c)
value, parent.value).
parent.value may be null if this node is the root.
c - the BiConsumer.Copyright © 2025. All rights reserved.