Interface Tree<T>

  • All Known Implementing Classes:
    NaryTree

    public interface Tree<T>
    Interface for class that want to implement Tree collection behavior.
    Version:
    $Revision$ $Date$
    Author:
    Nick Collier
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      void addNode​(T parent, T child)
      Adds the specified child to the tree as a child of the specified parent.
      boolean contains​(T parent, T node)
      Checks if the tree contains the specified node with the specified parent.
      Collection<T> getChildren​(T obj)
      Gets the direct children of the specified node.
      T getRoot()
      Gets the root of the tree.
      void preOrderTraversal​(TreeVisitor<T> visitor)
      Traverse the tree in preOrder - depth first, processing parents before children - applying the visitor to the nodes.
      boolean removeNode​(T obj)
      Removes the specified object from the tree.
      void replaceNode​(T oldObj, T newObj)
      Replaces the old object in the tree with the new one.
      int size()
      Gets the number of nodes currently in the tree.
      void sortChildren​(Comparator<T> comparator)
      Sorts the children of each node w/r to each other according the specified comparator
    • Method Detail

      • getRoot

        T getRoot()
        Gets the root of the tree.
        Returns:
        the root of the tree.
      • getChildren

        Collection<T> getChildren​(T obj)
        Gets the direct children of the specified node. This will not return grand children etc.
        Returns:
        the direct children of the specified node.
        Throws:
        IllegalArgumentException - if the object is not currently in the tree.
      • addNode

        void addNode​(T parent,
                     T child)
        Adds the specified child to the tree as a child of the specified parent.
        Parameters:
        parent - the parent node
        child - the child node
        Throws:
        IllegalArgumentException - if the parent is not currently in the tree.
      • removeNode

        boolean removeNode​(T obj)
        Removes the specified object from the tree.
        Parameters:
        obj - the object to remove
        Returns:
        true if the object was successfully removed, otherwise false.
      • replaceNode

        void replaceNode​(T oldObj,
                         T newObj)
        Replaces the old object in the tree with the new one.
        Parameters:
        oldObj - the old object to replace
        newObj - the new object
        Throws:
        IllegalArgumentException - if the old object is not currently in the tree.
      • contains

        boolean contains​(T parent,
                         T node)
        Checks if the tree contains the specified node with the specified parent. This will stop when it finds the first node corresponding to the parent, meaning, if multiple nodes correspond to the parent, only the first one will be checked.
        Parameters:
        parent - the parent node
        node - the child of the parent
        Returns:
        true if the tree contains the specified child node pair
      • size

        int size()
        Gets the number of nodes currently in the tree.
        Returns:
        the number of nodes currently in the tree.
      • sortChildren

        void sortChildren​(Comparator<T> comparator)
        Sorts the children of each node w/r to each other according the specified comparator
        Parameters:
        comparator - the comparator used to sort the children
      • preOrderTraversal

        void preOrderTraversal​(TreeVisitor<T> visitor)
        Traverse the tree in preOrder - depth first, processing parents before children - applying the visitor to the nodes.
        Parameters:
        visitor - the visitor to apply to the nodes