Package at.jku.ssw.fp.coll
Class Tree<E>
- java.lang.Object
-
- at.jku.ssw.fp.coll.Tree<E>
-
- Type Parameters:
E
- The type of elements
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
Tree.Empty
,Tree.Node
public abstract class Tree<E> extends Object implements Serializable
Binary tree with elements which are generic. Trees are immutable. This structure closely corresponds to the functional list structureFList
- Author:
- Herbert Praehofer
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Tree.Empty<E>
Class for the empty tree.static class
Tree.Node<E>
Class representing a tree node with a value and a left and right subtree.
-
Constructor Summary
Constructors Constructor Description Tree()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static <E> Tree<E>
empty()
Returns the empty tree.abstract boolean
isEmpty()
Tests if this tree is the empty tree.abstract Tree<E>
left()
Returns the left subtree of this tree node.abstract boolean
leftExists()
Tests if the left subtree is not empty.static <E> Tree<E>
of(E value)
Creates a functional tree node with a value and empty left and right subtrees.static <E> Tree<E>
of(E value, Tree<E> left, Tree<E> right)
Creates a functional tree node with a value and a left and right subtree.abstract Tree<E>
right()
Returns the right subtree of this tree node.abstract boolean
rightExists()
Tests if the right subtree is not empty.abstract E
value()
Returns the value of this tree node.
-
-
-
Field Detail
-
EMPTY
private static final Tree EMPTY
The single object representing the empty tree
-
-
Method Detail
-
empty
public static <E> Tree<E> empty()
Returns the empty tree.- Type Parameters:
E
- the element type- Returns:
- the empty tree
-
of
public static <E> Tree<E> of(E value, Tree<E> left, Tree<E> right)
Creates a functional tree node with a value and a left and right subtree.- Type Parameters:
E
- the element type- Parameters:
value
- the value of this tree nodeleft
- the left subtreeright
- the right subtree- Returns:
- the tree node with value and left and right subtrees
-
of
public static <E> Tree<E> of(E value)
Creates a functional tree node with a value and empty left and right subtrees.- Type Parameters:
E
- the element type- Parameters:
value
- the value of this tree node- Returns:
- the tree node with value and empty left and right subtrees
-
value
public abstract E value()
Returns the value of this tree node.- Returns:
- the value of this tree node
-
left
public abstract Tree<E> left()
Returns the left subtree of this tree node.- Returns:
- the left subtree of this tree node
-
right
public abstract Tree<E> right()
Returns the right subtree of this tree node.- Returns:
- the right subtree of this tree node
-
isEmpty
public abstract boolean isEmpty()
Tests if this tree is the empty tree.- Returns:
true
, if this tree is the empty tree;false
otherwise
-
leftExists
public abstract boolean leftExists()
Tests if the left subtree is not empty.- Returns:
true
if the left subtree is not empty;false
otherwise
-
rightExists
public abstract boolean rightExists()
Tests if the right subtree is not empty.- Returns:
true
if the right subtree is not empty;false
otherwise
-
-