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
ConstructorsConstructorDescriptionTree()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 TypeMethodDescriptionvoidAdds a new child to this tree.voidAdds a new child to this tree.voidAdds a new child to this tree.voidAdds 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 ... of this node.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.intReturns 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.intReturns 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()intReturns the index in this tree of the first occurrence of the specified child element, or -1 if this treet does not contain this child elementbooleanisNodeChild(Tree aNode) Returns true ifaNodeis a child of this node.booleanisNodeSibling(Tree anotherNode) Returns true ifanotherNodeis 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.voidRemovesaChildfrom this node's child array, giving it a null parent.voidRemoves all of this node's children, setting their parents to null.removeChildAt(int index) Removes a child with given index.voidRemoves the subtree rooted at this node from the tree, giving this node a null parent.voidSets a new info String.voidsetMayHaveChildren(boolean mayHaveChildren) Sets the flag if this tree node may have children or not.voidSewts the value of the tree node.voidInforms 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 IvyScript and Java. It has the visibility NOVICE.
-
Tree
Creates a new root tree with given value.- Parameters:
aValue-- API:
- This public API is available in IvyScript and Java. It has the visibility NOVICE.
-
Tree
Creates a new root tree with given value and info- Parameters:
aValue-anInfo-- API:
- This public API is available in IvyScript and Java. It has the visibility NOVICE.
-
Tree
Creates a new root tree with given value and info- Parameters:
aValue-anInfo-mayHaveChildren-- API:
- This public API is available in IvyScript and Java. It has the visibility NOVICE.
-
-
Method Details
-
getParent
Returns the parent node.- Returns:
- the parent node.
- API:
- This public API is available in IvyScript and Java. It has the visibility NOVICE.
-
getValue
- Returns:
- The value of the tree node.
- API:
- This public API is available in IvyScript and Java. It has the visibility NOVICE.
-
setValue
Sewts the value of the tree node.- Parameters:
newValue-- API:
- This public API is available in IvyScript and Java. It has the visibility NOVICE.
-
getInfo
Returns an info String.- Returns:
- an info String.
- API:
- This public API is available in IvyScript and Java. It has the visibility NOVICE.
-
setInfo
Sets a new info String.- Parameters:
newInfo-- API:
- This public API is available in IvyScript and Java. It has the visibility NOVICE.
-
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 IvyScript and Java. It has the visibility NOVICE.
-
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 IvyScript and Java. It has the visibility NOVICE.
-
getChildAt
Returns the child with given index.- Parameters:
index-- Returns:
- The child at the given index or
nullwhen no child at the given index - API:
- This public API is available in IvyScript and Java. It has the visibility NOVICE.
-
removeChildAt
Removes a child with given index.- Parameters:
index-- Returns:
- The removed child.
- API:
- This public API is available in IvyScript and Java. It has the visibility NOVICE.
-
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 IvyScript and Java. It has the visibility NOVICE.
-
remove
RemovesaChildfrom this node's child array, giving it a null parent.- Parameters:
aChild- a child of this node to remove- Throws:
IllegalArgumentException- ifaChildis null or is not a child of this node- API:
- This public API is available in IvyScript and Java. It has the visibility NOVICE.
-
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 IvyScript and Java. It has the visibility NOVICE.
-
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 IvyScript and Java. It has the visibility NOVICE.
-
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 IvyScript and Java. It has the visibility NOVICE.
-
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 IvyScript and Java. It has the visibility NOVICE.
-
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 IvyScript and Java. It has the visibility NOVICE.
-
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 IvyScript and Java. It has the visibility NOVICE.
-
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 IvyScript and Java. It has the visibility NOVICE.
-
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 IvyScript and Java. It has the visibility NOVICE.
-
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 IvyScript and Java. It has the visibility NOVICE.
-
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 IvyScript and Java. It has the visibility NOVICE.
-
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 IvyScript and Java. It has the visibility NOVICE.
-
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 IvyScript and Java. It has the visibility NOVICE.
-
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 IvyScript and Java. It has the visibility NOVICE.
-
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 IvyScript and Java. It has the visibility NOVICE.
-
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 IvyScript and Java. It has the visibility NOVICE.
-
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 IvyScript and Java. It has the visibility NOVICE.
-
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 IvyScript and Java. It has the visibility NOVICE.
-
clone
Clones this tree (shallow copy).- Specified by:
clonein interfaceIIvyDataObject- Overrides:
clonein classNestedObject- Returns:
- A shallow of this object.
- See Also:
- API:
- This public API is available in IvyScript and Java. It has the visibility NOVICE.
-
deepClone
Clones this Tree (deep copy).- Specified by:
deepClonein interfaceIIvyDataObject- Overrides:
deepClonein classNestedObject- Returns:
- A deep of this object.
- API:
- This public API is available in IvyScript and Java. It has the visibility NOVICE.
-
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 IvyScript and Java. It has the visibility NOVICE.
-
getChildren
Gets the child nodes of this node.- Returns:
- a list with child tree nodes
- API:
- This public API is available in IvyScript and Java. It has the visibility NOVICE.
-
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 IvyScript and Java. It has the visibility NOVICE.
-
getRoot
Returns the root element of this (sub)-tree.- Returns:
- the root element
- API:
- This public API is available in IvyScript and Java. It has the visibility NOVICE.
-
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 IvyScript and Java. It has the visibility NOVICE.
-
treeValueChanged
public void treeValueChanged()Informs the listeners that a tree value vas relpaced or changed.- API:
- This public API is available in IvyScript and Java. It has the visibility EXPERT.
-
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 IvyScript and Java. It has the visibility ADVANCED.
-
getPreviousNode
Returns the node that precedes this node in a preorder traversal of this node's tree. Returnsnullif 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 IvyScript and Java. It has the visibility ADVANCED.
-
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 IvyScript and Java. It has the visibility EXPERT.
-
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 IvyScript and Java. It has the visibility EXPERT.
-
isNodeSibling
Returns true ifanotherNodeis a sibling of (has the same parent as) this node. A node is its own sibling. IfanotherNodeis null, returns false.- Parameters:
anotherNode- node to test as sibling of this node- Returns:
- true if
anotherNodeis a sibling of this node - API:
- This public API is available in IvyScript and Java. It has the visibility EXPERT.
-
getChildBefore
Returns the child in this node's child array that immediately precedesaChild, which must be a child of this node. IfaChildis the first child, returns null. This method performs a linear search of this node's children foraChildand 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- ifaChildis null or is not a child of this node- API:
- This public API is available in IvyScript and Java. It has the visibility ADVANCED.
-
getChildAfter
Returns the child in this node's child array that immediately followsaChild, which must be a child of this node. IfaChildis the last child, returns null. This method performs a linear search of this node's children foraChildand 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- ifaChildis null or is not a child of this node- See Also:
-
fChildren
- API:
- This public API is available in IvyScript and Java. It has the visibility ADVANCED.
-
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
-1if the specified node is a not a child of this node - Throws:
IllegalArgumentException- ifaChildis null- API:
- This public API is available in IvyScript and Java. It has the visibility ADVANCED.
-
isNodeChild
Returns true ifaNodeis a child of this node. IfaNodeis null, this method returns false.- Parameters:
aNode- the reference node- Returns:
- true if
aNodeis a child of this node; false ifaNodeis null - API:
- This public API is available in IvyScript and Java. It has the visibility ADVANCED.
-
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 IvyScript and Java. It has the visibility ADVANCED.
-
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 IvyScript and Java. It has the visibility ADVANCED.
-
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 IvyScript and Java. It has the visibility ADVANCED.
-
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 IvyScript and Java. It has the visibility ADVANCED.
-
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 IvyScript and Java. It has the visibility NOVICE.
-