javatools.datatypes
Class Tree<T>

java.lang.Object
  extended by javatools.datatypes.Tree<T>
All Implemented Interfaces:
java.lang.Iterable<T>, Visitable<Tree<T>>

public class Tree<T>
extends java.lang.Object
implements java.lang.Iterable<T>, Visitable<Tree<T>>

This class is part of the Java Tools (see http://mpii.de/yago-naga/javatools). It is licensed under the Creative Commons Attribution License (see http://creativecommons.org/licenses/by/3.0) by the YAGO-NAGA team (see http://mpii.de/yago-naga). The class represents the simple datatype of a Tree.


Constructor Summary
Tree()
          Constructs an empty tree with a null element
Tree(T element)
          Constructs a tree with a node element
Tree(T element, java.util.List<Tree<T>> children)
          Constructs a tree with a node element and children
Tree(Tree<T> parent, T element)
          Constructs a tree with a node element and a parent
Tree(Tree<T> parent, T element, java.util.List<Tree<T>> children)
          Constructs a tree with a node element and a parent
 
Method Summary
 void addChild(Tree<T> child)
          Adds a child
 java.util.List<Tree<T>> getChildren()
          Depth first search across the tree
 T getElement()
          Returns the element
 Tree<T> getParent()
          Returns the parent
 java.util.Iterator<T> iterator()
           
static void main(java.lang.String[] args)
           
 boolean receive(Visitor<Tree<T>> visitor)
          Receives a visitor for a depth first traversal
 void setChildren(java.util.List<Tree<T>> children)
          Sets the children
 void setElement(T element)
          Sets the element
 void setParent(Tree<T> parent)
          Sets the parent
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Tree

public Tree()
Constructs an empty tree with a null element


Tree

public Tree(T element)
Constructs a tree with a node element


Tree

public Tree(Tree<T> parent,
            T element)
Constructs a tree with a node element and a parent


Tree

public Tree(T element,
            java.util.List<Tree<T>> children)
Constructs a tree with a node element and children


Tree

public Tree(Tree<T> parent,
            T element,
            java.util.List<Tree<T>> children)
Constructs a tree with a node element and a parent

Method Detail

getParent

public Tree<T> getParent()
Returns the parent


setParent

public void setParent(Tree<T> parent)
Sets the parent


getChildren

public java.util.List<Tree<T>> getChildren()
Depth first search across the tree


setChildren

public void setChildren(java.util.List<Tree<T>> children)
Sets the children


addChild

public void addChild(Tree<T> child)
Adds a child


getElement

public T getElement()
Returns the element


setElement

public void setElement(T element)
Sets the element


iterator

public java.util.Iterator<T> iterator()
Specified by:
iterator in interface java.lang.Iterable<T>

receive

public boolean receive(Visitor<Tree<T>> visitor)
                throws java.lang.Exception
Receives a visitor for a depth first traversal

Specified by:
receive in interface Visitable<Tree<T>>
Throws:
java.lang.Exception

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

main

public static void main(java.lang.String[] args)