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 boolean
DEFAULT_COPY_USER_DATA
By default, does the user data are copied or not.static boolean
DEFAULT_LINK_LIST_USE
By default, does tree nodes use a linked list or not.protected List<TreeNodeListener>
nodeListeners
List of the event listeners on the tree.protected int
notNullChildCount
Temporary 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 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.int
compareTo(N obj)
protected void
firePropertyDataChanged(int delta)
Fire the event for the changes of the user data associated to a node.protected void
firePropertyDataChanged(Collection<? extends D> oldData, Collection<? extends D> newData)
Fire the event for the changes of the user data associated to a node.(package private) void
firePropertyDataChanged(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.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[]
getHeights()
Replies the heights of all the leaf nodes.protected abstract void
getHeights(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.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.boolean
isEmpty()
Replies if this node is a leaf and has no user data.boolean
isValid()
Replies if this node is a valid.void
removeAllUserData()
Remove all the user data associated to this node.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 data1)
Remove a user data associated to this node.boolean
removeUserData(Collection<D> data)
Remove a user data associated to this node.boolean
setUserData(D data1)
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.void
toJson(JsonBuffer buffer)
Replies the Json representation of this node.N
toN()
Cast this node to N.String
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, 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 iftrue
or 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:TreeNode
Replies 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:TreeNode
Replies 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:
toJson
in interfaceJsonableObject
- Parameters:
buffer
- the Json buffer.- Since:
- 14.0
-
getAllUserData
public D[] getAllUserData(D[] array)
Description copied from interface:TreeNode
Replies the all user data associated to this node.- Specified by:
getAllUserData
in interfaceTreeNode<D,N extends AbstractParentlessTreeNode<D,N>>
- 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 public List<D> getAllUserData()
Description copied from interface:TreeNode
Replies the all user data associated to this node.- Specified by:
getAllUserData
in 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
AbstractParentlessTreeNode
will not be taken into account (no event...).- Returns:
- the internal data structure
-
getUserData
@Pure public D getUserData()
Description copied from interface:TreeNode
Replies the first user data associated to this node.- Specified by:
getUserData
in interfaceTreeNode<D,N extends AbstractParentlessTreeNode<D,N>>
- Returns:
- first user data
-
getUserDataCount
@Pure public int getUserDataCount()
Description copied from interface:TreeNode
Replies the count of user data associated to this node.- Specified by:
getUserDataCount
in 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:TreeNode
Replies the user data associated to this node which is at the specified index.- Specified by:
getUserDataAt
in 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:TreeNode
Add a user data associated to this node.- Specified by:
addUserData
in interfaceTreeNode<D,N extends AbstractParentlessTreeNode<D,N>>
- Parameters:
data
- the data to add.- Returns:
true
if the the list of user data has changed, otherwisefalse
.
-
addUserData
public final boolean addUserData(int index, Collection<? extends D> data)
Description copied from interface:TreeNode
Add a user data associated to this node.- Specified by:
addUserData
in 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:
true
if the the list of user data has changed, otherwisefalse
.
-
addUserData
public final boolean addUserData(D data)
Description copied from interface:TreeNode
Add a user data associated to this node.- Specified by:
addUserData
in interfaceTreeNode<D,N extends AbstractParentlessTreeNode<D,N>>
- Parameters:
data
- the data to add.- Returns:
true
if the data was successfully added, otherwhisefalse
-
addUserData
public final void addUserData(int index, D data)
Description copied from interface:TreeNode
Add a user data associated to this node.- Specified by:
addUserData
in 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:TreeNode
Remove a user data associated to this node.- Specified by:
removeUserData
in interfaceTreeNode<D,N extends AbstractParentlessTreeNode<D,N>>
- Parameters:
data
- the data to remove.- Returns:
true
if the data was successfully removed, otherwhisefalse
-
removeUserData
public final D removeUserData(int index)
Description copied from interface:TreeNode
Remove a user data associated to this node.- Specified by:
removeUserData
in interfaceTreeNode<D,N extends AbstractParentlessTreeNode<D,N>>
- Parameters:
index
- is the position of the user data to remove.- Returns:
- the removed data or
null
if the data was not removed.
-
removeUserData
public final boolean removeUserData(D data1)
Description copied from interface:TreeNode
Remove a user data associated to this node.- Specified by:
removeUserData
in interfaceTreeNode<D,N extends AbstractParentlessTreeNode<D,N>>
- Parameters:
data1
- the data to remove.- Returns:
true
if the data was successfully removed, otherwhisefalse
-
removeAllUserData
public void removeAllUserData()
Description copied from interface:TreeNode
Remove all the user data associated to this node.- Specified by:
removeAllUserData
in interfaceTreeNode<D,N extends AbstractParentlessTreeNode<D,N>>
-
setUserData
public boolean setUserData(Collection<D> data)
Description copied from interface:TreeNode
Set the user data associated to this node.- Specified by:
setUserData
in interfaceTreeNode<D,N extends AbstractParentlessTreeNode<D,N>>
- Parameters:
data
- the data to put inside.- Returns:
true
if the data was successfully set, otherwhisefalse
-
setUserData
public final boolean setUserData(D data1)
Description copied from interface:TreeNode
Set the user data associated to this node.- Specified by:
setUserData
in interfaceTreeNode<D,N extends AbstractParentlessTreeNode<D,N>>
- Parameters:
data1
- the data to put inside.- Returns:
true
if the data was successfully set, otherwhisefalse
-
setUserDataAt
public boolean setUserDataAt(int index, D data) throws IndexOutOfBoundsException
Description copied from interface:TreeNode
Set the user data associated to this node at the specified index.- Specified by:
setUserDataAt
in 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:
true
if 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:TreeNode
Add a listener on the node events.- Specified by:
addTreeNodeListener
in interfaceTreeNode<D,N extends AbstractParentlessTreeNode<D,N>>
- Parameters:
listener
- the listener.
-
removeTreeNodeListener
public final void removeTreeNodeListener(TreeNodeListener listener)
Description copied from interface:TreeNode
Remove a listener on the node events.- Specified by:
removeTreeNodeListener
in interfaceTreeNode<D,N extends AbstractParentlessTreeNode<D,N>>
- Parameters:
listener
- the listener.
-
compareTo
@Pure public int compareTo(N obj)
- Specified by:
compareTo
in interfaceComparable<D>
-
getDeepNodeCount
@Pure public int getDeepNodeCount()
Description copied from interface:TreeNode
Replies the count of nodes inside the tree for which the root is this node.- Specified by:
getDeepNodeCount
in interfaceTreeNode<D,N extends AbstractParentlessTreeNode<D,N>>
- Returns:
- the count of node inside the subtree.
-
getDeepUserDataCount
@Pure public int getDeepUserDataCount()
Description copied from interface:TreeNode
Replies the count of user data inside the tree for which the root is this node.- Specified by:
getDeepUserDataCount
in 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:TreeNode
Replies the heights of all the leaf nodes. The order of the heights is given by a depth-first iteration.- Specified by:
getHeights
in interfaceTreeNode<D,N extends AbstractParentlessTreeNode<D,N>>
- Returns:
- the heights of the leaf nodes
-
-