csli.util.collections.tree
Class AbstractTree<N,T extends AbstractTree<N,T>>

java.lang.Object
  extended by java.util.AbstractCollection<N>
      extended by csli.util.collections.tree.AbstractTree<N,T>
Type Parameters:
N -
T -
All Implemented Interfaces:
Tree<N,T>, Iterable<N>, Collection<N>

public abstract class AbstractTree<N,T extends AbstractTree<N,T>>
extends AbstractCollection<N>
implements Tree<N,T>

Author:
jefe An abstract implementation of tree iteration and other basic functionality. To get a fully functional tree, you need to implement: getNode getChildren isLeaf getParent (optional) addChild (optional) setNode (optional) isRoot (optional)

Constructor Summary
AbstractTree()
           
 
Method Summary
 void addChild(T child)
           
 void addChildren(Collection<? extends T> children)
           
 int depth()
           
 Transformer.Transform<T,Integer> depthGetter()
           
 T getParent()
           
 T getRoot()
           
 boolean isEmpty()
           
 boolean isRoot()
           
 Iterator<N> iterator()
          Iterate over nodes.
 Collection<T> leaves()
          Return an unmodifiable collection view of the tree's leaves.
 Transformer.Transform<T,N> nodeGetter()
           
 Collection<N> nodes()
          Returns a view of the tree as an unmodifiable collection of nodes of type T.
 int numChildren()
           
 void setNode(N node)
           
 int size()
           
 Transformer.Transform<T,Integer> sizeGetter()
           
protected  Iterator<T> subtreeIterator()
          Return an iterator over all of the subtrees in this tree.
 Collection<T> subtrees()
          Return an unmodifiable collection view of all of the subtrees in this tree.
 String toString()
           
 
Methods inherited from class java.util.AbstractCollection
add, addAll, clear, contains, containsAll, remove, removeAll, retainAll, toArray, toArray
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface csli.util.collections.tree.Tree
getChildren, getNode, isLeaf
 
Methods inherited from interface java.util.Collection
add, addAll, clear, contains, containsAll, equals, hashCode, remove, removeAll, retainAll, toArray, toArray
 

Constructor Detail

AbstractTree

public AbstractTree()
Method Detail

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Collection<N>
Overrides:
isEmpty in class AbstractCollection<N>

size

public int size()
Specified by:
size in interface Collection<N>
Specified by:
size in class AbstractCollection<N>

depth

public int depth()
Specified by:
depth in interface Tree<N,T extends AbstractTree<N,T>>

numChildren

public int numChildren()
Specified by:
numChildren in interface Tree<N,T extends AbstractTree<N,T>>

getParent

public T getParent()
Specified by:
getParent in interface Tree<N,T extends AbstractTree<N,T>>

isRoot

public boolean isRoot()
Specified by:
isRoot in interface Tree<N,T extends AbstractTree<N,T>>

getRoot

public T getRoot()
Specified by:
getRoot in interface Tree<N,T extends AbstractTree<N,T>>

addChild

public void addChild(T child)
Specified by:
addChild in interface Tree<N,T extends AbstractTree<N,T>>

setNode

public void setNode(N node)
Specified by:
setNode in interface Tree<N,T extends AbstractTree<N,T>>

addChildren

public void addChildren(Collection<? extends T> children)
Specified by:
addChildren in interface Tree<N,T extends AbstractTree<N,T>>

toString

public String toString()
Overrides:
toString in class AbstractCollection<N>

nodes

public Collection<N> nodes()
Returns a view of the tree as an unmodifiable collection of nodes of type T.

Specified by:
nodes in interface Tree<N,T extends AbstractTree<N,T>>

iterator

public Iterator<N> iterator()
Iterate over nodes.

Specified by:
iterator in interface Iterable<N>
Specified by:
iterator in interface Collection<N>
Specified by:
iterator in class AbstractCollection<N>

subtrees

public Collection<T> subtrees()
Return an unmodifiable collection view of all of the subtrees in this tree.

Specified by:
subtrees in interface Tree<N,T extends AbstractTree<N,T>>

subtreeIterator

protected Iterator<T> subtreeIterator()
Return an iterator over all of the subtrees in this tree.


leaves

public Collection<T> leaves()
Return an unmodifiable collection view of the tree's leaves.

Specified by:
leaves in interface Tree<N,T extends AbstractTree<N,T>>

nodeGetter

public Transformer.Transform<T,N> nodeGetter()

sizeGetter

public Transformer.Transform<T,Integer> sizeGetter()

depthGetter

public Transformer.Transform<T,Integer> depthGetter()