-
- Type Parameters:
T
- the entity type contained in the tree
- All Superinterfaces:
Foldable<T>
,java.lang.Iterable<T>
,java.io.Serializable
,Streamable<T>
,Traversable<T>
,Value<T>
public interface Tree<T> extends Traversable<T>
- Since:
- 0.0.5
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
Tree.NodeCollection<T>
The node collection is a set of tree elements each containing exactly one value.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description Tree<T>
appendChild(java.lang.String label, T child)
Tree.NodeCollection<T>
children()
Fetch the collection of child tree elements contained within this tree.default Optional<Tree<T>>
getChild(java.lang.String label)
default boolean
isLeaf()
Indicates if the tree is a leaf node.default boolean
isRoot()
Indicates if the current tree node is the root of the tree.java.lang.String
label()
Fetch the label that belongs to the current tree.<U> Tree<U>
map(java.util.function.Function<T,U> mapper)
Perform a mapping operation on the elements in the stream.Tree<T>
orElse(java.lang.Iterable<? extends T> other)
Returns eitherthis
if it is non empty, otherwise will return the providedother
.Tree<T>
orElse(java.util.function.Supplier<? extends java.lang.Iterable<? extends T>> supplier)
Returns eitherthis
if it is non empty, otherwise the provided supplier is evaluated and returned.Tree<T>
parent()
Get the parent tree node for this tree node.-
Methods inherited from interface com.jongsoft.lang.collection.Foldable
fold, foldLeft, foldRight, reduce, reduceLeft
-
-
-
-
Method Detail
-
children
Tree.NodeCollection<T> children()
Fetch the collection of child tree elements contained within this tree.- Returns:
- the child collection
-
isLeaf
default boolean isLeaf()
Indicates if the tree is a leaf node. This will betrue
when the Tree has not children.- Returns:
- true if
children()
is empty
-
isRoot
default boolean isRoot()
Indicates if the current tree node is the root of the tree. This call yields the same result as validating if parent() equalsnull
.- Returns:
- true if this tree node is the root
-
label
java.lang.String label()
Fetch the label that belongs to the current tree.- Returns:
- the string label of the tree
-
map
<U> Tree<U> map(java.util.function.Function<T,U> mapper)
Description copied from interface:Streamable
Perform a mapping operation on the elements in the stream.This operation will loop over all elements in the stream and apply the
mapper
method. The mapped values will be returned in as a new stream of elements.- Specified by:
map
in interfaceStreamable<T>
- Specified by:
map
in interfaceTraversable<T>
- Type Parameters:
U
- the type of object expected as a result- Parameters:
mapper
- the mapping functionality- Returns:
- the mapped object
-
orElse
Tree<T> orElse(java.lang.Iterable<? extends T> other)
Description copied from interface:Traversable
Returns eitherthis
if it is non empty, otherwise will return the providedother
.- Specified by:
orElse
in interfaceTraversable<T>
- Parameters:
other
- the alternative- Returns:
- this
Traversable
if non empty, orother
-
orElse
Tree<T> orElse(java.util.function.Supplier<? extends java.lang.Iterable<? extends T>> supplier)
Description copied from interface:Traversable
Returns eitherthis
if it is non empty, otherwise the provided supplier is evaluated and returned.- Specified by:
orElse
in interfaceTraversable<T>
- Parameters:
supplier
- the supplier to generate the other- Returns:
- this (@code Traversable} if non empty, otherwise other
-
-