Class 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 of Node, 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:
     
                   r
                 / | \
                a  b  c
               /|\    |
              d e f   g
     
     
    In the example above, r is the root and b,d,e,f,g are leaves. When traversing this tree, the Iterator will visit nodes a,b,c,d,e,f,g in this exact sequence. The Tree provides an breadth-first Iterator.
    • Constructor Detail

      • Tree

        public Tree()
    • Method Detail

      • isEmpty

        public boolean isEmpty()
        Returns true if this tree contains no elements, false otherwise
        Returns:
        true if this tree contains no elements
      • leaves

        public List<T> leaves()
        Returns a List containing the values (contents) of all leaf nodes of this tree
        Returns:
        a list of values
      • iterator

        public Iterator<T> iterator()
        Returns a breadth-first iterator over the elements in this tree
        Specified by:
        iterator in interface Iterable<T>
        Returns:
        an iterator