Class Tree.Node<E>

  • Type Parameters:
    E - the element type
    All Implemented Interfaces:
    Serializable
    Enclosing class:
    Tree<E>

    public static class Tree.Node<E>
    extends Tree<E>
    Class representing a tree node with a value and a left and right subtree.
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private Tree<E> left
      The left subtree of this tree node; possibly empty.
      private Tree<E> right
      The right subtree of this tree node; possibly empty.
      private E value
      The value of this tree node.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private Node​(E value, Tree<E> left, Tree<E> right)
      Private constructor initializing value and left and right subtrees.
    • Field Detail

      • value

        private final E value
        The value of this tree node.
      • left

        private final Tree<E> left
        The left subtree of this tree node; possibly empty.
      • right

        private final Tree<E> right
        The right subtree of this tree node; possibly empty.
    • Constructor Detail

      • Node

        private Node​(E value,
                     Tree<E> left,
                     Tree<E> right)
        Private constructor initializing value and left and right subtrees.
        Parameters:
        value - the value of this tree node
        left - the left subtree of this tree node
        right - the right subtree of this tree node
    • Method Detail

      • value

        public E value()
        Returns the value of this tree node.
        Specified by:
        value in class Tree<E>
        Returns:
        the value of this node
      • left

        public Tree<E> left()
        Returns the left subtree of this tree node
        Specified by:
        left in class Tree<E>
        Returns:
        the left subtree of this tree node
      • right

        public Tree<E> right()
        Returns the right subtree of this tree node
        Specified by:
        right in class Tree<E>
        Returns:
        the right subtree of this tree node
      • isEmpty

        public boolean isEmpty()
        Returns false as this tree node is not the empty tree node.
        Specified by:
        isEmpty in class Tree<E>
        Returns:
        false
      • leftExists

        public boolean leftExists()
        Test if the left subtree is not empty.
        Specified by:
        leftExists in class Tree<E>
        Returns:
        true if the the left subtree is not empty; false otherwise
      • rightExists

        public boolean rightExists()
        Test if the right subtree is not empty.
        Specified by:
        rightExists in class Tree<E>
        Returns:
        true if the the right subtree is not empty; false otherwise
      • toString

        public String toString()
        Returns a string representation of this tree node.
        Overrides:
        toString in class Object
        Returns:
        a string representation of this tree node
      • hashCode

        public int hashCode()
        Returns a hash code value for the tree node. It is computed from the hash code of the value and the left and right substrees.
        Overrides:
        hashCode in class Object
        Returns:
        the hash code
      • equals

        public boolean equals​(Object obj)
        Indicates whether some other object is "equal to" this tree. The object is equal to this tree, if it is a tree node and the value and the left and right subtrees are equal.
        Overrides:
        equals in class Object
        Returns:
        true if this tree is the same as the argument; false otherwise.