Interface TreeModel<T>

    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      TreeModel<T> addChild​(T data)
      Creates and adds a child tree node with the given wrapped data to the current tree node.
      TreeModel<T> addChildNode​(TreeModel<T> child)
      Adds the given child tree node to the current tree node.
      int getChildCount()
      Returns the count of the children of the current tree node.
      List<TreeModel<T>> getChildren()
      Returns an unmodifiable list of all child tree nodes of the current tree node.
      T getData()
      Returns the wrapped data of the current tree node.
      String getIndex()
      Returns the zero-based unique index of the current tree node.
      int getLevel()
      Returns the level of the current tree node.
      TreeModel<T> getNextSibling()
      Returns the next tree node sibling of the current tree node.
      TreeModel<T> getParent()
      Returns the parent tree node of the current tree node.
      TreeModel<T> getPreviousSibling()
      Returns the previous tree node sibling of the current tree node.
      boolean isFirst()
      Returns whether the current tree node is the first child of its parent, if any.
      boolean isLast()
      Returns whether the current tree node is the last child of its parent, if any.
      boolean isLeaf()
      Returns whether the current tree node is a leaf node.
      boolean isRoot()
      Returns whether the current tree node is the root node.
      Iterator<TreeModel<T>> iterator()
      Returns an unmodifiable iterator over the children of the current tree node.
      TreeModel<T> remove()
      Removes the current tree node from its parent, if any.
      void setData​(T data)
      Sets the wrapped data of the current tree node.
    • Method Detail

      • setData

        void setData​(T data)
        Sets the wrapped data of the current tree node.
        Parameters:
        data - The wrapped data of current tree node.
      • addChild

        TreeModel<T> addChild​(T data)
        Creates and adds a child tree node with the given wrapped data to the current tree node. It returns the newly created and added child tree node to ease further building.
        Parameters:
        data - The wrapped data of the child tree node to be created and added.
        Returns:
        The newly created and added child tree node of the current tree node.
        Throws:
        IllegalArgumentException - When the given wrapped data is not acceptable by the tree model implementation.
        UnsupportedOperationException - When the child tree node cannot be instantiated using default constructor.
      • addChildNode

        TreeModel<T> addChildNode​(TreeModel<T> child)
        Adds the given child tree node to the current tree node. It returns the added child tree node to ease further building.
        Parameters:
        child - The child tree node to be added.
        Returns:
        The same child treenode.
        Throws:
        IllegalArgumentException - When the given child is not an instance of the same class as the parent.
        Since:
        1.1
      • remove

        TreeModel<T> remove()
        Removes the current tree node from its parent, if any. It returns the parent to ease further building.
        Returns:
        The parent tree node of the current tree node.
        Since:
        1.1
      • getData

        T getData()
        Returns the wrapped data of the current tree node.
        Returns:
        The wrapped data of the current tree node.
      • getParent

        TreeModel<T> getParent()
        Returns the parent tree node of the current tree node. Returns null if there is none.
        Returns:
        The parent tree node of the current tree node.
      • getNextSibling

        TreeModel<T> getNextSibling()
        Returns the next tree node sibling of the current tree node. Returns null if there is none.
        Returns:
        The next tree node sibling of the current tree node.
        Since:
        1.4
      • getPreviousSibling

        TreeModel<T> getPreviousSibling()
        Returns the previous tree node sibling of the current tree node. Returns null if there is none.
        Returns:
        The previous tree node sibling of the current tree node.
        Since:
        1.4
      • getChildCount

        int getChildCount()
        Returns the count of the children of the current tree node.
        Returns:
        The count of the children of the current tree node.
      • getChildren

        List<TreeModel<T>> getChildren()
        Returns an unmodifiable list of all child tree nodes of the current tree node. Adding and removing elements is not supported on the list. Adding new children should be done by the addChild(Object) method on the tree node parent. Removing children should be done by the remove() method on the tree node itself.
        Returns:
        An unmodifiable list of all child tree nodes of the current tree node.
      • iterator

        Iterator<TreeModel<T>> iterator()
        Returns an unmodifiable iterator over the children of the current tree node. Adding/inserting/removing elements is not supported on the iterator.
        Specified by:
        iterator in interface Iterable<T>
        Returns:
        An unmodifiable iterator over the children of the current tree node.
        See Also:
        Iterable
      • getLevel

        int getLevel()
        Returns the level of the current tree node. The root node has level 0.
        Returns:
        The level of the current tree node.
      • getIndex

        String getIndex()
        Returns the zero-based unique index of the current tree node. This is an underscore separated representation of the position of the node in the tree hierarchy. The root node has index of null. The first child has index 0. The second child of first child has index 0_1. The first child of second child of third child has index 2_1_0.
        Returns:
        The unique index of the current tree node.
      • isRoot

        boolean isRoot()
        Returns whether the current tree node is the root node. That is, when it has no parent.
        Returns:
        true if the current tree node is the root node, otherwise false.
      • isLeaf

        boolean isLeaf()
        Returns whether the current tree node is a leaf node. That is, when it has no children.
        Returns:
        true if the current tree node is a leaf node, otherwise false.
      • isFirst

        boolean isFirst()
        Returns whether the current tree node is the first child of its parent, if any.
        Returns:
        true if the current tree node is the first child of its parent, otherwise false.
      • isLast

        boolean isLast()
        Returns whether the current tree node is the last child of its parent, if any.
        Returns:
        true if the current tree node is the last child of its parent, otherwise false.