a whole bunch of stuff
[ephemerata.git] / KezvhLib / src-lib / net / kezvh / collections / trees / Tree.java
blobb714de82ddb621b09983823870c7a76034d4371e
1 /**
3 */
4 package net.kezvh.collections.trees;
6 import java.util.Collection;
7 import java.util.List;
9 /**
10 * @author afflux
12 * @param <E> collection element type
14 public interface Tree<E> {
15 /**
16 * @return a value associated with the root node of this tree
18 E value();
20 /**
21 * @param value new value
22 * @return the previous value of the root node
24 E setValue(E value);
26 /**
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();
33 /**
34 * backed by the tree
36 * @param index index of the child
37 * @return child at the index
39 Tree<E> child(int index);
41 /**
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);
47 /**
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);
54 /**
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);
62 /**
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.
66 * @param tree
67 * @return the child tree node of the tree as spliced
69 Tree<E> splice(Tree<E> tree);
71 /**
72 * @param index index at which to insert the spliced tree
73 * @param tree
74 * @return the child tree node of the tree as spliced
76 Tree<E> spliceAt(int index, Tree<E> tree);
78 /**
79 * @param index in the list of children
80 * @return the value of the child at the specified index
82 E childValue(int index);
84 /**
85 * @return true if the node has no children
87 boolean isLeaf();
89 /**
90 * @return a collection of elements of the tree backed by the tree. iterates inorder.
92 Collection<E> inorder();
94 /**
95 * @return a collection of elements of the tree backed by the tree. iterates preorder (depth first).
97 Collection<E> preorder();
99 /**
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
112 int size();
115 * @return the tree to which this is a child, if such exists
117 Tree<E> parent();