public class Tree extends NestedObject implements Iterable<Tree>
Constructor and 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 info
|
Tree(Object aValue,
String anInfo,
boolean mayHaveChildren)
Creates a new root tree with given value and info
|
Modifier and Type | Method and Description |
---|---|
void |
add(Tree child)
Adds a new child to this tree.
|
void |
addAll(List<Tree> newChildren)
Adds a new child to this tree.
|
void |
addAllAt(int index,
List<Tree> newChildren)
Adds a new child to this tree.
|
void |
addAt(int index,
Tree child)
Adds a new child to this tree.
|
Tree |
clone()
Clones this tree (shallow copy).
|
Tree |
createChild(Object newValue)
Adds a child to this node.
|
Tree |
createChild(Object newValue,
String newInfo)
Adds a child to this node.
|
Tree |
createChildAt(int index,
Object newValue)
Inserts a child into the childrenlist of this node.
|
Tree |
createChildAt(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.
|
Tree |
deepClone()
Clones this Tree (deep copy).
|
List<Tree> |
getAllDeepChildren()
Gets all child nodes and child nodes of child nodes ...
|
Tree |
getChildAfter(Tree aChild)
Returns the child in this node's child array that immediately
follows
aChild , which must be a child of this node. |
Tree |
getChildAt(int index)
Returns the child with given index.
|
Tree |
getChildBefore(Tree aChild)
Returns the child in this node's child array that immediately
precedes
aChild , which must be a child of this node. |
int |
getChildCount()
Returns the number of children of this node.
|
List<Tree> |
getChildren()
Gets the child nodes of this node.
|
Tree |
getFirstChild()
Returns this node's first child.
|
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.
|
int |
getIndex(Tree aChild)
Returns the index of the specified child in this node's child array.
|
String |
getInfo()
Returns an info String.
|
Tree |
getLastChild()
Returns this node's last child.
|
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.
|
Tree |
getNextNode()
Returns the node that follows this node in a preorder traversal of this
node's tree.
|
Tree |
getNextSibling()
Returns the next sibling of this node in the parent's children array.
|
Tree |
getParent()
Returns the parent node.
|
List<Tree> |
getPath()
Returns a path for from the root node to this node.
|
Tree |
getPreviousNode()
Returns the node that precedes this node in a preorder traversal of
this node's tree.
|
Tree |
getPreviousSibling()
Returns the previous sibling of this node in the parent's children
array.
|
Tree |
getRoot()
Returns the root element of this (sub)-tree.
|
Object |
getValue() |
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
|
boolean |
isNodeChild(Tree aNode)
Returns true if
aNode is a child of this node. |
boolean |
isNodeSibling(Tree anotherNode)
Returns true if
anotherNode is 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.
|
void |
remove(Tree aChild)
Removes
aChild from this node's child array, giving it a
null parent. |
void |
removeAllChildren()
Removes all of this node's children, setting their parents to null.
|
Tree |
removeChildAt(int index)
Removes a child with given index.
|
void |
removeFromParent()
Removes the subtree rooted at this node from the tree, giving this
node a null parent.
|
void |
setInfo(String newInfo)
Sets a new info String.
|
void |
setMayHaveChildren(boolean mayHaveChildren)
Sets the flag if this tree node may have children or not.
|
void |
setValue(Object newValue)
Sewts the value of the tree node.
|
void |
treeValueChanged()
Informs the listeners that a tree value vas relpaced or changed.
|
equals, hashCode, toString
public Tree()
public Tree(Object aValue)
aValue
- public Tree(Object aValue, String anInfo)
aValue
- anInfo
- public Tree getParent()
public Object getValue()
public void setValue(Object newValue)
newValue
- public String getInfo()
public void setInfo(String newInfo)
newInfo
- public void setMayHaveChildren(boolean mayHaveChildren)
mayHaveChildren
- true if this node may have children, false if this
node doesn't have any children.public int getChildCount()
public Tree getChildAt(int index)
index
- null
when no child at the given indexpublic Tree removeChildAt(int index)
index
- public void removeFromParent()
public void remove(Tree aChild)
aChild
from this node's child array, giving it a
null parent.aChild
- a child of this node to removeIllegalArgumentException
- if aChild
is null or is not a child of this nodepublic void removeAllChildren()
public List<Tree> createChildren(List<?> values)
values
- a list of values for new children.public List<Tree> createChildren(List<?> values, String _info)
values
- a list of values for new children._info
- the info of the new children.public List<Tree> createChildren(List<?> values, List<String> infos)
values
- a list of values for new children.infos
- the infos of the new children.public List<Tree> createChildren(List<?> values, List<String> infos, List<Boolean> mayHaveChildrenList)
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.public List<Tree> createChildrenAt(int index, List<?> values)
index
- Where to insert.values
- a list of values for new children.public List<Tree> createChildrenAt(int index, List<?> values, String _info)
index
- Where to insert.values
- a list of values for new children._info
- the info of the new children.public List<Tree> createChildrenAt(int index, List<?> values, List<String> infos)
index
- Where to insert.values
- a list of values for new children.infos
- the infos of the new children.public List<Tree> createChildrenAt(int index, List<?> values, List<String> infos, List<Boolean> mayHaveChildrenList)
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.public Tree createChild(Object newValue)
newValue
- The value of the new child.public Tree createChild(Object newValue, String newInfo)
newValue
- The value of the new child.newInfo
- the info of the new childpublic Tree createChildAt(int index, Object newValue, String newInfo)
index
- The index of the new childnewValue
- The value of the new child.newInfo
- The info of the new childpublic Tree createChildAt(int index, Object newValue)
index
- The index of the new childnewValue
- The value of the new child.public void add(Tree child)
child
- A new child; if the parent of child is not null,
this argument is cloned.public void addAt(int index, Tree child)
index
- child
- A new child; if the parent of child is not null,
this argument is cloned.public void addAll(List<Tree> newChildren)
newChildren
- A list of new children;
if the parent of a child is not null,
the child is cloned.public void addAllAt(int index, List<Tree> newChildren)
index
- Where to insertnewChildren
- A list of new children;
if the parent of a child is not null,
the child is cloned.public Tree clone()
clone
in interface IIvyDataObject
clone
in class NestedObject
Object.clone()
public Tree deepClone()
deepClone
in interface IIvyDataObject
deepClone
in class NestedObject
public int indexOf(Tree child)
child
- the child node to searchpublic List<Tree> getChildren()
public List<Tree> getAllDeepChildren()
public Tree getRoot()
public List<Tree> getPath()
public void treeValueChanged()
public Tree getNextNode()
public Tree getPreviousNode()
null
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.public Tree getNextSibling()
Tree.fChildren
public Tree getPreviousSibling()
public boolean isNodeSibling(Tree anotherNode)
anotherNode
is a sibling of (has the
same parent as) this node. A node is its own sibling. If
anotherNode
is null, returns false.anotherNode
- node to test as sibling of this nodeanotherNode
is a sibling of this nodepublic Tree getChildBefore(Tree aChild)
aChild
, which must be a child of this node. If
aChild
is the first child, returns null. This method
performs a linear search of this node's children for aChild
and is O(n) where n is the number of children.aChild
- the reference childaChild
IllegalArgumentException
- if aChild
is null
or is not a child of this nodepublic Tree getChildAfter(Tree aChild)
aChild
, which must be a child of this node. If
aChild
is the last child, returns null. This method
performs a linear search of this node's children for
aChild
and is O(n) where n is the number of children; to
traverse the entire array of children, use an enumeration instead.aChild
- the reference childaChild
IllegalArgumentException
- if aChild
is
null or is not a child of this nodeTree.fChildren
public int getIndex(Tree aChild)
-1
. This method performs a linear search and is O(n)
where n is the number of children.aChild
- the TreeNode to search for among this node's children-1
if the specified node is a not
a child of this nodeIllegalArgumentException
- if aChild
is nullpublic boolean isNodeChild(Tree aNode)
aNode
is a child of this node. If
aNode
is null, this method returns false.aNode
- the reference nodeaNode
is a child of this node; false if
aNode
is nullpublic Tree getFirstLeaf()
Tree.isLeaf()
public Tree getLastLeaf()
Tree.isLeaf()
public Tree getFirstChild()
public Tree getLastChild()
public Iterator<Tree> iterator()
nextElement()
method is this node.Modifying the tree by inserting, removing, or moving a node invalidates any enumerations created before the modification.
Copyright © 2024
AXON IVY AG
All Rights Reserved Documentation was generated
on April 28, 2024