E - the type of elements in this treepublic abstract class AbstractTree<E> extends java.util.AbstractCollection<E> implements Tree<E>
int or
boolean, not instances of the Type type. Note that child nodes may have duplicate
elements.| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
PAREN_END |
static java.lang.String |
PAREN_START |
| Constructor and Description |
|---|
AbstractTree()
Public constructor.
|
AbstractTree(E element)
Public constructor.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(E e)
Adds a child with the given element.
|
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.
|
E |
getElement()
Returns the element of this node.
|
java.util.List<E> |
getLeafElements()
Returns a list of leaf elements in this tree in a natural order.
|
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 |
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. |
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. |
java.util.Iterator<E> |
iterator()
Returns the iterator of this tree.
|
int |
numLeaves()
Returns the number of leaves of this tree.
|
void |
removeChildren(java.util.Collection<E> elements)
Removes children with one of the given elements from this node.
|
void |
setElement(E element)
Sets the given element to this node.
|
int |
size()
Returns the number of nodes in this tree.
|
java.util.List<E> |
yield()
Returns the yield of this tree as a list of elements of leaves.
|
addAll, clear, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toStringequals, getClass, hashCode, notify, notifyAll, wait, wait, waitaddChild, equals, find, findChild, getAncestorElements, getElements, getNodes, getParent, getRoot, getSiblingElements, hasChild, hashCode, numChildren, numSiblings, remove, removeChild, removeChildrenpublic static final java.lang.String PAREN_START
public static final java.lang.String PAREN_END
public AbstractTree()
public AbstractTree(E element)
element - an element of this nodepublic java.util.Iterator<E> iterator()
public int size()
public int depth()
public int depth(Tree<E> node)
public boolean hasParent()
true if this node has a parent.public boolean hasParent(E element)
true if this node has a parent with the given element.public boolean isRoot()
true if this node is the root.public int degree()
public int degree(Tree<E> node)
public boolean hasChild()
true if this node has a child.public boolean add(E e)
public void removeChildren(java.util.Collection<E> elements)
removeChildren in interface Tree<E>elements - a collection of elements to be removed from the children of this nodepublic boolean hasAncestor(E element)
true if this node has an ancestor with the given element.hasAncestor in interface Tree<E>element - an element whose presence in the ancestors of this node will be testedtrue if this node has the given ancestor; false otherwisepublic boolean hasAncestor(Tree<E> ancestor)
true if this node has the given ancestor.hasAncestor in interface Tree<E>ancestor - an ancestor whose presence for this node will be testedtrue if this node has the given ancestor; false otherwisepublic boolean hasDescendant(E element)
true if this node has a descendant with the given element.hasDescendant in interface Tree<E>element - an element whose presence in the descendants of this node will be testedtrue if this node has the given descendant; false otherwisepublic boolean hasDescendant(Tree<E> descendant)
true if this node has the given descendant.hasDescendant in interface Tree<E>descendant - a descendant whose presence for this node will be testedtrue if this node has the given descendant; false otherwisepublic boolean isLeaf()
true if this node is a leaf.public int numLeaves()
public E getElement()
getElement in interface Tree<E>public void setElement(E element)
setElement in interface Tree<E>element - an element that will be set to this nodepublic boolean hasElement()
true if this node has an element.hasElement in interface Tree<E>true if this node has an element; false otherwisepublic boolean hasElement(E element)
true if this node has the given element.hasElement in interface Tree<E>element - an element whose presence in this node will be testedtrue if this node has the given element; false otherwisepublic boolean isLabeled()
true if this node is labeled.public boolean 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.isLabeledTree in interface Tree<E>alphabet - a set of elements to be compared with elements in this treetrue if this tree is a labeled tree; false otherwisepublic java.util.List<E> yield()
public java.util.List<E> getLeafElements()
public boolean isBalanced()
true if this tree is balanced. A balanced tree is a tree such that all leaves
of the tree are at the same depth.isBalanced in interface Tree<E>true if this tree is balanced; false otherwise