Package org.arakhne.afc.math.tree.node
Class AbstractTreeNode<D,N extends AbstractTreeNode<D,N>>
- java.lang.Object
-
- org.arakhne.afc.math.tree.node.AbstractParentlessTreeNode<D,N>
-
- org.arakhne.afc.math.tree.node.AbstractTreeNode<D,N>
-
- Type Parameters:
D
- is the type of the data inside the treeN
- is the type of the tree nodes.
- All Implemented Interfaces:
Serializable
,Comparable<N>
,IterableNode<N>
,TreeNode<D,N>
,JsonableObject
- Direct Known Subclasses:
BinaryTreeNode
,ConstantNaryTreeNode
,NaryTreeNode
,OctTreeNode
,PentaTreeNode
,QuadTreeNode
,TernaryTreeNode
public abstract class AbstractTreeNode<D,N extends AbstractTreeNode<D,N>> extends AbstractParentlessTreeNode<D,N>
This is the generic implementation of a tree tree with a weak reference to its parent node.- Since:
- 13.0
- Version:
- 17.0 2020-01-04 14:41:41
- Author:
- Stéphane GALLAND
- See Also:
- Serialized Form
- Maven Group Id:
- org.arakhne.afc.core
- Maven Artifact Id:
- mathtree
-
-
Field Summary
-
Fields inherited from class org.arakhne.afc.math.tree.node.AbstractParentlessTreeNode
DEFAULT_COPY_USER_DATA, DEFAULT_LINK_LIST_USE, nodeListeners, notNullChildCount
-
-
Constructor Summary
Constructors Constructor Description AbstractTreeNode(boolean useLinkedList)
Construct node.AbstractTreeNode(boolean useLinkedList, boolean copyDataCollection, List<D> data)
Construct node.AbstractTreeNode(boolean useLinkedList, D data)
Construct node.AbstractTreeNode(boolean useLinkedList, Collection<D> data)
Construct node.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Iterator<N>
children()
Replies the not-null child nodes of this node.protected void
firePropertyChildAdded(int childIndex, N newChild)
Fire the event for the node child sets.(package private) void
firePropertyChildAdded(TreeNodeAddedEvent event)
Fire the event for the node child sets.protected void
firePropertyChildRemoved(int childIndex, N oldChild)
Fire the event for the removed node child.(package private) void
firePropertyChildRemoved(TreeNodeRemovedEvent event)
Fire the event for the removed node child.protected void
firePropertyParentChanged(N oldParent, N newParent)
Fire the event for the changes node parents.(package private) void
firePropertyParentChanged(N node, N oldParent, N newParent)
Fire the event for the changes node parents.(package private) void
firePropertyParentChanged(TreeNodeParentChangedEvent event)
Fire the event for the changes node parents.N[]
getChildren(Class<N> type)
Replies the child nodes of this node.int
getDepth()
Replies the depth level of this node.N
getParentNode()
Replies the parent node ornull
.boolean
isRoot()
Replies if this node is a root.protected boolean
moveTo(N newParent, int index, boolean isDynamicChildList)
Move this node in the given new node.void
removeDeeplyFromParent()
Remove this node from its parent and remove the parent if it is becoming empty, and so one.N
removeFromParent()
Remove this node from its parent.abstract boolean
setChildAt(int index, N newChild)
Set the n-th child in this node.protected abstract void
setChildAtWithoutEventFiring(int index, N child)
Invoked by the inner classes to set the child at the given index without firing the events.(package private) boolean
setParentNodeReference(N newParent, boolean fireEvent)
Set the reference to the parent node.-
Methods inherited from class org.arakhne.afc.math.tree.node.AbstractParentlessTreeNode
addTreeNodeListener, addUserData, addUserData, addUserData, addUserData, compareTo, firePropertyDataChanged, firePropertyDataChanged, firePropertyDataChanged, getAllUserData, getAllUserData, getDeepNodeCount, getDeepUserDataCount, getHeights, getHeights, getInternalDataStructureForUserData, getUserData, getUserDataAt, getUserDataCount, isEmpty, isValid, removeAllUserData, removeTreeNodeListener, removeUserData, removeUserData, removeUserData, setUserData, setUserData, setUserDataAt, toJson, toN, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.arakhne.afc.math.tree.IterableNode
getChildAt, getChildCount, getNotNullChildCount, isLeaf
-
Methods inherited from interface org.arakhne.afc.math.tree.TreeNode
clear, getChildren, getMaxHeight, getMinHeight, getPartitionEnumeration, indexOf, moveTo, removeChild
-
-
-
-
Constructor Detail
-
AbstractTreeNode
public AbstractTreeNode(boolean useLinkedList)
Construct node.- Parameters:
useLinkedList
- indicates if a linked list must be used to store the data. Iffalse
, an ArrayList will be used.
-
AbstractTreeNode
public AbstractTreeNode(boolean useLinkedList, boolean copyDataCollection, List<D> data)
Construct node.- Parameters:
useLinkedList
- indicates if a linked list must be used to store the data. Iffalse
, an ArrayList will be used.copyDataCollection
- indicates if the given data collection is copied iftrue
or the inner data collection will be the given collection itself iffalse
.data
- are the initial user data.
-
AbstractTreeNode
public AbstractTreeNode(boolean useLinkedList, Collection<D> data)
Construct node.- Parameters:
useLinkedList
- indicates if a linked list must be used to store the data. Iffalse
, an ArrayList will be used.data
- are the initial user data.
-
AbstractTreeNode
public AbstractTreeNode(boolean useLinkedList, D data)
Construct node.- Parameters:
useLinkedList
- indicates if a linked list must be used to store the data. Iffalse
, an ArrayList will be used.data
- are the initial user data.
-
-
Method Detail
-
getDepth
@Pure public int getDepth()
Description copied from interface:TreeNode
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.
-
setChildAt
public abstract boolean setChildAt(int index, N newChild) throws IndexOutOfBoundsException
Description copied from interface:TreeNode
Set the n-th child in this node.- Parameters:
index
- is the index of the child to replynewChild
- is the new child node.- Returns:
true
if it was set, otherwisefalse
- Throws:
IndexOutOfBoundsException
- if the given index was invalid
-
getParentNode
@Pure public final N getParentNode()
Description copied from interface:TreeNode
Replies the parent node ornull
.- Returns:
- the node that is containing this object.
-
setParentNodeReference
boolean setParentNodeReference(N newParent, boolean fireEvent)
Set the reference to the parent node.- Parameters:
newParent
- is the new parent.fireEvent
- indicates if the event must be fired or not.- Returns:
true
if an event must be fired due to the action of this function, otherwisefalse
.- Since:
- 4.0
-
removeFromParent
public N removeFromParent()
Description copied from interface:IterableNode
Remove this node from its parent.- Returns:
- the parent node from which the node was removed.
-
removeDeeplyFromParent
public void removeDeeplyFromParent()
Description copied from interface:TreeNode
Remove this node from its parent and remove the parent if it is becoming empty, and so one.
-
firePropertyChildAdded
protected final void firePropertyChildAdded(int childIndex, N newChild)
Fire the event for the node child sets.- Parameters:
childIndex
- is the index of the child that was set. If the added node was root, this parameter is0
.newChild
- is the child that was added.
-
firePropertyChildAdded
void firePropertyChildAdded(TreeNodeAddedEvent event)
Fire the event for the node child sets.- Parameters:
event
- the event.
-
firePropertyChildRemoved
protected final void firePropertyChildRemoved(int childIndex, N oldChild)
Fire the event for the removed node child.- Parameters:
childIndex
- is the index of the child that was removed. If the added node was root, this parameter is0
.oldChild
- is the child that was removed.
-
firePropertyChildRemoved
void firePropertyChildRemoved(TreeNodeRemovedEvent event)
Fire the event for the removed node child.- Parameters:
event
- the event.
-
firePropertyParentChanged
protected final void firePropertyParentChanged(N oldParent, N newParent)
Fire the event for the changes node parents.- Parameters:
oldParent
- is the previous parent nodenewParent
- is the current parent node
-
firePropertyParentChanged
void firePropertyParentChanged(N node, N oldParent, N newParent)
Fire the event for the changes node parents.- Parameters:
node
- is the node for which the parent has changed.oldParent
- is the previous parent nodenewParent
- is the current parent node
-
firePropertyParentChanged
void firePropertyParentChanged(TreeNodeParentChangedEvent event)
Fire the event for the changes node parents.- Parameters:
event
- the event.
-
isRoot
@Pure public final boolean isRoot()
Description copied from interface:TreeNode
Replies if this node is a root.- Returns:
true
is this node is the root, otherwisefalse
-
getChildren
@Pure public final N[] getChildren(Class<N> type)
Description copied from interface:TreeNode
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:
TreeNode.getChildren(Object[])
,TreeNode.children()
-
children
@Pure public final Iterator<N> children()
Description copied from interface:TreeNode
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:
TreeNode.getChildren(Object[])
,TreeNode.getChildren(Class)
-
moveTo
protected boolean moveTo(N newParent, int index, boolean isDynamicChildList)
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
removeFromParent()
andsetChildAt(int, AbstractTreeNode)
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.isDynamicChildList
- indicates if the parent node has a dynamic list of children. Iftrue
the givenindex
is clamped to avoidIndexOutOfBoundsException
when inserting this node in the parent node. Iffalse
anIndexOutOfBoundsException
is thrown when the givenindex
is outside the range of children of the parent node.- Returns:
true
on success, otherwisefalse
.
-
setChildAtWithoutEventFiring
protected abstract void setChildAtWithoutEventFiring(int index, N child) throws IndexOutOfBoundsException
Invoked by the inner classes to set the child at the given index without firing the events. This function should never invokesetParentNodeReference(AbstractTreeNode, boolean)
.- Parameters:
index
- is the position of the new child.child
- is the new child- Throws:
IndexOutOfBoundsException
- if the index is invalid.
-
-