package innovimax.mixthem.io;

import java.io.IOException;
//import java.util.ArrayList;
//import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class MultiChannelLineReader implements IMultiChannelLineInput {
	
	private final List<ILineInput> readers;
	
	/**
	* Constructor
	* @param inputs The list of inputs as InputResource
	* @param selection The input index selection (maybe empty)
	* @see innovimax.mixthem.io.InputResource
	*/
	public MultiChannelLineReader(final List<InputResource> inputs, final Set<Integer> selection) {
		this.readers = IntStream.rangeClosed(1, inputs.size())
			.filter(index -> selection.isEmpty() || selection.contains(Integer.valueOf(index)))
			.mapToObj(index -> inputs.get(index-1))
			.map(input -> {
				try {
					return new DefaultLineReader(input);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}})
			.collect(Collectors.toList());
	}
	
	@Override
	public boolean hasLine() throws IOException {
		return this.readers.stream()
			.anyMatch(reader -> {
				try {
					return reader.hasLine();
				} catch (IOException e) {
					throw new RuntimeException(e);
				}});
	}
	
	@Override
	public List<String> nextLineRange(List<Boolean> readingRange) throws IOException {		
		/*final List<String> lines = new ArrayList<String>();
		int index = 0;
		final Iterator<ILineInput> iterator = this.readers.iterator();
		while (iterator.hasNext()) {
			final ILineInput reader = iterator.next();
			if (readingRange.get(index).booleanValue()) {				
				lines.add(reader.nextLine());
			} else {
				lines.add(null);
			}
			index++;
		}
		return lines;*/
		return IntStream.range(0, readers.size())
			.mapToObj(index -> {
				try {
					return readingRange.get(index).booleanValue() ? readers.get(index).nextLine() : null;
				} catch (IOException e) {
					throw new RuntimeException(e);
				}})
			.collect(Collectors.toList());
	}

	@Override
	public void close() throws IOException {
		this.readers
			.forEach(reader -> {
				try {
					reader.close();
				} catch (IOException e) {
					throw new RuntimeException(e);
				}});		
	}
	
}

@@ -56,67 +56,8 @@
 on;%0A
-//import java.util.ArrayList;%0A//import java.util.Iterator;%0A
 impo
@@ -1269,382 +1269,8 @@
 %7B%09%09%0A
-%09%09/*final 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%09final ILineInput reader = iterator.next();%0A%09%09%09if (readingRange.get(index).booleanValue()) %7B%09%09%09%09%0A%09%09%09%09lines.add(reader.nextLine());%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;*/%0A
 %09%09re

Update MultiChannelLineReader.java