4 package net
.kezvh
.collections
.trees
;
6 import java
.util
.Collection
;
12 * @param <E> collection element type
14 public interface Tree
<E
> {
16 * @return a value associated with the root node of this tree
21 * @param value new value
22 * @return the previous value of the root node
27 * you can't add things to this list, though things may be removed
29 * @return a list of children of the tree, backed by the tree
31 List
<Tree
<E
>> children();
36 * @param index index of the child
37 * @return child at the index
39 Tree
<E
> child(int index
);
42 * @param e a value to associate with a new child of the tree
43 * @return the new child node
45 Tree
<E
> addChild(E e
);
48 * @param index index in the list of children to insert the child
49 * @param e a value to associate with a new child of the tree
50 * @return the new child node
52 Tree
<E
> addChild(int index
, E e
);
55 * remove a child node from the tree
57 * @param index index of a child
58 * @return tree that exists with that child as the root
60 Tree
<E
> pruneChild(int index
);
63 * like "Collection.addAll", the original tree will not become *part* of this tree
64 * merely, its elements and structure will become part of this tree.
67 * @return the child tree node of the tree as spliced
69 Tree
<E
> splice(Tree
<E
> tree
);
72 * @param index index at which to insert the spliced tree
74 * @return the child tree node of the tree as spliced
76 Tree
<E
> spliceAt(int index
, Tree
<E
> tree
);
79 * @param index in the list of children
80 * @return the value of the child at the specified index
82 E
childValue(int index
);
85 * @return true if the node has no children
90 * @return a collection of elements of the tree backed by the tree. iterates inorder.
92 Collection
<E
> inorder();
95 * @return a collection of elements of the tree backed by the tree. iterates preorder (depth first).
97 Collection
<E
> preorder();
100 * @return a collection of elements of the tree backed by the tree. iterates postorder.
102 Collection
<E
> postorder();
105 * @return a collection of elements of the tree backed by the tree. iterates level order (breadth first).
107 Collection
<E
> levelOrder();
110 * @return number of nodes in the tree
115 * @return the tree to which this is a child, if such exists