package innovimax.mixthem.operation;

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

import java.util.Map;

/**
* <p>Zips two lines on a common field.</p>
* @see ILineOperation
* @author Innovimax
* @version 1.0
*/
public class DefaultLineZipping implements ILineOperation {
	
	private final static String DEFAULT_ZIP_SEPARATOR = "";

	private final Map<RuleParam, ParamValue> params;
	
	/**
 	* @param params The list of parameters (maybe empty)
	* @see innovimax.mixthem.operation.RuleParam
	* @see innovimax.mixthem.operation.ParamValue
	*/
	public DefaultLineZipping(Map<RuleParam, ParamValue> params) {
		this.params = params;
	}
	
	/**
 	* Returns the result of zipping two lines.
	* @param line1 The first line to zip
 	* @param line2 The second line to zip	
 	* @return The result of zipping two lines
 	* @throws MixException - If an mixing error occurs
 	*/
	@Override
	public String process(String line1, String line2) throws MixException {
		String zip = null;
		String sep = DEFAULT_ZIP_SEPARATOR;
		if (this.params.containsKey(RuleParam._ZIP_SEP)) {
			sep = this.params.get(RuleParam._ZIP_SEP).asString();
		}		
		if (line1 != null && line2 != null) {      			
			zip = line1 + sep + line2;
		}
		return zip;
	}

}

@@ -414,16 +414,45 @@
  = %22%22;%0A%0A
+%09private final ZipType type;%0A
 %09private
@@ -496,24 +496,81 @@
 ams;%0A%09%0A%09/**%0A
+%09* Constructor%0A%09* @param type The type of zip to process%0A
  %09* @param p
@@ -648,16 +648,60 @@
 eration.
+ZipType%0A%09* @see innovimax.mixthem.arguments.
 RulePara
@@ -728,25 +728,25 @@
 mixthem.
-operation
+arguments
 .ParamVa
@@ -780,16 +780,30 @@
 Zipping(
+ZipType type, 
 Map%3CRule
@@ -831,16 +831,36 @@
 rams) %7B%0A
+%09%09this.type = type;%0A
 %09%09this.p
@@ -1413,47 +1413,469 @@
 l) %7B
-      %09%09%09%0A%09%09%09zip = line1 + se
+%0A%09%09%09switch (this.type) %7B%0A%09%09%09%09case _LINE:%0A%09%09%09%09%09zip = line1 + sep + line2;%0A%09%09%09%09%09break;%0A%09%09%09%09case _CELL:%09%09%09%09%09%0A%09%09%09%09%09List%3CString%3E list1 = Arrays.asList(line1.split(%22%5C%5Cs%22));%0A%09%09%09%09%09List%3CString%3E list2 = Arrays.asList(line2.split(%22%5C%5Cs%22));%0A%09%09%09%09%09int index = 0;%0A%09%09%09%09%09while (index %3C list1.size() && index %3C list2.size()) %7B%09%09%09%09%09%09%0A%09%09%09%09%09%09if (index == 0) %7B%0A%09%09%09%09%09%09%09zip = %22%22;%0A%09%09%09%09%09%09%7D else %7B%0A%09%09%09%09%09%09%09zi
 p +
+=
  li
-ne2;
+st1.get(index) + sep + list2.get(index);%0A%09%09%09%09%09%09%7D%0A%09%09%09%09%09%09index++;%0A%09%09%09%09%09%7D%0A%09%09%09%7D
 %0A%09%09%7D

add zip-cell process