package innovimax.mixthem.operation;

import innovimax.mixthem.MixException;
import innovimax.mixthem.arguments.RuleParam;
import innovimax.mixthem.arguments.ParamValue;
import innovimax.mixthem.io.DefaultLineWriter;
import innovimax.mixthem.io.ILineOutput;
import innovimax.mixthem.io.IMultiChannelLineInput;
import innovimax.mixthem.io.InputResource;
import innovimax.mixthem.io.MultiChannelLineReader;

import java.io.IOException;
import java.io.OutputStream;
import java.util.List;
import java.util.Map;

/**
* <p>Abstract class for all line operation.</p>
* @see ILineOperation
* @author Innovimax
* @version 1.0
*/
public abstract class AbstractLineOperation extends AbstractOperation implements ILineOperation {
	
	/**
	* Constructor
 	* @param params The list of parameters (maybe empty)
	* @see innovimax.mixthem.arguments.RuleParam
	* @see innovimax.mixthem.arguments.ParamValue
	*/
	public AbstractLineOperation(final Map<RuleParam, ParamValue> params) {
		super(params);
	}

	@Override
	public void processFiles(final List<InputResource> inputs, final OutputStream output) throws MixException, IOException {
		final IMultiChannelLineInput reader = new MultiChannelLineReader(inputs);
		final ILineOutput writer = new DefaultLineWriter(output);
		final LineResult result = new LineResult(inputs.size());
		while (reader.hasLine()) {
			// read next range lines depends on last result indicators
			final List<String> lineRange = reader.nextLineRange(result.getLineReadingRange());
			// set range preserved lines from last result
			for (int i=0; i < lineRange.size(); i++) {
				if (!result.getLineReadingRange().get(i).booleanValue()) {
					lineRange.set(i, result.getRangeLine(i));
				}
			}
			// process mixing
			process(lineRange, result);
			// write mixing result if has one
			if (result.hasResult()) {
				writer.writeLine(result.getResult());
			}
		}
		reader.close();
		writer.close();
    	}

}

@@ -1722,16 +1722,46 @@
  mixing%0A
+%09%09%09if (mixable(lineRange)) %7B%0A%09
 %09%09%09proce
@@ -1783,16 +1783,17 @@
 esult);%0A
+%09
 %09%09%09// wr
@@ -1820,24 +1820,25 @@
  has one%0A%09%09%09
+%09
 if (result.h
@@ -1847,24 +1847,25 @@
 Result()) %7B%0A
+%09
 %09%09%09%09writer.w
@@ -1894,16 +1894,22 @@
 ult());%0A
+%09%09%09%09%7D%0A
 %09%09%09%7D%0A%09%09%7D
@@ -1951,12 +1951,216 @@
 ;%0A    %09%7D
+%0A%09%0A%09@Override%0A%09public boolean mixable(final List%3CString%3E lineRange) %7B%09%09%0A%09%09for (int i=0; i %3C lineRange.size(); i++) %7B%09%09%09%0A%09%09%09if (lineRange.get(i) == null) %7B%0A%09%09%09%09return false;%09%09%09%09%0A%09%09%09%7D%0A%09%09%7D%0A%09%09return true;%09%0A%09%7D
 %0A%0A%7D%0A

Update AbstractLineOperation.java