E
- the type of elements in this treepublic class OrderedTree<E> extends AbstractTree<E>
PAREN_END, PAREN_START
Constructor and Description |
---|
OrderedTree()
Public constructor.
|
OrderedTree(E element)
Public constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
add(OrderedTree<E> child)
Adds the given child to this node.
|
void |
addChild(E element)
Adds a child with the given element to this node.
|
void |
addChild(OrderedTree<E> child)
Adds the given child to this node.
|
BinaryTree<E> |
binarize()
Converts this ordered tree to a binary tree.
|
boolean |
equals(java.lang.Object obj)
Returns
true if this tree is equal to the given object. |
OrderedTree<E> |
find(E element)
Finds a node of the first occurrence of the given element in this tree.
|
OrderedTree<E> |
findChild(E element)
Finds a child of the first occurrence of the given element in this node.
|
java.util.List<E> |
getAncestorElements()
Returns a list of elements of ancestors of this node, ordered from the root to the parent of
this node.
|
java.util.List<OrderedTree<E>> |
getAncestors()
Returns a list of ancestors of this node, ordered from the root to the parent of this node.
|
OrderedTree<E> |
getChildAt(int index)
Returns the child of this node at the given index.
|
java.util.List<OrderedTree<E>> |
getChildren()
Returns a list of children of this node.
|
java.util.List<E> |
getElements()
Returns a list of all elements in this tree.
|
OrderedTree<E> |
getFirstChild()
Returns the first child of this node.
|
OrderedTree<E> |
getLastChild()
Returns the last child of this node.
|
java.util.List<OrderedTree<E>> |
getLeaves()
Returns a list of leaves in this tree in a natural order.
|
java.util.List<Tree<E>> |
getNodes()
Returns a list of all nodes of the type
Tree<E> in this tree. |
java.util.List<OrderedTree<E>> |
getOrderedTreeNodes()
Returns a list of all nodes of the type
OrderedTree<E> in this tree. |
OrderedTree<E> |
getParent()
Returns the parent of this node.
|
OrderedTree<E> |
getRoot()
Returns the root of this tree.
|
java.util.List<E> |
getSiblingElements()
Returns a list of elements of siblings of this node.
|
java.util.List<OrderedTree<E>> |
getSiblings()
Returns a list of siblings of this node.
|
java.util.List<OrderedTree<E>> |
getSubtrees()
Returns a list of subtrees of this tree.
|
boolean |
hasChild(E element)
Returns
true if this node has a child with the given element. |
boolean |
hasChild(OrderedTree<E> child)
Returns
true if this node has the given child. |
int |
hashCode()
Returns the hash code value for this tree.
|
boolean |
isFirstChild(OrderedTree<E> node)
Returns
true if the first child of this node is the given node. |
boolean |
isLastChild(OrderedTree<E> node)
Returns
true if the last child of this node is the given node. |
int |
numChildren()
Returns the number of children of this node.
|
int |
numSiblings()
Returns the number of siblings of this node.
|
void |
remove()
Removes this node.
|
void |
removeChild(E element)
Removes a child with the given element from this node.
|
void |
removeChild(OrderedTree<E> child)
Removes the given child from this node.
|
void |
removeChildAt(int index)
Removes a child at the given index from this node.
|
void |
removeChildren()
Removes all children from this node.
|
void |
setChildAt(int index,
OrderedTree<E> child)
Sets the given child to this node at the given index.
|
void |
setParent(OrderedTree<E> parent)
Sets the given parent to this node.
|
boolean |
subsumes(OrderedTree<E> tree)
Returns
true if the given tree matches this tree or a subtree of the tree. |
java.lang.String |
toNewick()
Returns a string representation of this tree in the Newick standard format.
|
java.lang.String |
toNewick(java.lang.String startMark,
java.lang.String endMark)
Returns a string representation of this tree in the Newick standard format with the given
starting and ending mark.
|
java.lang.String |
toString()
Returns a string representation of this tree in the format of the UNIX 'tree' command.
|
java.util.List<E> |
traverse()
Traverses this tree, and returns a list of found elements in this tree.
|
java.util.List<E> |
traverseLevelOrder()
Traverses this tree in the level-order manner, which is breadth-first search (BFS), and returns
a list of found elements.
|
java.util.List<OrderedTree<E>> |
traverseNodes()
Traverses this tree, and returns a list of found nodes in this tree.
|
java.util.List<OrderedTree<E>> |
traverseNodesLevelOrder()
Traverses this tree in the level-order manner, which is breadth-first search (BFS), and returns
a list of found nodes.
|
java.util.List<OrderedTree<E>> |
traverseNodesPostOrder()
Traverses this tree in the post-order manner, which is one way of depth-first search (DFS), and
returns a list of found nodes.
|
java.util.List<OrderedTree<E>> |
traverseNodesPreOrder()
Traverses this tree in the pre-order manner, which is one way of depth-first search (DFS), and
returns a list of found nodes.
|
java.util.List<E> |
traversePostOrder()
Traverses this tree in the post-order manner, which is one way of depth-first search (DFS), and
returns a list of found elements.
|
java.util.List<E> |
traversePreOrder()
Traverses this tree in the pre-order manner, which is one way of depth-first search (DFS), and
returns a list of found elements.
|
add, degree, degree, depth, depth, getElement, getLeafElements, hasAncestor, hasAncestor, hasChild, hasDescendant, hasDescendant, hasElement, hasElement, hasParent, hasParent, hasParent, isBalanced, isLabeled, isLabeledTree, isLeaf, isRoot, iterator, numLeaves, removeChildren, setElement, size, yield
addAll, clear, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray
public OrderedTree()
public OrderedTree(E element)
element
- an element of this nodepublic boolean equals(java.lang.Object obj)
true
if this tree is equal to the given object. Two ordered trees are equal if
they have the same elements in the same tree structure.public int hashCode()
public java.lang.String toString()
toString
in class java.util.AbstractCollection<E>
public java.lang.String toNewick()
public java.lang.String toNewick(java.lang.String startMark, java.lang.String endMark)
startMark
- a string to start with a string presentation of a nodeendMark
- a string to end with a string presentation of a nodepublic OrderedTree<E> find(E element)
element
- an element to be found in this tree, if presentpublic OrderedTree<E> findChild(E element)
element
- an element to be found in the children of this node, if presentpublic OrderedTree<E> getParent()
public void setParent(OrderedTree<E> parent)
parent
- a parent that will be set to this nodepublic OrderedTree<E> getChildAt(int index)
index
- an index of the element to returnpublic java.util.List<OrderedTree<E>> getChildren()
public int numChildren()
public boolean hasChild(E element)
true
if this node has a child with the given element.element
- an element whose presence in the children of this node will be testedtrue
if this node has a child with the given element; false
otherwisepublic boolean hasChild(OrderedTree<E> child)
true
if this node has the given child.child
- a node whose presence in the children of this node will be testedtrue
if this node has the given child; false
otherwisepublic OrderedTree<E> getFirstChild()
public boolean isFirstChild(OrderedTree<E> node)
true
if the first child of this node is the given node.node
- a node whose presence as the first child will be testedtrue
if the first child of this node is the given node; false
otherwisepublic OrderedTree<E> getLastChild()
public boolean isLastChild(OrderedTree<E> node)
true
if the last child of this node is the given node.node
- a node whose presence as the last child will be testedtrue
if the last child of this node is the given node; false
otherwisepublic void setChildAt(int index, OrderedTree<E> child)
index
- an index of the element to setchild
- a child that will be set to this nodepublic void add(OrderedTree<E> child)
child
- a child that will be added to this nodepublic void addChild(OrderedTree<E> child)
child
- a child that will be added to this nodepublic void addChild(E element)
element
- an element that will be added to the children of this nodepublic java.util.List<OrderedTree<E>> getSiblings()
public java.util.List<E> getSiblingElements()
public int numSiblings()
public OrderedTree<E> getRoot()
public java.util.List<OrderedTree<E>> getAncestors()
public java.util.List<E> getAncestorElements()
public java.util.List<OrderedTree<E>> getOrderedTreeNodes()
OrderedTree<E>
in this tree.OrderedTree<E>
in this treepublic java.util.List<Tree<E>> getNodes()
Tree<E>
in this tree.Tree<E>
in this treepublic java.util.List<E> getElements()
public java.util.List<E> traverse()
public java.util.List<OrderedTree<E>> traverseNodes()
public java.util.List<E> traversePreOrder()
public java.util.List<OrderedTree<E>> traverseNodesPreOrder()
public java.util.List<E> traversePostOrder()
public java.util.List<OrderedTree<E>> traverseNodesPostOrder()
public java.util.List<E> traverseLevelOrder()
public java.util.List<OrderedTree<E>> traverseNodesLevelOrder()
public void remove()
public void removeChild(OrderedTree<E> child)
child
- a node to be removed from the children of this nodepublic void removeChild(E element)
element
- an element to be removed from the children of this nodepublic void removeChildAt(int index)
index
- an index where a child will be removed from this nodepublic void removeChildren()
Tree
public java.util.List<OrderedTree<E>> getSubtrees()
public java.util.List<OrderedTree<E>> getLeaves()
public boolean subsumes(OrderedTree<E> tree)
true
if the given tree matches this tree or a subtree of the tree.tree
- a tree to compared with this treetrue
if the given tree matches this tree or a subtree of the tree;
false
otherwisepublic BinaryTree<E> binarize()