public final class FlatTreeNode<T> extends Object implements FlatTree<T,FlatTreeNode<T>>, Serializable
FlatTree
interface.Modifier and Type | Method and Description |
---|---|
int |
childCount()
Return the number of children this tree node consists of.
|
int |
childOffset()
Return the index of the first child node in the underlying node array.
|
boolean |
equals(Object obj) |
ISeq<FlatTreeNode<T>> |
flattenedNodes()
Return the whole flattened tree values in breadth-first order.
|
FlatTreeNode<T> |
getChild(int index)
Return the child node with the given index.
|
Optional<FlatTreeNode<T>> |
getParent()
Return the parent node of this tree node.
|
FlatTreeNode<T> |
getRoot()
Returns the root of the tree that contains this node.
|
T |
getValue()
Return the value of the current
Tree node. |
int |
hashCode() |
boolean |
identical(Tree<?,?> other)
Tests whether
this node is the same as the other node. |
boolean |
isRoot()
Returns
true if this node is the root of the tree. |
<B> ISeq<B> |
map(Function<FlatTreeNode<T>,? extends B> mapper)
Return a sequence of all mapped nodes of the whole underlying
tree.
|
static <V> FlatTreeNode<V> |
of(Tree<? extends V,?> tree)
Create a new
FlatTreeNode from the given tree . |
Stream<FlatTreeNode<T>> |
stream()
Return a stream of all nodes of the whole underlying tree.
|
String |
toString() |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
breadthFirstIterator, breadthFirstStream, childAfter, childAtPath, childAtPath, childBefore, childIterator, childPath, childStream, depth, depthFirstIterator, depthFirstStream, equals, firstChild, firstLeaf, getIndex, getPath, hashCode, isAncestor, isChild, isDescendant, isLeaf, isRelated, isSibling, iterator, lastChild, lastLeaf, leafCount, level, nextLeaf, nextNode, nextSibling, pathFromAncestorIterator, postorderIterator, postorderStream, preorderIterator, preorderStream, previousLeaf, previousNode, previousSibling, sharedAncestor, siblingCount, size, toCompactString, toDottyString, toParenthesesString, toParenthesesString, toString
forEach, spliterator
public FlatTreeNode<T> getRoot()
getRoot
in interface Tree<T,FlatTreeNode<T>>
public boolean isRoot()
Tree
true
if this node is the root of the tree.isRoot
in interface Tree<T,FlatTreeNode<T>>
true
if this node is the root of its tree, false
otherwisepublic T getValue()
Tree
Tree
node. The value may be
null
.getValue
in interface Tree<T,FlatTreeNode<T>>
Tree
nodepublic Optional<FlatTreeNode<T>> getParent()
Tree
getParent
in interface Tree<T,FlatTreeNode<T>>
Optional.empty()
if this node is the
root of the treepublic FlatTreeNode<T> getChild(int index)
Tree
getChild
in interface Tree<T,FlatTreeNode<T>>
index
- the child indexpublic int childCount()
Tree
childCount
in interface Tree<T,FlatTreeNode<T>>
public int childOffset()
-1
is returned if this
node is a leaf.childOffset
in interface FlatTree<T,FlatTreeNode<T>>
-1
if this
node is a leafpublic ISeq<FlatTreeNode<T>> flattenedNodes()
FlatTree
final ISeq<T> seq = getRoot().breadthFirstStream()
.collect(ISeq.toISeq());
flattenedNodes
in interface FlatTree<T,FlatTreeNode<T>>
public Stream<FlatTreeNode<T>> stream()
final Stream<FlatTreeNode<T>> nodes = getRoot().breadthFirstStream();
stream
in interface Tree<T,FlatTreeNode<T>>
Tree.breadthFirstStream()
public <B> ISeq<B> map(Function<FlatTreeNode<T>,? extends B> mapper)
final ISeq<B> seq = stream()
.map(mapper)
.collect(ISeq.toISeq())
B
- the mapped typemapper
- the mapper functionpublic boolean identical(Tree<?,?> other)
Tree
this
node is the same as the other
node.
The default implementation returns the object identity,
this == other
, of the two objects, but other implementations may
use different criteria for checking the identity.identical
in interface Tree<T,FlatTreeNode<T>>
other
- the other
nodetrue
if the other
node is the same as this
node.public static <V> FlatTreeNode<V> of(Tree<? extends V,?> tree)
FlatTreeNode
from the given tree
.V
- the tree value typestree
- the source treeFlatTreeNode
from the given tree
NullPointerException
- if the given tree
is null
© 2007-2019 Franz Wilhelmstötter (2019-02-19 21:44)