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>
public class Tree extends NestedObject implements Iterable<Tree>
A class for tree (nodes).- See Also:
- Serialized Form
- API:
- This is a public API.
-
-
Constructor Summary
Constructors Constructor Description Tree()Creates a new root tree.Tree(Object aValue)Creates a new root tree with given value.Tree(Object aValue, String anInfo)Creates a new root tree with given value and infoTree(Object aValue, String anInfo, boolean mayHaveChildren)Creates a new root tree with given value and info
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(Tree child)Adds a new child to this tree.voidaddAll(List<Tree> newChildren)Adds a new child to this tree.voidaddAllAt(int index, List<Tree> newChildren)Adds a new child to this tree.voidaddAt(int index, Tree child)Adds a new child to this tree.Treeclone()Clones this tree (shallow copy).TreecreateChild(Object newValue)Adds a child to this node.TreecreateChild(Object newValue, String newInfo)Adds a child to this node.TreecreateChildAt(int index, Object newValue)Inserts a child into the childrenlist of this node.TreecreateChildAt(int index, Object newValue, String newInfo)Inserts a child at the given position into this node.List<Tree>createChildren(List<?> values)Creates and adds new children.List<Tree>createChildren(List<?> values, List<String> infos)Creates and adds new children.List<Tree>createChildren(List<?> values, List<String> infos, List<Boolean> mayHaveChildrenList)Creates and adds new children.List<Tree>createChildren(List<?> values, String _info)Creates and adds new children.List<Tree>createChildrenAt(int index, List<?> values)Creates and adds new children.List<Tree>createChildrenAt(int index, List<?> values, List<String> infos)Creates and adds new children.List<Tree>createChildrenAt(int index, List<?> values, List<String> infos, List<Boolean> mayHaveChildrenList)Creates and adds new children.List<Tree>createChildrenAt(int index, List<?> values, String _info)Creates and adds new children.TreedeepClone()Clones this Tree (deep copy).List<Tree>getAllDeepChildren()Gets all child nodes and child nodes of child nodes ...TreegetChildAfter(Tree aChild)Returns the child in this node's child array that immediately followsaChild, which must be a child of this node.TreegetChildAt(int index)Returns the child with given index.TreegetChildBefore(Tree aChild)Returns the child in this node's child array that immediately precedesaChild, which must be a child of this node.intgetChildCount()Returns the number of children of this node.List<Tree>getChildren()Gets the child nodes of this node.TreegetFirstChild()Returns this node's first child.TreegetFirstLeaf()Finds and returns the first leaf that is a descendant of this node -- either this node or its first child's first leaf.intgetIndex(Tree aChild)Returns the index of the specified child in this node's child array.StringgetInfo()Returns an info String.TreegetLastChild()Returns this node's last child.TreegetLastLeaf()Finds and returns the last leaf that is a descendant of this node -- either this node or its last child's last leaf.TreegetNextNode()Returns the node that follows this node in a preorder traversal of this node's tree.TreegetNextSibling()Returns the next sibling of this node in the parent's children array.TreegetParent()Returns the parent node.List<Tree>getPath()Returns a path for from the root node to this node.TreegetPreviousNode()Returns the node that precedes this node in a preorder traversal of this node's tree.TreegetPreviousSibling()Returns the previous sibling of this node in the parent's children array.TreegetRoot()Returns the root element of this (sub)-tree.ObjectgetValue()intindexOf(Tree child)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 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<Tree>iterator()Creates and returns an iterator that traverses the subtree rooted at this node in preorder.voidremove(Tree aChild)RemovesaChildfrom this node's child array, giving it a null parent.voidremoveAllChildren()Removes all of this node's children, setting their parents to null.TreeremoveChildAt(int index)Removes a child with given index.voidremoveFromParent()Removes the subtree rooted at this node from the tree, giving this node a null parent.voidsetInfo(String newInfo)Sets a new info String.voidsetMayHaveChildren(boolean mayHaveChildren)Sets the flag if this tree node may have children or not.voidsetValue(Object newValue)Sewts the value of the tree node.voidtreeValueChanged()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 Detail
-
Tree
public Tree()
Creates a new root tree.- API:
- This public API is available in IvyScript and Java. It has the visibility NOVICE.
-
Tree
public Tree(Object aValue)
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
public Tree(Object aValue, String anInfo)
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.
-
-
Method Detail
-
getParent
public Tree 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
public Object getValue()
- Returns:
- The value of the tree node.
- API:
- This public API is available in IvyScript and Java. It has the visibility NOVICE.
-
setValue
public void setValue(Object newValue)
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
public String 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
public void setInfo(String newInfo)
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
public Tree getChildAt(int index)
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
public Tree removeChildAt(int index)
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
public void remove(Tree aChild)
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
public List<Tree> createChildren(List<?> values)
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
public List<Tree> createChildren(List<?> values, String _info)
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
public List<Tree> createChildren(List<?> values, List<String> infos)
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
public List<Tree> createChildrenAt(int index, List<?> values)
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
public List<Tree> createChildrenAt(int index, List<?> values, String _info)
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
public List<Tree> createChildrenAt(int index, List<?> values, List<String> infos)
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
public Tree createChild(Object newValue)
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
public Tree createChild(Object newValue, String newInfo)
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
public Tree createChildAt(int index, Object newValue, String newInfo)
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
public Tree createChildAt(int index, Object newValue)
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
public void add(Tree child)
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
public void addAt(int index, Tree child)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
public void addAll(List<Tree> newChildren)
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
public void addAllAt(int index, List<Tree> newChildren)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
public Tree clone()
Clones this tree (shallow copy).- Specified by:
clonein interfaceIIvyDataObject- Overrides:
clonein classNestedObject- Returns:
- A shallow of this object.
- See Also:
Object.clone()- API:
- This public API is available in IvyScript and Java. It has the visibility NOVICE.
-
deepClone
public Tree 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
public int indexOf(Tree child)
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
public List<Tree> 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
public List<Tree> 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
public Tree 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
public List<Tree> 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
public Tree 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
public Tree 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
public Tree 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
public Tree 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
public boolean isNodeSibling(Tree anotherNode)
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
public Tree getChildBefore(Tree aChild)
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
public Tree getChildAfter(Tree aChild)
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
public int getIndex(Tree aChild)
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
public boolean isNodeChild(Tree aNode)
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
public Tree 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
public Tree 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
public Tree 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
public Tree 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
public Iterator<Tree> 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.
-
-