E
- the type of elements in this treepublic interface Tree<E>
extends java.util.Collection<E>
Modifier and Type | Method and Description |
---|---|
void |
addChild(E element)
Adds a child with the given element to this node.
|
int |
degree()
Returns the degree of this tree.
|
int |
degree(Tree<E> node)
Returns the degree of the given node.
|
int |
depth()
Returns the depth of this tree.
|
int |
depth(Tree<E> node)
Returns the depth of the given node.
|
boolean |
equals(java.lang.Object obj)
Returns
true if the given object is equal to this tree. |
Tree<E> |
find(E element)
Finds a node of the first occurrence of the given element in this tree.
|
Tree<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.
|
E |
getElement()
Returns the element of this node.
|
java.util.List<E> |
getElements()
Returns a list of all elements of this tree.
|
java.util.List<Tree<E>> |
getNodes()
Returns a list of all nodes of this tree.
|
Tree<E> |
getParent()
Returns the parent of this node.
|
Tree<E> |
getRoot()
Returns the root of this tree.
|
java.util.Collection<E> |
getSiblingElements()
Returns a collection of elements of siblings of this node.
|
boolean |
hasAncestor(E element)
Returns
true if this node has an ancestor with the given element. |
boolean |
hasAncestor(Tree<E> ancestor)
Returns
true if this node has the given ancestor. |
boolean |
hasChild()
Returns
true if this node has a child. |
boolean |
hasChild(E element)
Returns
true if this node has a child with the given element. |
boolean |
hasDescendant(E element)
Returns
true if this node has a descendant with the given element. |
boolean |
hasDescendant(Tree<E> descendant)
Returns
true if this node has the given descendant. |
boolean |
hasElement()
Returns
true if this node has an element. |
boolean |
hasElement(E element)
Returns
true if this node has the given element. |
int |
hashCode()
Returns the hash code value for this tree.
|
boolean |
hasParent()
Returns
true if this node has a parent. |
boolean |
hasParent(E element)
Returns
true if this node has a parent with the given element. |
boolean |
hasParent(Tree<E> parent)
Returns
true if this node has the given parent. |
boolean |
isBalanced()
Returns
true if this tree is balanced. |
boolean |
isLabeled()
Returns
true if this node is labeled. |
boolean |
isLabeledTree(java.util.Set<E> alphabet)
Returns
true if this tree is a labeled tree. |
boolean |
isLeaf()
Returns
true if this node is a leaf. |
boolean |
isRoot()
Returns
true if this node is the root. |
int |
numChildren()
Returns the number of children of this node.
|
int |
numLeaves()
Returns the number of leaves in this tree.
|
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 |
removeChildren()
Removes all children from this node.
|
void |
removeChildren(java.util.Collection<E> element)
Removes children with one of the given elements from this node.
|
void |
setElement(E element)
Sets the given element to this node.
|
java.util.List<E> |
yield()
Returns the yield of this tree as a list of elements of leaves.
|
boolean equals(java.lang.Object obj)
true
if the given object is equal to this tree.equals
in interface java.util.Collection<E>
equals
in class java.lang.Object
obj
- an object to be compared with this treetrue
if the given object is equal to this tree; false
otherwiseint hashCode()
hashCode
in interface java.util.Collection<E>
hashCode
in class java.lang.Object
Tree<E> find(E element)
element
- an element to be found in this tree, if presentTree<E> findChild(E element)
element
- an element to be found in the children of this node, if presentint depth()
int depth(Tree<E> node)
node
- a node whose depth will be returnedboolean hasParent()
true
if this node has a parent.true
if this node has a parent; false
otherwiseboolean hasParent(E element)
true
if this node has a parent with the given element.element
- an element whose presence in the parent of this node will be testedtrue
if this node has a parent with the given element; false
otherwiseboolean hasParent(Tree<E> parent)
true
if this node has the given parent.parent
- a parent whose presence in this node will be testedtrue
if this node has the given parent; false
otherwiseint degree()
int degree(Tree<E> node)
node
- a node whose degree will be returnedint numChildren()
boolean hasChild()
true
if this node has a child.true
if this node has a child; false
otherwiseboolean 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
otherwisevoid addChild(E element)
element
- an element that will be added to the children of this nodejava.util.Collection<E> getSiblingElements()
int numSiblings()
boolean isRoot()
true
if this node is the root.true
if this node is the root; false
otherwisejava.util.List<E> getAncestorElements()
void remove()
void removeChild(E element)
element
- an element to be removed from the children of this nodevoid removeChildren()
void removeChildren(java.util.Collection<E> element)
element
- a collection of elements to be removed from the children of this nodeboolean hasAncestor(E element)
true
if this node has an ancestor with the given element.element
- an element whose presence in the ancestors of this node will be testedtrue
if this node has the given ancestor; false
otherwiseboolean hasAncestor(Tree<E> ancestor)
true
if this node has the given ancestor.ancestor
- an ancestor whose presence for this node will be testedtrue
if this node has the given ancestor; false
otherwiseboolean hasDescendant(E element)
true
if this node has a descendant with the given element.element
- an element whose presence in the descendants of this node will be testedtrue
if this node has the given descendant; false
otherwiseboolean hasDescendant(Tree<E> descendant)
true
if this node has the given descendant.descendant
- a descendant whose presence for this node will be testedtrue
if this node has the given descendant; false
otherwisejava.util.List<E> getElements()
java.util.List<Tree<E>> getNodes()
boolean isLeaf()
true
if this node is a leaf.true
if this node is a leaf; false
otherwiseint numLeaves()
E getElement()
void setElement(E element)
element
- an element that will be set to this nodeboolean hasElement()
true
if this node has an element.true
if this node has an element; false
otherwiseboolean hasElement(E element)
true
if this node has the given element.element
- an element whose presence in this node will be testedtrue
if this node has the given element; false
otherwiseboolean isLabeled()
true
if this node is labeled.true
if this node is labeled; false
otherwiseboolean isLabeledTree(java.util.Set<E> alphabet)
true
if this tree is a labeled tree. A labeled tree is defined as a tree such
that each node has a symbol assigned from a fixed finite alphabet.alphabet
- a set of elements to be compared with elements in this treetrue
if this tree is a labeled tree; false
otherwisejava.util.List<E> yield()
boolean isBalanced()
true
if this tree is balanced. A balanced tree is a tree such that all leaf
nodes of the tree are at the same depth.true
if this tree is balanced; false
otherwise