Interface Tree<T>

  • 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 Detail

      • appendChild

        Tree<T> appendChild​(java.lang.String label,
                            T child)
      • children

        Tree.NodeCollection<T> children()
        Fetch the collection of child tree elements contained within this tree.
        Returns:
        the child collection
      • getChild

        default Optional<Tree<T>> getChild​(java.lang.String label)
      • isLeaf

        default boolean isLeaf()
        Indicates if the tree is a leaf node. This will be true 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() equals null.
        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 interface Streamable<T>
        Specified by:
        map in interface Traversable<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 either this if it is non empty, otherwise will return the provided other.
        Specified by:
        orElse in interface Traversable<T>
        Parameters:
        other - the alternative
        Returns:
        this Traversable if non empty, or other
      • orElse

        Tree<T> orElse​(java.util.function.Supplier<? extends java.lang.Iterable<? extends T>> supplier)
        Description copied from interface: Traversable
        Returns either this if it is non empty, otherwise the provided supplier is evaluated and returned.
        Specified by:
        orElse in interface Traversable<T>
        Parameters:
        supplier - the supplier to generate the other
        Returns:
        this (@code Traversable} if non empty, otherwise other
      • parent

        Tree<T> parent()
        Get the parent tree node for this tree node.
        Returns:
        the parent, or null if no parent exists