Interface TreeNode<D,N extends TreeNode<D,?>>
-
- Type Parameters:
D
- is the type of the data inside the treeN
- is the type of the tree nodes.
- All Superinterfaces:
Comparable<N>
,IterableNode<N>
- All Known Subinterfaces:
GISTreeNode<P,N>
- All Known Implementing Classes:
AbstractGISTreeSetNode
,AbstractParentlessTreeNode
,AbstractTreeNode
,BinaryTreeNode
,BinaryTreeNode.DefaultBinaryTreeNode
,ConstantNaryTreeNode
,ConstantNaryTreeNode.DefaultConstantNaryTreeNode
,GISTreeSetNode
,IcosepBinaryTreeNode
,IcosepBinaryTreeNode.DefaultIcosepBinaryTreeNode
,IcosepOctTreeNode
,IcosepOctTreeNode.DefaultIcosepOctTreeNode
,IcosepQuadTreeNode
,IcosepQuadTreeNode.DefaultIcosepQuadTreeNode
,NaryTreeNode
,NaryTreeNode.DefaultNaryTreeNode
,OctTreeNode
,OctTreeNode.DefaultOctTreeNode
,PentaTreeNode
,PentaTreeNode.DefaultPentaTreeNode
,QuadTreeNode
,QuadTreeNode.DefaultQuadTreeNode
,TernaryTreeNode
,TernaryTreeNode.DefaultTernaryTreeNode
,UnsupportedOperationTreeNode
,WeakGISTreeSetNode
public interface TreeNode<D,N extends TreeNode<D,?>> extends IterableNode<N>, Comparable<N>
This is the generic implementation of a tree node.- Since:
- 13.0
- Version:
- 17.0 2020-01-04 14:41:41
- Author:
- Stéphane GALLAND
- Maven Group Id:
- org.arakhne.afc.core
- Maven Artifact Id:
- mathtree
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
addTreeNodeListener(TreeNodeListener listener)
Add a listener on the node events.void
addUserData(int index, D data)
Add a user data associated to this node.boolean
addUserData(int index, Collection<? extends D> data)
Add a user data associated to this node.boolean
addUserData(D data)
Add a user data associated to this node.boolean
addUserData(Collection<? extends D> data)
Add a user data associated to this node.Iterator<N>
children()
Replies the not-null child nodes of this node.void
clear()
Clear the tree.List<D>
getAllUserData()
Replies the all user data associated to this node.D[]
getAllUserData(D[] array)
Replies the all user data associated to this node.N[]
getChildren(Class<N> type)
Replies the child nodes of this node.void
getChildren(Object[] array)
Replies the child nodes of this node.int
getDeepNodeCount()
Replies the count of nodes inside the tree for which the root is this node.int
getDeepUserDataCount()
Replies the count of user data inside the tree for which the root is this node.int
getDepth()
Replies the depth level of this node.int[]
getHeights()
Replies the heights of all the leaf nodes.int
getMaxHeight()
Replies the maximal height of the tree.int
getMinHeight()
Replies the minimal height of the tree.N
getParentNode()
Replies the parent node ornull
.Class<? extends Enum<?>>
getPartitionEnumeration()
Replies the enumeration type that is defining the children of the nodes.D
getUserData()
Replies the first user data associated to this node.D
getUserDataAt(int index)
Replies the user data associated to this node which is at the specified index.int
getUserDataCount()
Replies the count of user data associated to this node.int
indexOf(N child)
Replies the index of the specified child.boolean
isEmpty()
Replies if this node is a leaf and has no user data.boolean
isRoot()
Replies if this node is a root.boolean
isValid()
Replies if this node is a valid.boolean
moveTo(N newParent, int index)
Move this node in the given new node.void
removeAllUserData()
Remove all the user data associated to this node.boolean
removeChild(N child)
Remove the specified node from this node if it is a child.void
removeDeeplyFromParent()
Remove this node from its parent and remove the parent if it is becoming empty, and so one.void
removeTreeNodeListener(TreeNodeListener listener)
Remove a listener on the node events.D
removeUserData(int index)
Remove a user data associated to this node.boolean
removeUserData(D data)
Remove a user data associated to this node.boolean
removeUserData(Collection<D> data)
Remove a user data associated to this node.boolean
setChildAt(int index, N child)
Set the n-th child in this node.boolean
setUserData(D data)
Set the user data associated to this node.boolean
setUserData(Collection<D> data)
Set the user data associated to this node.boolean
setUserDataAt(int index, D data)
Set the user data associated to this node at the specified index.-
Methods inherited from interface java.lang.Comparable
compareTo
-
Methods inherited from interface org.arakhne.afc.math.tree.IterableNode
getChildAt, getChildCount, getNotNullChildCount, isLeaf, removeFromParent
-
-
-
-
Method Detail
-
getParentNode
@Pure N getParentNode()
Replies the parent node ornull
.- Returns:
- the node that is containing this object.
-
setChildAt
boolean setChildAt(int index, N child) throws IndexOutOfBoundsException
Set the n-th child in this node.- Parameters:
index
- is the index of the child to replychild
- is the new child node.- Returns:
true
if it was set, otherwisefalse
- Throws:
IndexOutOfBoundsException
- if the given index was invalid
-
indexOf
@Pure int indexOf(N child)
Replies the index of the specified child.- Parameters:
child
- is the node to search for.- Returns:
- the index or
-1
.
-
getPartitionEnumeration
@Pure Class<? extends Enum<?>> getPartitionEnumeration()
Replies the enumeration type that is defining the children of the nodes.- Returns:
- the enumeration type of the child partition,
or
null
if no such enumeration type is defined.
-
getAllUserData
D[] getAllUserData(D[] array)
Replies the all user data associated to this node.- Parameters:
array
- is the array to fill if it has enough cells- Returns:
- the parameter
a
if it has enough cells, otherwise another array.
-
getAllUserData
@Pure List<D> getAllUserData()
Replies the all user data associated to this node.- Returns:
- all the user data
-
getUserData
@Pure D getUserData()
Replies the first user data associated to this node.- Returns:
- first user data
-
getUserDataCount
@Pure int getUserDataCount()
Replies the count of user data associated to this node.- Returns:
- the count of user data.
-
getUserDataAt
@Pure D getUserDataAt(int index) throws IndexOutOfBoundsException
Replies the user data associated to this node which is at the specified index.- Parameters:
index
- is the position of the data to reply- Returns:
- the user data
- Throws:
IndexOutOfBoundsException
- when the given index in not valid
-
addUserData
boolean addUserData(Collection<? extends D> data)
Add a user data associated to this node.- Parameters:
data
- the data to add.- Returns:
true
if the the list of user data has changed, otherwisefalse
.
-
addUserData
boolean addUserData(int index, Collection<? extends D> data)
Add a user data associated to this node.- Parameters:
index
- is the position where to put the elements in the user data list.data
- the data to add.- Returns:
true
if the the list of user data has changed, otherwisefalse
.
-
addUserData
boolean addUserData(D data)
Add a user data associated to this node.- Parameters:
data
- the data to add.- Returns:
true
if the data was successfully added, otherwhisefalse
-
addUserData
void addUserData(int index, D data)
Add a user data associated to this node.- Parameters:
index
- is the position where to insert the data.data
- the data to add.
-
removeUserData
boolean removeUserData(Collection<D> data)
Remove a user data associated to this node.- Parameters:
data
- the data to remove.- Returns:
true
if the data was successfully removed, otherwhisefalse
-
removeUserData
boolean removeUserData(D data)
Remove a user data associated to this node.- Parameters:
data
- the data to remove.- Returns:
true
if the data was successfully removed, otherwhisefalse
-
removeUserData
D removeUserData(int index)
Remove a user data associated to this node.- Parameters:
index
- is the position of the user data to remove.- Returns:
- the removed data or
null
if the data was not removed.
-
setUserData
boolean setUserData(Collection<D> data)
Set the user data associated to this node.- Parameters:
data
- the data to put inside.- Returns:
true
if the data was successfully set, otherwhisefalse
-
setUserData
boolean setUserData(D data)
Set the user data associated to this node.- Parameters:
data
- the data to put inside.- Returns:
true
if the data was successfully set, otherwhisefalse
-
setUserDataAt
boolean setUserDataAt(int index, D data) throws IndexOutOfBoundsException
Set the user data associated to this node at the specified index.- Parameters:
index
- the index at which the data must be set.data
- the data to put inside.- Returns:
true
if the data was successfully set, otherwhisefalse
- Throws:
IndexOutOfBoundsException
- if the given index was invalid
-
addTreeNodeListener
void addTreeNodeListener(TreeNodeListener listener)
Add a listener on the node events.- Parameters:
listener
- the listener.
-
removeTreeNodeListener
void removeTreeNodeListener(TreeNodeListener listener)
Remove a listener on the node events.- Parameters:
listener
- the listener.
-
isEmpty
@Pure boolean isEmpty()
Replies if this node is a leaf and has no user data.This function is equivalent to call
IterableNode.isLeaf()
&&getUserDataCount()
==0- Returns:
true
is this node is a leaf without user data, otherwisefalse
-
isRoot
@Pure boolean isRoot()
Replies if this node is a root.- Returns:
true
is this node is the root, otherwisefalse
-
isValid
@Pure boolean isValid()
Replies if this node is a valid. The validity of a node depends of the node implementation.- Returns:
true
is this node is valid, otherwisefalse
-
clear
void clear()
Clear the tree.Caution: this method also destroyes the links between the child nodes inside the tree. If you want to unlink the first-level child node with this node but leave the rest of the tree unchanged, please call
setChildAt(i,null)
.
-
removeAllUserData
void removeAllUserData()
Remove all the user data associated to this node.
-
removeChild
boolean removeChild(N child)
Remove the specified node from this node if it is a child.- Parameters:
child
- is the child to remove.- Returns:
true
if the node was removed, otherwisefalse
-
removeDeeplyFromParent
void removeDeeplyFromParent()
Remove this node from its parent and remove the parent if it is becoming empty, and so one.
-
getDeepNodeCount
@Pure int getDeepNodeCount()
Replies the count of nodes inside the tree for which the root is this node.- Returns:
- the count of node inside the subtree.
-
getDeepUserDataCount
@Pure int getDeepUserDataCount()
Replies the count of user data inside the tree for which the root is this node.- Returns:
- the count of user data inside the subtree.
-
children
@Pure Iterator<N> children()
Replies the not-null child nodes of this node.The given iterator never replies a null value for a child node.
- Returns:
- the children.
- See Also:
getChildren(Object[])
,getChildren(Class)
-
getChildren
@Pure N[] getChildren(Class<N> type)
Replies the child nodes of this node.This function may put
null
in the array cells if the current tree node has not a child at the corresponding index.- Parameters:
type
- is the type of the children to reply.- Returns:
- the children.
- See Also:
getChildren(Object[])
,children()
-
getChildren
void getChildren(Object[] array)
Replies the child nodes of this node.This function may put
null
in the array cells if the current tree node has not a child at the corresponding index.- Parameters:
array
- is the array to fill.- See Also:
getChildren(Class)
,children()
-
getDepth
@Pure int getDepth()
Replies the depth level of this node. Depth level0
is the root node,1
are the children of the root node, etc.- Returns:
- the height of the lowest leaf in the tree.
-
getMinHeight
@Pure int getMinHeight()
Replies the minimal height of the tree.- Returns:
- the height of the uppest leaf in the tree.
-
getMaxHeight
@Pure int getMaxHeight()
Replies the maximal height of the tree.- Returns:
- the height of the lowest leaf in the tree.
-
getHeights
@Pure int[] getHeights()
Replies the heights of all the leaf nodes. The order of the heights is given by a depth-first iteration.- Returns:
- the heights of the leaf nodes
-
moveTo
boolean moveTo(N newParent, int index)
Move this node in the given new node.If any child node is already present at the given position in the new parent node, the tree node may replace the existing node or insert the moving node according to its implementation.
This function is preferred to a sequence of calls to
IterableNode.removeFromParent()
andsetChildAt(int, TreeNode)
because it fires a limited set of events dedicated to the move the node.- Parameters:
newParent
- is the new parent for this node.index
- is the position of this node in the new parent.- Returns:
true
on success, otherwisefalse
.
-
-