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.io.UncheckedIOException;
import java.util.List;
import java.util.stream.Collectors;

/**
* <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 BufferedReader reader;
	private List<String> lines;	

	/**
 	* Creates a line reader.
 	* @param file The input file to be read
 	* @throws IOException - If an I/O error occurs
 	*/
	public DefaultLineReader(File input) throws IOException {
		this.reader = new BufferedReader(new FileReader(input));
	}

	@Override
	public boolean hasLine() throws IOException {
		return this.reader.ready();
	}

	@Override
	public String nextLine() throws IOException {
		return this.reader.readLine();
	}

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

	@Override
	public void preload() throws IOException {
		try {
			this.lines = this.reader.lines().collect(Collectors.toList());	
		} catch (UncheckedIOException e) {
			throw e.getCause();
		}
	}	

	@Override
	public int size() {
		if (this.lines != null) {
			return this.lines.size();
		}
		return -1;
	}

	@Override
	public boolean hasLine(int index) {
		if (this.lines != null) {
			return (index < this.lines.size());
		}
		return false;
	}

	@Override
	public String getLine(int index) {		
		if (this.hasLine(index)) {
			return this.lines.get(index);
		}
		return null;
	}

}

@@ -180,104 +180,8 @@
 ion;
-%0Aimport java.io.UncheckedIOException;%0Aimport java.util.List;%0Aimport java.util.stream.Collectors;
 %0A%0A/*
@@ -444,38 +444,8 @@
 der;
-%0A%09private List%3CString%3E lines;%09
 %0A%0A%09/
@@ -924,32 +924,32 @@
 s IOException %7B%0A
+
 %09%09this.reader.cl
@@ -963,588 +963,6 @@
 %09%7D%0A%0A
-%09@Override%0A%09public void preload() throws IOException %7B%0A%09%09try %7B%0A%09%09%09this.lines = this.reader.lines().collect(Collectors.toList());%09%0A%09%09%7D catch (UncheckedIOException e) %7B%0A%09%09%09throw e.getCause();%0A%09%09%7D%0A%09%7D%09%0A%0A%09@Override%0A%09public int size() %7B%0A%09%09if (this.lines != null) %7B%0A%09%09%09return this.lines.size();%0A%09%09%7D%0A%09%09return -1;%0A%09%7D%0A%0A%09@Override%0A%09public boolean hasLine(int index) %7B%0A%09%09if (this.lines != null) %7B%0A%09%09%09return (index %3C this.lines.size());%0A%09%09%7D%0A%09%09return false;%0A%09%7D%0A%0A%09@Override%0A%09public String getLine(int index) %7B%09%09%0A%09%09if (this.hasLine(index)) %7B%0A%09%09%09return this.lines.get(index);%0A%09%09%7D%0A%09%09return null;%0A%09%7D%0A%0A
 %7D%0A

Update DefaultLineReader.java