package innovimax.mixthem.operation;

import innovimax.mixthem.MixException;
import innovimax.mixthem.arguments.RuleParam;
import innovimax.mixthem.arguments.ParamValue;
//import innovimax.mixthem.io.DefaultLineReader;
import innovimax.mixthem.io.DefaultLineWriter;
//import innovimax.mixthem.io.ILineInput;
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 ILineInput reader1 = new DefaultLineReader(inputs.get(0));
		final ILineInput reader2 = new DefaultLineReader(inputs.get(1));
		final ILineOutput writer = new DefaultLineWriter(output);
		final LineResult result = new LineResult();
		while (reader1.hasLine() || reader2.hasLine()) {
			final String line1 = result.readingFirstFile() ? reader1.nextLine() : result.getFirstLine();
			final String line2 = result.readingSecondFile() ? reader2.nextLine() : result.getSecondLine();
			process(line1, line2, result);
			if (result.hasResult()) {
				writer.writeLine(result.getResult());
			}
        	}
        	reader1.close();
        	reader2.close();
        	writer.close();	*/
		final IMultiChannelLineInput reader = new MultiChannelLineReader(inputs);
		final ILineOutput writer = new DefaultLineWriter(output);
		final LineResult result = new LineResult(inputs.size());
		while (reader.hasLine()) {
			final List<String> lineRange = reader.nextLineRange(result.getLineReadingRange());
			for (int i=0; i < lineRange.size(); i++) {
				if (!result.getLineReadingRange().get(i).booleanValue()) {
					lineRange.set(i, result.getRangeLine(i));
				}
			}
			process(lineRange, result);
			if (result.hasResult()) {
				writer.writeLine(result.getResult());
			}
		}
		reader.close();
		writer.close();
    	}

}

@@ -167,57 +167,8 @@
 ue;%0A
-//import innovimax.mixthem.io.DefaultLineReader;%0A
 impo
@@ -214,50 +214,8 @@
 er;%0A
-//import innovimax.mixthem.io.ILineInput;%0A
 impo
@@ -1117,696 +1117,8 @@
 n %7B%0A
-%09%09/*final ILineInput reader1 = new DefaultLineReader(inputs.get(0));%0A%09%09final ILineInput reader2 = new DefaultLineReader(inputs.get(1));%0A%09%09final ILineOutput writer = new DefaultLineWriter(output);%0A%09%09final LineResult result = new LineResult();%0A%09%09while (reader1.hasLine() %7C%7C reader2.hasLine()) %7B%0A%09%09%09final String line1 = result.readingFirstFile() ? reader1.nextLine() : result.getFirstLine();%0A%09%09%09final String line2 = result.readingSecondFile() ? reader2.nextLine() : result.getSecondLine();%0A%09%09%09process(line1, line2, result);%0A%09%09%09if (result.hasResult()) %7B%0A%09%09%09%09writer.writeLine(result.getResult());%0A%09%09%09%7D%0A        %09%7D%0A        %09reader1.close();%0A        %09reader2.close();%0A        %09writer.close();%09*/%0A
 %09%09fi
@@ -1337,16 +1337,78 @@
 ne()) %7B%0A
+%09%09%09// read next range lines depends on last result indicators%0A
 %09%09%09final
@@ -1485,16 +1485,65 @@
 nge());%0A
+%09%09%09// set range preserved lines from last result%0A
 %09%09%09for (
@@ -1701,16 +1701,37 @@
 %09%7D%0A%09%09%09%7D%0A
+%09%09%09// process mixing%0A
 %09%09%09proce
@@ -1753,16 +1753,53 @@
 esult);%0A
+%09%09%09// write mixing result if has one%0A
 %09%09%09if (r

Update AbstractLineOperation.java