java.lang.Object
org.bzdev.util.UniTreeNode<T>
- All Implemented Interfaces:
Iterable<T>
Class used to construct a tree of elements traversable in one direction.
The tree can be traversed only from a leaf or
intermediate node towards the root. As a result, the tree is
thread safe without the need for locking (a UniTreeNode's fields
are modified only in constructors), resulting in a light-weight
implementation.
Each leaf's view of the tree is basically a unidirectional link list, but where multiple lists may share common nodes. There is no operation to remove items from the tree: memory will be reclaimed by the garbage collector once references to a a UniTreeNode are dropped.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdd a node to this tree.static <T> UniTreeNode<T>
addTo
(T element, UniTreeNode<T> tree) Add a node to a tree.Get the element associated with a node.iterator()
Return a parallel stream of the elements from this leaf to the root of the tree.parent()
Get the parent of this node.stream()
Return a stream of the elements from this leaf to the root of the tree.
-
Constructor Details
-
UniTreeNode
Constructor.- Parameters:
element
- the element associated with a new root node
-
-
Method Details
-
add
Add a node to this tree.- Parameters:
element
- the element to add to this tree- Returns:
- the new node
-
addTo
Add a node to a tree.- Type Parameters:
T
- the type of the element to add to this tree- Parameters:
element
- the element to add to this treetree
- an existing tree- Returns:
- the new node
-
getElement
Get the element associated with a node.- Returns:
- the element associated with this node
-
parent
Get the parent of this node.- Returns:
- the next node
-
iterator
-
spliterator
- Specified by:
spliterator
in interfaceIterable<T>
-
stream
Return a stream of the elements from this leaf to the root of the tree.- Returns:
- a stream
-
parallelStream
Return a parallel stream of the elements from this leaf to the root of the tree.- Returns:
- a parallel stream
-