package innovimax.mixthem.operation;

import innovimax.mixthem.MixException;
import innovimax.mixthem.arguments.RuleParam;
import innovimax.mixthem.arguments.ParamValue;

import java.util.List;
import java.util.Map;

/**
* <p>Zips two or more lines.</p>
* <p>Zipping stops when a line is missing.</p>
* @see ILineOperation
* @author Innovimax
* @version 1.0
*/
public class DefaultLineZipping extends AbstractLineOperation {
	
	protected final String sep;
	
	/**
	* Constructor
 	* @param params The list of parameters (maybe empty)
	* @see innovimax.mixthem.arguments.RuleParam
	* @see innovimax.mixthem.arguments.ParamValue
	*/
	public DefaultLineZipping(final Map<RuleParam, ParamValue> params) {
		super(params);
		this.sep = params.getOrDefault(RuleParam.ZIP_SEP, ZipOperation.DEFAULT_ZIP_SEPARATOR.getValue()).asString();	
	}
	
	@Override
	public void process(final List<String> lineRange, final LineResult result) throws MixException {
		result.reset();
		//System.out.println("RANGE="+lineRange.toString());
		if (linesZipable(lineRange)) {	
			StringBuilder zip = new StringBuilder();
			int index = 0;
			for (String line : lineRange) {
				if (index > 0) {
					zip.append(this.sep);
				}
				zip.append(line);
				index++;
			}
			result.setResult(zip.toString());
		}
	}
	
	protected boolean linesZipable(final List<String> lineRange) {		
		for (int i=0; i < lineRange.size(); i++) {			
			if (lineRange.get(i) == null) {
				return false;				
			}
		}
		return true;	
	}

}

@@ -1012,44 +1012,11 @@
 ());
-%0A
 %09%09
-if (linesZipable(lineRange)) %7B%09%0A%09
+%0A
 %09%09St
@@ -1056,17 +1056,16 @@
 er();%0A%09%09
-%09
 int inde
@@ -1071,17 +1071,16 @@
 ex = 0;%0A
-%09
 %09%09for (S
@@ -1108,17 +1108,16 @@
 e) %7B%0A%09%09%09
-%09
 if (inde
@@ -1125,17 +1125,16 @@
  %3E 0) %7B%0A
-%09
 %09%09%09%09zip.
@@ -1154,20 +1154,18 @@
 ep);%0A%09%09%09
-%09
 %7D%0A
-%09
 %09%09%09zip.a
@@ -1180,17 +1180,16 @@
 ne);%0A%09%09%09
-%09
 index++;
@@ -1191,20 +1191,18 @@
 ex++;%0A%09%09
-%09
 %7D%0A
-%09
 %09%09result
@@ -1233,213 +1233,8 @@
 ));%0A
-%09%09%7D%0A%09%7D%0A%09%0A%09protected boolean linesZipable(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

Update DefaultLineZipping.java