package com.azabani.java.rover;

import java.util.Stack;
import java.util.Iterator;

public class RecursionCommand implements RoverCommand {
	int listIndex; // non-negative
	RoverListList program;
	Stack<Iterator<RoverCommand>> stack;
	public RecursionCommand(int listIndex, RoverListList program,
		Stack<Iterator<RoverCommand>> stack)
		throws IllegalArgumentException {
		if (listIndex < 0)
			throw new IllegalArgumentException(
				"listIndex must not be negative"
			);
		this.listIndex = listIndex;
		this.program = program;
		this.stack = stack;
	}
	public void execute() {
		stack.push(program.get(listIndex).iterator());
	}
	public String toString() {
		return "call:" + Integer.toString(listIndex);
	}
}

@@ -270,70 +270,8 @@
 ndex
-, RoverListList program,%0A%09%09Stack%3CIterator%3CRoverCommand%3E%3E stack
 )%0A%09%09
@@ -442,32 +442,148 @@
 x;%0A%09
-%09this.program = program;
+%7D%0A%09public void setProgram(RoverListList program) %7B%0A%09%09this.program = program;%0A%09%7D%0A%09public void setStack(Stack%3CIterator%3CRoverCommand%3E%3E stack) %7B
 %0A%09%09t

allow users of RecursionCommand to set program/stack late