package innovimax.mixthem.io;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class MultiChannelLineReader implements IMultiChannelLineInput {
	
	private final List<ILineInput> readers = new ArrayList<ILineInput>();
	
	public MultiChannelLineReader(final List<InputResource> inputs) {
		inputs.stream().forEach(input -> {
			try {
				this.readers.add(new DefaultLineReader(input));
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		});
	}
	
	@Override
	public boolean hasLine() throws IOException {
		final Iterator<ILineInput> iterator = this.readers.iterator();
		while (iterator.hasNext()) {
			final ILineInput reader = iterator.next();
			if (reader.hasLine()) {
				return true;
			}
		}
		return false;
	}
	
	@Override
	public List<String> nextLineRange() throws IOException {
		final List<String> lines = new ArrayList<String>();		
		final Iterator<ILineInput> iterator = this.readers.iterator();
		while (iterator.hasNext()) {
			final ILineInput reader = iterator.next();
			final String line = reader.nextLine();
			lines.add(line);
		}
		return lines;
	}

	@Override
	public void close() throws IOException {
		final Iterator<ILineInput> iterator = this.readers.iterator();
		while (iterator.hasNext()) {
			final ILineInput reader = iterator.next();
			reader.close();
		}		
	}
	
}

@@ -1145,16 +1145,516 @@
 n lines;
+%09%0A%09%7D%0A%09%0A%09@Override%0A%09public List%3CString%3E nextLineRange(List%3CBoolean%3E readingRange) throws IOException %7B%0A%09%09final List%3CString%3E lines = new ArrayList%3CString%3E();%0A%09%09int index = 0;%0A%09%09final Iterator%3CILineInput%3E iterator = this.readers.iterator();%0A%09%09while (iterator.hasNext()) %7B%0A%09%09%09if (readingRange.get(index).booleanValue()) %7B%0A%09%09%09%09final ILineInput reader = iterator.next();%0A%09%09%09%09final String line = reader.nextLine();%0A%09%09%09%09lines.add(line);%0A%09%09%09%7D else %7B%0A%09%09%09%09lines.add(null);%0A%09%09%09%7D%0A%09%09%09index++;%0A%09%09%7D%0A%09%09return lines;%09%09
 %0A%09%7D%0A%0A%09@O

Update MultiChannelLineReader.java