- public Tree(Input.Location loc, T head) { this(loc, head, null); }
- public Tree(Input.Location loc, T head, Tree<T>[] children) {
- this.location = loc;
- this.head = head;
- Tree<T>[] children2 = children==null ? new Tree[0] : new Tree[children.length];
- if (children != null) System.arraycopy(children, 0, children2, 0, children.length);
- this.children = children2;
+ /** the element at the head of the tree */
+ public NodeType head() { return ihead; }
+ public NodeType getHead() { return ihead; }
+
+ /** the tree's children */
+ public Iterable<Tree<NodeType>> children() { return this; }
+
+ /** the tree's children */
+ public Iterator<Tree<NodeType>> iterator() {
+ return lift
+ ? new ConcatenateIterator(new ArrayIterator(children, 0, children.length-1),
+ children[children.length-1].iterator())
+ : new ArrayIterator(children);
+ }
+
+ /** get the <tt>i</t>th child */
+ public Tree<NodeType> child(int i) {
+ return lift && i >= children.length-1
+ ? children[children.length-1].child(i-(children.length-1))
+ : children[i];