package fortran.reader;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringReader;

import com.google.common.collect.AbstractIterator;

class CardReaderImpl extends AbstractIterator<Card> implements CardReader {
	private final BufferedReader reader;
	private int lineNo = 1;

	public CardReaderImpl(String source) {
		this(new StringReader(source));
	}

	public CardReaderImpl(InputStream input) {
		this(new InputStreamReader(input));
	}

	public CardReaderImpl(Reader reader) {
		this(new BufferedReader(reader));
	}

	public CardReaderImpl(BufferedReader reader) {
		this.reader = reader;
	}

	@Override
	protected Card computeNext() {
		try {
			String line = reader.readLine();
			if (line != null)
				return new CardImpl(line, lineNo++);
			else
				return endOfData();
		} catch (IOException e) {
			return endOfData();
		}
	}
}

@@ -594,68 +594,63 @@
 %7B%0A%09%09
-this(new BufferedReader(reader));%0A%09%7D%0A%0A%09public CardR
+if (reader instanceof BufferedReader)%0A%09%09%09this.r
 eader
-Impl
+ = 
 (Buf
@@ -660,27 +660,34 @@
 edReader
+)
  reader
-) %7B%0A
+;%0A%09%09else%0A%09
 %09%09this.r
@@ -694,22 +694,42 @@
 eader = 
-reader
+new BufferedReader(reader)
 ;%0A%09%7D%0A%0A%09@

unify constructors