csli.util.collections.tree
Class AbstractTree<N,T extends AbstractTree<N,T>>
java.lang.Object
java.util.AbstractCollection<N>
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)
| Methods inherited from interface java.util.Collection |
add, addAll, clear, contains, containsAll, equals, hashCode, remove, removeAll, retainAll, toArray, toArray |
AbstractTree
public AbstractTree()
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()