Package org.atlanmod.commons.collect
Class Tree<T>
- java.lang.Object
-
- org.atlanmod.commons.collect.Tree<T>
-
- Type Parameters:
T- the type of elements (node contents) in this tree.
- All Implemented Interfaces:
Iterable<T>
@ParametersAreNonnullByDefault public class Tree<T> extends Object implements Iterable<T>
A Tree data structure, with a root value and subtrees of children with a parent node, represented as a set of linked nodes. This data structure can represent hierarchical data such as: - File paths: "/usr/local/bin" - Domain names: "org.atlanmod.commons" - Namespaces: "java.util.function.BiFunction" This Tree can be seen as a recursive collection ofNode, where each node is itself a data structure consisting of a content (or value), along with a ser of nodes, the children. Nodes that do not have children are named Leaves. For instance:
In the example above, r is the root and b,d,e,f,g are leaves. When traversing this tree, ther / | \ a b c /|\ | d e f gIteratorwill visit nodes a,b,c,d,e,f,g in this exact sequence. TheTreeprovides an breadth-firstIterator.
-
-
Constructor Summary
Constructors Constructor Description Tree()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(T... path)booleanisEmpty()Returnstrueif this tree contains no elements,falseotherwiseIterator<T>iterator()Returns a breadth-first iterator over the elements in this treeList<T>leaves()Returns aListcontaining the values (contents) of all leaf nodes of this treeStringtoString()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Method Detail
-
add
@SafeVarargs public final void add(T... path)
-
isEmpty
public boolean isEmpty()
Returnstrueif this tree contains no elements,falseotherwise- Returns:
trueif this tree contains no elements
-
leaves
public List<T> leaves()
Returns aListcontaining the values (contents) of all leaf nodes of this tree- Returns:
- a list of values
-
-