Class Tree<E>

  • Type Parameters:
    E - The type of elements
    All Implemented Interfaces:
    Serializable
    Direct Known Subclasses:
    Tree.Empty, Tree.Node

    public abstract class Tree<E>
    extends Object
    implements Serializable
    Binary tree with elements which are generic. Trees are immutable. This structure closely corresponds to the functional list structure FList
    Author:
    Herbert Praehofer
    See Also:
    Serialized Form
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  Tree.Empty<E>
      Class for the empty tree.
      static class  Tree.Node<E>
      Class representing a tree node with a value and a left and right subtree.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static Tree EMPTY
      The single object representing the empty tree
    • Constructor Summary

      Constructors 
      Constructor Description
      Tree()  
    • Field Detail

      • EMPTY

        private static final Tree EMPTY
        The single object representing the empty tree
    • Constructor Detail

      • Tree

        public Tree()
    • Method Detail

      • empty

        public static <E> Tree<E> empty()
        Returns the empty tree.
        Type Parameters:
        E - the element type
        Returns:
        the empty tree
      • of

        public static <E> Tree<E> of​(E value,
                                     Tree<E> left,
                                     Tree<E> right)
        Creates a functional tree node with a value and a left and right subtree.
        Type Parameters:
        E - the element type
        Parameters:
        value - the value of this tree node
        left - the left subtree
        right - the right subtree
        Returns:
        the tree node with value and left and right subtrees
      • of

        public static <E> Tree<E> of​(E value)
        Creates a functional tree node with a value and empty left and right subtrees.
        Type Parameters:
        E - the element type
        Parameters:
        value - the value of this tree node
        Returns:
        the tree node with value and empty left and right subtrees
      • value

        public abstract E value()
        Returns the value of this tree node.
        Returns:
        the value of this tree node
      • left

        public abstract Tree<E> left()
        Returns the left subtree of this tree node.
        Returns:
        the left subtree of this tree node
      • right

        public abstract Tree<E> right()
        Returns the right subtree of this tree node.
        Returns:
        the right subtree of this tree node
      • isEmpty

        public abstract boolean isEmpty()
        Tests if this tree is the empty tree.
        Returns:
        true, if this tree is the empty tree; false otherwise
      • leftExists

        public abstract boolean leftExists()
        Tests if the left subtree is not empty.
        Returns:
        true if the left subtree is not empty; false otherwise
      • rightExists

        public abstract boolean rightExists()
        Tests if the right subtree is not empty.
        Returns:
        true if the right subtree is not empty; false otherwise