Package ch.ivyteam.ivy.scripting.objects
Class Tree
java.lang.Object
ch.ivyteam.ivy.scripting.objects.NestedObject
ch.ivyteam.ivy.scripting.objects.Tree
- All Implemented Interfaces:
IIvyDataObject
,Serializable
,Cloneable
,Iterable<Tree>
A class for tree (nodes).
- See Also:
- API:
- This is a public API.
-
Constructor Summary
ConstructorDescriptionTree()
Creates a new root tree.Creates a new root tree with given value.Creates a new root tree with given value and infoCreates a new root tree with given value and info -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a new child to this tree.void
Adds a new child to this tree.void
Adds a new child to this tree.void
Adds a new child to this tree.clone()
Clones this tree (shallow copy).createChild
(Object newValue) Adds a child to this node.createChild
(Object newValue, String newInfo) Adds a child to this node.createChildAt
(int index, Object newValue) Inserts a child into the childrenlist of this node.createChildAt
(int index, Object newValue, String newInfo) Inserts a child at the given position into this node.createChildren
(List<?> values) Creates and adds new children.createChildren
(List<?> values, List<String> infos) Creates and adds new children.Creates and adds new children.createChildren
(List<?> values, String _info) Creates and adds new children.createChildrenAt
(int index, List<?> values) Creates and adds new children.createChildrenAt
(int index, List<?> values, List<String> infos) Creates and adds new children.Creates and adds new children.createChildrenAt
(int index, List<?> values, String _info) Creates and adds new children.Clones this Tree (deep copy).Gets all child nodes and child nodes of child nodes ...getChildAfter
(Tree aChild) Returns the child in this node's child array that immediately followsaChild
, which must be a child of this node.getChildAt
(int index) Returns the child with given index.getChildBefore
(Tree aChild) Returns the child in this node's child array that immediately precedesaChild
, which must be a child of this node.int
Returns the number of children of this node.Gets the child nodes of this node.Returns this node's first child.Finds and returns the first leaf that is a descendant of this node -- either this node or its first child's first leaf.int
Returns the index of the specified child in this node's child array.getInfo()
Returns an info String.Returns this node's last child.Finds and returns the last leaf that is a descendant of this node -- either this node or its last child's last leaf.Returns the node that follows this node in a preorder traversal of this node's tree.Returns the next sibling of this node in the parent's children array.Returns the parent node.getPath()
Returns a path for from the root node to this node.Returns the node that precedes this node in a preorder traversal of this node's tree.Returns the previous sibling of this node in the parent's children array.getRoot()
Returns the root element of this (sub)-tree.getValue()
int
Returns the index in this tree of the first occurrence of the specified child element, or -1 if this treet does not contain this child elementboolean
isNodeChild
(Tree aNode) Returns true ifaNode
is a child of this node.boolean
isNodeSibling
(Tree anotherNode) Returns true ifanotherNode
is a sibling of (has the same parent as) this node.iterator()
Creates and returns an iterator that traverses the subtree rooted at this node in preorder.void
RemovesaChild
from this node's child array, giving it a null parent.void
Removes all of this node's children, setting their parents to null.removeChildAt
(int index) Removes a child with given index.void
Removes the subtree rooted at this node from the tree, giving this node a null parent.void
Sets a new info String.void
setMayHaveChildren
(boolean mayHaveChildren) Sets the flag if this tree node may have children or not.void
Sewts the value of the tree node.void
Informs the listeners that a tree value vas relpaced or changed.Methods inherited from class ch.ivyteam.ivy.scripting.objects.NestedObject
equals, hashCode, toString
-
Constructor Details
-
Tree
public Tree()Creates a new root tree.- API:
- This public API is available in Java.
-
Tree
Creates a new root tree with given value.- Parameters:
aValue
-- API:
- This public API is available in Java.
-
Tree
Creates a new root tree with given value and info- Parameters:
aValue
-anInfo
-- API:
- This public API is available in Java.
-
Tree
Creates a new root tree with given value and info- Parameters:
aValue
-anInfo
-mayHaveChildren
-- API:
- This public API is available in Java.
-
-
Method Details
-
getParent
Returns the parent node.- Returns:
- the parent node.
- API:
- This public API is available in Java.
-
getValue
- Returns:
- The value of the tree node.
- API:
- This public API is available in Java.
-
setValue
Sewts the value of the tree node.- Parameters:
newValue
-- API:
- This public API is available in Java.
-
getInfo
Returns an info String.- Returns:
- an info String.
- API:
- This public API is available in Java.
-
setInfo
Sets a new info String.- Parameters:
newInfo
-- API:
- This public API is available in Java.
-
setMayHaveChildren
public void setMayHaveChildren(boolean mayHaveChildren) Sets the flag if this tree node may have children or not.- Parameters:
mayHaveChildren
- true if this node may have children, false if this node doesn't have any children.- API:
- This public API is available in Java.
-
getChildCount
public int getChildCount()Returns the number of children of this node.- Returns:
- the number of children of this node.
- API:
- This public API is available in Java.
-
getChildAt
Returns the child with given index.- Parameters:
index
-- Returns:
- The child at the given index or
null
when no child at the given index - API:
- This public API is available in Java.
-
removeChildAt
Removes a child with given index.- Parameters:
index
-- Returns:
- The removed child.
- API:
- This public API is available in Java.
-
removeFromParent
public void removeFromParent()Removes the subtree rooted at this node from the tree, giving this node a null parent. Does nothing if this node is the root of its tree.- API:
- This public API is available in Java.
-
remove
RemovesaChild
from this node's child array, giving it a null parent.- Parameters:
aChild
- a child of this node to remove- Throws:
IllegalArgumentException
- ifaChild
is null or is not a child of this node- API:
- This public API is available in Java.
-
removeAllChildren
public void removeAllChildren()Removes all of this node's children, setting their parents to null. If this node has no children, this method does nothing.- API:
- This public API is available in Java.
-
createChildren
Creates and adds new children.- Parameters:
values
- a list of values for new children.- Returns:
- A list with new Children.
- API:
- This public API is available in Java.
-
createChildren
Creates and adds new children.- Parameters:
values
- a list of values for new children._info
- the info of the new children.- Returns:
- A list with the new children.
- API:
- This public API is available in Java.
-
createChildren
Creates and adds new children.- Parameters:
values
- a list of values for new children.infos
- the infos of the new children.- Returns:
- A list with the new children.
- API:
- This public API is available in Java.
-
createChildren
public List<Tree> createChildren(List<?> values, List<String> infos, List<Boolean> mayHaveChildrenList) Creates and adds new children.- Parameters:
values
- a list of values for new children.infos
- the infos of the new children.mayHaveChildrenList
- a list of flags indicateing if the associated tree node could have children.- Returns:
- A list with the new children.
- API:
- This public API is available in Java.
-
createChildrenAt
Creates and adds new children.- Parameters:
index
- Where to insert.values
- a list of values for new children.- Returns:
- A list with new Children.
- API:
- This public API is available in Java.
-
createChildrenAt
Creates and adds new children.- Parameters:
index
- Where to insert.values
- a list of values for new children._info
- the info of the new children.- Returns:
- A list with the new children.
- API:
- This public API is available in Java.
-
createChildrenAt
Creates and adds new children.- Parameters:
index
- Where to insert.values
- a list of values for new children.infos
- the infos of the new children.- Returns:
- A list with the new children.
- API:
- This public API is available in Java.
-
createChildrenAt
public List<Tree> createChildrenAt(int index, List<?> values, List<String> infos, List<Boolean> mayHaveChildrenList) Creates and adds new children.- Parameters:
index
- Where to insert.values
- a list of values for new children.infos
- the infos of the new children.mayHaveChildrenList
- a list of flags indicateing if the associated tree node could have children. Can be null.- Returns:
- A list with the new children.
- API:
- This public API is available in Java.
-
createChild
Adds a child to this node.- Parameters:
newValue
- The value of the new child.- Returns:
- The new child.
- API:
- This public API is available in Java.
-
createChild
Adds a child to this node.- Parameters:
newValue
- The value of the new child.newInfo
- the info of the new child- Returns:
- The new child.
- API:
- This public API is available in Java.
-
createChildAt
Inserts a child at the given position into this node. If the index is smaller than zero, the the new child is added at the beginning of the list. If the index is equal or bigger than the number of already existing children, the new child is inserted at the end.- Parameters:
index
- The index of the new childnewValue
- The value of the new child.newInfo
- The info of the new child- Returns:
- The new child; never null
- API:
- This public API is available in Java.
-
createChildAt
Inserts a child into the childrenlist of this node.- Parameters:
index
- The index of the new childnewValue
- The value of the new child.- Returns:
- The new child.
- API:
- This public API is available in Java.
-
add
Adds a new child to this tree.- Parameters:
child
- A new child; if the parent of child is not null, this argument is cloned.- API:
- This public API is available in Java.
-
addAt
Adds a new child to this tree.- Parameters:
index
-child
- A new child; if the parent of child is not null, this argument is cloned.- API:
- This public API is available in Java.
-
addAll
Adds a new child to this tree.- Parameters:
newChildren
- A list of new children; if the parent of a child is not null, the child is cloned.- API:
- This public API is available in Java.
-
addAllAt
Adds a new child to this tree.- Parameters:
index
- Where to insertnewChildren
- A list of new children; if the parent of a child is not null, the child is cloned.- API:
- This public API is available in Java.
-
clone
Clones this tree (shallow copy).- Specified by:
clone
in interfaceIIvyDataObject
- Overrides:
clone
in classNestedObject
- Returns:
- A shallow of this object.
- See Also:
- API:
- This public API is available in Java.
-
deepClone
Clones this Tree (deep copy).- Specified by:
deepClone
in interfaceIIvyDataObject
- Overrides:
deepClone
in classNestedObject
- Returns:
- A deep of this object.
- API:
- This public API is available in Java.
-
indexOf
Returns the index in this tree of the first occurrence of the specified child element, or -1 if this treet does not contain this child element- Parameters:
child
- the child node to search- Returns:
- index of the first occurence or -1 if not found
- API:
- This public API is available in Java.
-
getChildren
Gets the child nodes of this node.- Returns:
- a list with child tree nodes
- API:
- This public API is available in Java.
-
getAllDeepChildren
Gets all child nodes and child nodes of child nodes ... of this node. All nodes are returned that have this node as ancestor.- Returns:
- list with all child tree nodes.
- API:
- This public API is available in Java.
-
getRoot
Returns the root element of this (sub)-tree.- Returns:
- the root element
- API:
- This public API is available in Java.
-
getPath
Returns a path for from the root node to this node.- Returns:
- a path for from the root node to this node.
- API:
- This public API is available in Java.
-
treeValueChanged
public void treeValueChanged()Informs the listeners that a tree value vas relpaced or changed.- API:
- This public API is available in Java.
-
getNextNode
Returns the node that follows this node in a preorder traversal of this node's tree. Returns null if this node is the last node of the traversal. This is an inefficient way to traverse the entire tree; use an enumeration, instead.- Returns:
- the node that follows this node in a preorder traversal, or null if this node is last
- API:
- This public API is available in Java.
-
getPreviousNode
Returns the node that precedes this node in a preorder traversal of this node's tree. Returnsnull
if this node is the first node of the traversal -- the root of the tree. This is an inefficient way to traverse the entire tree; use an enumeration, instead.- Returns:
- the node that precedes this node in a preorder traversal, or null if this node is the first
- API:
- This public API is available in Java.
-
getNextSibling
Returns the next sibling of this node in the parent's children array. Returns null if this node has no parent or is the parent's last child. This method performs a linear search that is O(n) where n is the number of children; to traverse the entire array, use the parent's child enumeration instead.- Returns:
- the sibling of this node that immediately follows this node
- See Also:
-
fChildren
- API:
- This public API is available in Java.
-
getPreviousSibling
Returns the previous sibling of this node in the parent's children array. Returns null if this node has no parent or is the parent's first child. This method performs a linear search that is O(n) where n is the number of children.- Returns:
- the sibling of this node that immediately precedes this node
- API:
- This public API is available in Java.
-
isNodeSibling
Returns true ifanotherNode
is a sibling of (has the same parent as) this node. A node is its own sibling. IfanotherNode
is null, returns false.- Parameters:
anotherNode
- node to test as sibling of this node- Returns:
- true if
anotherNode
is a sibling of this node - API:
- This public API is available in Java.
-
getChildBefore
Returns the child in this node's child array that immediately precedesaChild
, which must be a child of this node. IfaChild
is the first child, returns null. This method performs a linear search of this node's children foraChild
and is O(n) where n is the number of children.- Parameters:
aChild
- the reference child- Returns:
- the child of this node that immediately precedes
aChild
- Throws:
IllegalArgumentException
- ifaChild
is null or is not a child of this node- API:
- This public API is available in Java.
-
getChildAfter
Returns the child in this node's child array that immediately followsaChild
, which must be a child of this node. IfaChild
is the last child, returns null. This method performs a linear search of this node's children foraChild
and is O(n) where n is the number of children; to traverse the entire array of children, use an enumeration instead.- Parameters:
aChild
- the reference child- Returns:
- the child of this node that immediately follows
aChild
- Throws:
IllegalArgumentException
- ifaChild
is null or is not a child of this node- See Also:
-
fChildren
- API:
- This public API is available in Java.
-
getIndex
Returns the index of the specified child in this node's child array. If the specified node is not a child of this node, returns-1
. This method performs a linear search and is O(n) where n is the number of children.- Parameters:
aChild
- the TreeNode to search for among this node's children- Returns:
- an int giving the index of the node in this node's child
array, or
-1
if the specified node is a not a child of this node - Throws:
IllegalArgumentException
- ifaChild
is null- API:
- This public API is available in Java.
-
isNodeChild
Returns true ifaNode
is a child of this node. IfaNode
is null, this method returns false.- Parameters:
aNode
- the reference node- Returns:
- true if
aNode
is a child of this node; false ifaNode
is null - API:
- This public API is available in Java.
-
getFirstLeaf
Finds and returns the first leaf that is a descendant of this node -- either this node or its first child's first leaf. Returns this node if it is a leaf.- Returns:
- the first leaf in the subtree rooted at this node
- See Also:
-
isLeaf()
- API:
- This public API is available in Java.
-
getLastLeaf
Finds and returns the last leaf that is a descendant of this node -- either this node or its last child's last leaf. Returns this node if it is a leaf.- Returns:
- the last leaf in the subtree rooted at this node
- See Also:
-
isLeaf()
- API:
- This public API is available in Java.
-
getFirstChild
Returns this node's first child. If this node has no children, it returns null.- Returns:
- the first child of this node, or null if the node doesn't have any child.
- API:
- This public API is available in Java.
-
getLastChild
Returns this node's last child. If this node has no children, it returns null.- Returns:
- the last child of this node or null if the node has no children.
- API:
- This public API is available in Java.
-
iterator
Creates and returns an iterator that traverses the subtree rooted at this node in preorder. The first node returned by the enumeration'snextElement()
method is this node.Modifying the tree by inserting, removing, or moving a node invalidates any enumerations created before the modification.
- Returns:
- the iterator
- API:
- This public API is available in Java.
-