package rpn;

import rpn.basic.Item;

public class RepeatStream extends ItemStream {
	Item a[];
	int n;
	int N;
	
	public RepeatStream(Item a[], int N) {
		this.a = a;
		this.N = N-1;
		n = 0;
	}
	
	public Item getItem() {
		if (n == a.length) {
			n = 0;
			N--;
		} 
		return(a[n++]);
	}

	public Item peek() {
		return(a[n]);
	}
	
	public boolean atEOF() {
		return(n == a.length && N == 0);
	}
	
	public String toString() {
		String s = new String("Repeat:\n");
		for (int i=n;i<a.length;i++) {
			s += a[i].toString();
			s += "\n";
		}
		return(s);
	}
}