- Type Parameters:
T- The type of the wrapped data of the tree node.
- All Superinterfaces:
Iterable<TreeModel<T>>,Serializable
- All Known Implementing Classes:
AbstractTreeModel,ListTreeModel,SortedTreeModel
A generic and simple tree data model which is to be used by
Tree component.- Author:
- Bauke Scholtz
-
Method Summary
Modifier and TypeMethodDescriptionCreates and adds a child tree node with the given wrapped data to the current tree node.addChildNode(TreeModel<T> child) Adds the given child tree node to the current tree node.intReturns the count of the children of the current tree node.Returns an unmodifiable list of all child tree nodes of the current tree node.getData()Returns the wrapped data of the current tree node.getIndex()Returns the zero-based unique index of the current tree node.intgetLevel()Returns the level of the current tree node.Returns the next tree node sibling of the current tree node.Returns the parent tree node of the current tree node.Returns the previous tree node sibling of the current tree node.booleanisFirst()Returns whether the current tree node is the first child of its parent, if any.booleanisLast()Returns whether the current tree node is the last child of its parent, if any.booleanisLeaf()Returns whether the current tree node is a leaf node.booleanisRoot()Returns whether the current tree node is the root node.iterator()Returns an unmodifiable iterator over the children of the current tree node.remove()Removes the current tree node from its parent, if any.voidSets the wrapped data of the current tree node.Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Method Details
-
setData
Sets the wrapped data of the current tree node.- Parameters:
data- The wrapped data of current tree node.
-
addChild
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
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
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
Returns the parent tree node of the current tree node. Returnsnullif there is none.- Returns:
- The parent tree node of the current tree node.
-
getNextSibling
Returns the next tree node sibling of the current tree node. Returnsnullif there is none.- Returns:
- The next tree node sibling of the current tree node.
- Since:
- 1.4
-
getPreviousSibling
Returns the previous tree node sibling of the current tree node. Returnsnullif 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
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 theaddChild(Object)method on the tree node parent. Removing children should be done by theremove()method on the tree node itself.- Returns:
- An unmodifiable list of all child tree nodes of the current tree node.
-
iterator
Returns an unmodifiable iterator over the children of the current tree node. Adding/inserting/removing elements is not supported on the iterator. -
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 ofnull. The first child has index0. The second child of first child has index0_1. The first child of second child of third child has index2_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:
trueif the current tree node is the root node, otherwisefalse.
-
isLeaf
boolean isLeaf()Returns whether the current tree node is a leaf node. That is, when it has no children.- Returns:
trueif the current tree node is a leaf node, otherwisefalse.
-
isFirst
boolean isFirst()Returns whether the current tree node is the first child of its parent, if any.- Returns:
trueif the current tree node is the first child of its parent, otherwisefalse.
-
isLast
boolean isLast()Returns whether the current tree node is the last child of its parent, if any.- Returns:
trueif the current tree node is the last child of its parent, otherwisefalse.
-