package innovimax.mixthem;

import innovimax.mixthem.interfaces.IInputLine;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.Random;

/**
* <p>Reads lines from a character-input file.</p>
* <p>This is the default implementation of IInputLine.</p>
* @see IInputLine
* @author Innovimax
* @version 1.0
*/
public class DefaultLineReader implements IInputLine {

	private final static int DEFAULT_RANDOM_SEED = 1789;

	private final BufferedReader reader;
	private final boolean first;
	private final Random random;
	private boolean jump;

	/**
 	* Creates a line reader.
 	* @param file The input file to be read
 	* @param first True is this reader is the first one
 	* @throws IOException - If an I/O error occurs
 	*/
	public DefaultLineReader(File input, boolean first) throws IOException {
		this.reader = new BufferedReader(new FileReader(input));
		this.first = first;
		this.random = new Random(DEFAULT_RANDOM_SEED);
		this.jump = !first;
	}

	@Override
	public boolean hasLine() throws IOException {
		// should return True only if there is a line to write regarding the type
		return this.reader.ready();
	}

	@Override
	public String nextLine(ReadType type, boolean force) throws IOException {
		String line = null;
		switch (type) {
			case _SIMPLE:
				if (this.jump && !force) {
					this.reader.readLine();
				}
				line = this.reader.readLine();
				this.jump = true;
				break;
			case _RANDOM:
				if (this.first) {
					if (random.nextBoolean() || force) {
						line = this.reader.readLine();
					} else {
						this.reader.readLine();
					}
				} else {
					if (!random.nextBoolean() || force) {
						line = this.reader.readLine();
					} else {
						this.reader.readLine();
					}
				}
				break;
		}
		return line;
	}

	@Override
	public void close() throws IOException {
		this.reader.close();
	}

}

@@ -1293,16 +1293,36 @@
 = null;%0A
+%09%09if (hasLine()) %7B%0A%09
 %09%09switch
@@ -1331,16 +1331,17 @@
 type) %7B%0A
+%09
 %09%09%09case 
@@ -1349,28 +1349,30 @@
 SIMPLE:%0A%09%09%09%09
+%09
 if (
+!
 this.jump &&
@@ -1373,12 +1373,11 @@
 ump 
-&& !
+%7C%7C 
 forc
@@ -1382,24 +1382,32 @@
 rce) %7B%0A%09%09%09%09%09
+%09line = 
 this.reader.
@@ -1421,26 +1421,35 @@
 e();
-%0A
+%09%09
 %09%09%09%09
-%7D
 %0A
+%09
 %09%09%09%09
-line = 
+%7D else %7B%0A%09%09%09%09%09%09
 this
@@ -1464,24 +1464,37 @@
 readLine();%0A
+%09%09%09%09%09%7D%09%09%09%09%09%0A%09
 %09%09%09%09this.jum
@@ -1501,14 +1501,21 @@
 p = 
-true
+!this.jump
 ;%0A
+%09
 %09%09%09%09
@@ -1521,16 +1521,17 @@
 %09break;%0A
+%09
 %09%09%09case 
@@ -1542,30 +1542,13 @@
 DOM:
-%0A
 %09%09%09%09
-if (this.first) %7B
+%09
 %0A%09%09%09
@@ -1552,16 +1552,17 @@
 %09%09%09%09%09if 
+(
 (random.
@@ -1579,150 +1579,21 @@
 n() 
-%7C%7C force) %7B%0A%09%09%09%09%09%09line = this.reader.readLine();%0A%09%09%09%09%09%7D else %7B%0A%09%09%09%09%09%09this.reader.readLine();%0A%09%09%09%09%09%7D%0A%09%09%09%09%7D else %7B%0A%09%09%09%09%09if (!random.nextBoolean(
+== this.first
 ) %7C%7C
@@ -1693,15 +1693,15 @@
 %09%09%09%7D
-%0A
+%09
 %09%09%09%09
-%7D
 %0A
+%09
 %09%09%09%09
@@ -1707,16 +1707,21 @@
 %09break;%0A
+%09%09%09%7D%0A
 %09%09%7D%0A%09%09re

Update DefaultLineReader.java