Package org.arakhne.afc.math.tree.node
Class AbstractParentlessTreeNode<D,N extends AbstractParentlessTreeNode<D,N>>
- java.lang.Object
-
- org.arakhne.afc.math.tree.node.AbstractParentlessTreeNode<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:
AbstractTreeNode
public abstract class AbstractParentlessTreeNode<D,N extends AbstractParentlessTreeNode<D,N>> extends Object implements TreeNode<D,N>, Serializable, JsonableObject
This is the very generic implementation of a tree node which does not made any implementation choice about how this node is related 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 Modifier and Type Field Description static booleanDEFAULT_COPY_USER_DATABy default, does the user data are copied or not.static booleanDEFAULT_LINK_LIST_USEBy default, does tree nodes use a linked list or not.protected List<TreeNodeListener>nodeListenersList of the event listeners on the tree.protected intnotNullChildCountTemporary count of child nodes that are not null.
-
Constructor Summary
Constructors Constructor Description AbstractParentlessTreeNode(boolean useLinkedList)Construct node.AbstractParentlessTreeNode(boolean useLinkedList, boolean copyDataCollection, List<D> idata)Construct node.AbstractParentlessTreeNode(boolean useLinkedList, D idata)Construct node.AbstractParentlessTreeNode(boolean useLinkedList, Collection<D> idata)Construct node.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddTreeNodeListener(TreeNodeListener listener)Add a listener on the node events.voidaddUserData(int index, D data)Add a user data associated to this node.booleanaddUserData(int index, Collection<? extends D> data)Add a user data associated to this node.booleanaddUserData(D data)Add a user data associated to this node.booleanaddUserData(Collection<? extends D> data)Add a user data associated to this node.intcompareTo(N obj)protected voidfirePropertyDataChanged(int delta)Fire the event for the changes of the user data associated to a node.protected voidfirePropertyDataChanged(Collection<? extends D> oldData, Collection<? extends D> newData)Fire the event for the changes of the user data associated to a node.(package private) voidfirePropertyDataChanged(TreeDataEvent event)Fire the event for the changes of the user data associated to a node.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.intgetDeepNodeCount()Replies the count of nodes inside the tree for which the root is this node.intgetDeepUserDataCount()Replies the count of user data inside the tree for which the root is this node.int[]getHeights()Replies the heights of all the leaf nodes.protected abstract voidgetHeights(int currentHeight, List<Integer> heights)Replies the heights of all the leaf nodes.protected List<D>getInternalDataStructureForUserData()Replies the internal data structure which is storing user datas.DgetUserData()Replies the first user data associated to this node.DgetUserDataAt(int index)Replies the user data associated to this node which is at the specified index.intgetUserDataCount()Replies the count of user data associated to this node.booleanisEmpty()Replies if this node is a leaf and has no user data.booleanisValid()Replies if this node is a valid.voidremoveAllUserData()Remove all the user data associated to this node.voidremoveTreeNodeListener(TreeNodeListener listener)Remove a listener on the node events.DremoveUserData(int index)Remove a user data associated to this node.booleanremoveUserData(D data1)Remove a user data associated to this node.booleanremoveUserData(Collection<D> data)Remove a user data associated to this node.booleansetUserData(D data1)Set the user data associated to this node.booleansetUserData(Collection<D> data)Set the user data associated to this node.booleansetUserDataAt(int index, D data)Set the user data associated to this node at the specified index.voidtoJson(JsonBuffer buffer)Replies the Json representation of this node.NtoN()Cast this node to N.StringtoString()-
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, removeFromParent
-
Methods inherited from interface org.arakhne.afc.math.tree.TreeNode
children, clear, getChildren, getChildren, getDepth, getMaxHeight, getMinHeight, getParentNode, getPartitionEnumeration, indexOf, isRoot, moveTo, removeChild, removeDeeplyFromParent, setChildAt
-
-
-
-
Field Detail
-
DEFAULT_LINK_LIST_USE
public static final boolean DEFAULT_LINK_LIST_USE
By default, does tree nodes use a linked list or not.- See Also:
- Constant Field Values
-
DEFAULT_COPY_USER_DATA
public static final boolean DEFAULT_COPY_USER_DATA
By default, does the user data are copied or not.- See Also:
- Constant Field Values
-
nodeListeners
protected transient List<TreeNodeListener> nodeListeners
List of the event listeners on the tree.
-
notNullChildCount
protected int notNullChildCount
Temporary count of child nodes that are not null.- See Also:
IterableNode.getNotNullChildCount()
-
-
Constructor Detail
-
AbstractParentlessTreeNode
public AbstractParentlessTreeNode(boolean useLinkedList)
Construct node.- Parameters:
useLinkedList- indicates if a linked list must be used to store the data. Iffalse, an ArrayList will be used.
-
AbstractParentlessTreeNode
public AbstractParentlessTreeNode(boolean useLinkedList, boolean copyDataCollection, List<D> idata)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 iftrueor the inner data collection will be the given collection itself iffalse.idata- are the initial user data
-
AbstractParentlessTreeNode
public AbstractParentlessTreeNode(boolean useLinkedList, Collection<D> idata)Construct node.- Parameters:
useLinkedList- indicates if a linked list must be used to store the data. Iffalse, an ArrayList will be used.idata- are the initial user data
-
AbstractParentlessTreeNode
public AbstractParentlessTreeNode(boolean useLinkedList, D idata)Construct node.- Parameters:
useLinkedList- indicates if a linked list must be used to store the data. Iffalse, an ArrayList will be used.idata- are the initial user data
-
-
Method Detail
-
toN
@Pure public N toN()
Cast this node to N.- Returns:
this
-
isValid
@Pure public boolean isValid()
Description copied from interface:TreeNodeReplies if this node is a valid. The validity of a node depends of the node implementation.
-
isEmpty
@Pure public boolean isEmpty()
Description copied from interface:TreeNodeReplies if this node is a leaf and has no user data.This function is equivalent to call
IterableNode.isLeaf()&&TreeNode.getUserDataCount()==0
-
toJson
public void toJson(JsonBuffer buffer)
Replies the Json representation of this node.- Specified by:
toJsonin interfaceJsonableObject- Parameters:
buffer- the Json buffer.- Since:
- 14.0
-
getAllUserData
public D[] getAllUserData(D[] array)
Description copied from interface:TreeNodeReplies the all user data associated to this node.- Specified by:
getAllUserDatain interfaceTreeNode<D,N extends AbstractParentlessTreeNode<D,N>>- Parameters:
array- is the array to fill if it has enough cells- Returns:
- the parameter
aif it has enough cells, otherwise another array.
-
getAllUserData
@Pure public List<D> getAllUserData()
Description copied from interface:TreeNodeReplies the all user data associated to this node.- Specified by:
getAllUserDatain interfaceTreeNode<D,N extends AbstractParentlessTreeNode<D,N>>- Returns:
- all the user data
-
getInternalDataStructureForUserData
@Pure protected final List<D> getInternalDataStructureForUserData()
Replies the internal data structure which is storing user datas.Use with caution because any change applied outside
AbstractParentlessTreeNodewill not be taken into account (no event...).- Returns:
- the internal data structure
-
getUserData
@Pure public D getUserData()
Description copied from interface:TreeNodeReplies the first user data associated to this node.- Specified by:
getUserDatain interfaceTreeNode<D,N extends AbstractParentlessTreeNode<D,N>>- Returns:
- first user data
-
getUserDataCount
@Pure public int getUserDataCount()
Description copied from interface:TreeNodeReplies the count of user data associated to this node.- Specified by:
getUserDataCountin interfaceTreeNode<D,N extends AbstractParentlessTreeNode<D,N>>- Returns:
- the count of user data.
-
getUserDataAt
@Pure public D getUserDataAt(int index) throws IndexOutOfBoundsException
Description copied from interface:TreeNodeReplies the user data associated to this node which is at the specified index.- Specified by:
getUserDataAtin interfaceTreeNode<D,N extends AbstractParentlessTreeNode<D,N>>- Parameters:
index- is the position of the data to reply- Returns:
- the user data
- Throws:
IndexOutOfBoundsException- when the given index in not valid
-
addUserData
public boolean addUserData(Collection<? extends D> data)
Description copied from interface:TreeNodeAdd a user data associated to this node.- Specified by:
addUserDatain interfaceTreeNode<D,N extends AbstractParentlessTreeNode<D,N>>- Parameters:
data- the data to add.- Returns:
trueif the the list of user data has changed, otherwisefalse.
-
addUserData
public final boolean addUserData(int index, Collection<? extends D> data)Description copied from interface:TreeNodeAdd a user data associated to this node.- Specified by:
addUserDatain interfaceTreeNode<D,N extends AbstractParentlessTreeNode<D,N>>- Parameters:
index- is the position where to put the elements in the user data list.data- the data to add.- Returns:
trueif the the list of user data has changed, otherwisefalse.
-
addUserData
public final boolean addUserData(D data)
Description copied from interface:TreeNodeAdd a user data associated to this node.- Specified by:
addUserDatain interfaceTreeNode<D,N extends AbstractParentlessTreeNode<D,N>>- Parameters:
data- the data to add.- Returns:
trueif the data was successfully added, otherwhisefalse
-
addUserData
public final void addUserData(int index, D data)Description copied from interface:TreeNodeAdd a user data associated to this node.- Specified by:
addUserDatain interfaceTreeNode<D,N extends AbstractParentlessTreeNode<D,N>>- Parameters:
index- is the position where to insert the data.data- the data to add.
-
removeUserData
public boolean removeUserData(Collection<D> data)
Description copied from interface:TreeNodeRemove a user data associated to this node.- Specified by:
removeUserDatain interfaceTreeNode<D,N extends AbstractParentlessTreeNode<D,N>>- Parameters:
data- the data to remove.- Returns:
trueif the data was successfully removed, otherwhisefalse
-
removeUserData
public final D removeUserData(int index)
Description copied from interface:TreeNodeRemove a user data associated to this node.- Specified by:
removeUserDatain interfaceTreeNode<D,N extends AbstractParentlessTreeNode<D,N>>- Parameters:
index- is the position of the user data to remove.- Returns:
- the removed data or
nullif the data was not removed.
-
removeUserData
public final boolean removeUserData(D data1)
Description copied from interface:TreeNodeRemove a user data associated to this node.- Specified by:
removeUserDatain interfaceTreeNode<D,N extends AbstractParentlessTreeNode<D,N>>- Parameters:
data1- the data to remove.- Returns:
trueif the data was successfully removed, otherwhisefalse
-
removeAllUserData
public void removeAllUserData()
Description copied from interface:TreeNodeRemove all the user data associated to this node.- Specified by:
removeAllUserDatain interfaceTreeNode<D,N extends AbstractParentlessTreeNode<D,N>>
-
setUserData
public boolean setUserData(Collection<D> data)
Description copied from interface:TreeNodeSet the user data associated to this node.- Specified by:
setUserDatain interfaceTreeNode<D,N extends AbstractParentlessTreeNode<D,N>>- Parameters:
data- the data to put inside.- Returns:
trueif the data was successfully set, otherwhisefalse
-
setUserData
public final boolean setUserData(D data1)
Description copied from interface:TreeNodeSet the user data associated to this node.- Specified by:
setUserDatain interfaceTreeNode<D,N extends AbstractParentlessTreeNode<D,N>>- Parameters:
data1- the data to put inside.- Returns:
trueif the data was successfully set, otherwhisefalse
-
setUserDataAt
public boolean setUserDataAt(int index, D data) throws IndexOutOfBoundsExceptionDescription copied from interface:TreeNodeSet the user data associated to this node at the specified index.- Specified by:
setUserDataAtin interfaceTreeNode<D,N extends AbstractParentlessTreeNode<D,N>>- Parameters:
index- the index at which the data must be set.data- the data to put inside.- Returns:
trueif the data was successfully set, otherwhisefalse- Throws:
IndexOutOfBoundsException- if the given index was invalid
-
firePropertyDataChanged
protected final void firePropertyDataChanged(Collection<? extends D> oldData, Collection<? extends D> newData)
Fire the event for the changes of the user data associated to a node.- Parameters:
oldData- is the list of old valuesnewData- is the list of new values
-
firePropertyDataChanged
protected final void firePropertyDataChanged(int delta)
Fire the event for the changes of the user data associated to a node.- Parameters:
delta- is the difference between the size of the data list before change and size after change.
-
firePropertyDataChanged
void firePropertyDataChanged(TreeDataEvent event)
Fire the event for the changes of the user data associated to a node.- Parameters:
event- is the event ot fire.
-
addTreeNodeListener
public final void addTreeNodeListener(TreeNodeListener listener)
Description copied from interface:TreeNodeAdd a listener on the node events.- Specified by:
addTreeNodeListenerin interfaceTreeNode<D,N extends AbstractParentlessTreeNode<D,N>>- Parameters:
listener- the listener.
-
removeTreeNodeListener
public final void removeTreeNodeListener(TreeNodeListener listener)
Description copied from interface:TreeNodeRemove a listener on the node events.- Specified by:
removeTreeNodeListenerin interfaceTreeNode<D,N extends AbstractParentlessTreeNode<D,N>>- Parameters:
listener- the listener.
-
compareTo
@Pure public int compareTo(N obj)
- Specified by:
compareToin interfaceComparable<D>
-
getDeepNodeCount
@Pure public int getDeepNodeCount()
Description copied from interface:TreeNodeReplies the count of nodes inside the tree for which the root is this node.- Specified by:
getDeepNodeCountin interfaceTreeNode<D,N extends AbstractParentlessTreeNode<D,N>>- Returns:
- the count of node inside the subtree.
-
getDeepUserDataCount
@Pure public int getDeepUserDataCount()
Description copied from interface:TreeNodeReplies the count of user data inside the tree for which the root is this node.- Specified by:
getDeepUserDataCountin interfaceTreeNode<D,N extends AbstractParentlessTreeNode<D,N>>- Returns:
- the count of user data inside the subtree.
-
getHeights
@Pure public final int[] getHeights()
Description copied from interface:TreeNodeReplies the heights of all the leaf nodes. The order of the heights is given by a depth-first iteration.- Specified by:
getHeightsin interfaceTreeNode<D,N extends AbstractParentlessTreeNode<D,N>>- Returns:
- the heights of the leaf nodes
-
-