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 characters.</p>
* @see CharOperation
* @author Innovimax
* @version 1.0
*/
public class DefaultCharZipping extends AbstractCharOperation {
	
	private final static String DEFAULT_ZIP_SEPARATOR = "";

	/**
	* Constructor
 	* @param params The list of parameters (maybe empty)
	* @see innovimax.mixthem.arguments.RuleParam
	* @see innovimax.mixthem.arguments.ParamValue
	*/
	public DefaultCharZipping(Map<RuleParam, ParamValue> params) {
		super(params);
	}
	
	/**
 	* Returns the result of zipping two lines.
	* @param c1 The first character to zip
 	* @param c2 The second character to zip	
 	* @return The result of zipping two characters
 	* @throws MixException - If an mixing error occurs
 	*/
	@Override
	public int[] process(int c1, int c2) throws MixException {
		int[] zip = null;
		String sep = DEFAULT_ZIP_SEPARATOR;
		if (this.params.containsKey(RuleParam._ZIP_SEP)) {
			sep = this.params.get(RuleParam._ZIP_SEP).asString();
		}		
		if (c1 != -1 && c2 != -1) {
        		zip = new int[2 + sep.length()];
        		int index = 0;
        		zip[index++] = c1;
        		for (int n = 0; n < sep.length(); n++) {
				int cn = sep.codePointAt(n);
				zip[index++] = cn;
			}
        		zip[index] = c2;
		}		
		return zip;
	}

}

@@ -976,28 +976,10 @@
 on %7B
-%0A
 %09%09
-int%5B%5D zip = null;
 %0A%09%09S
@@ -1133,48 +1133,23 @@
 %7D%09%09%0A
-%09%09if (c1 != -1 && c2 != -1) %7B%0A        %09%09
+        %09int%5B%5D 
 zip 
@@ -1186,17 +1186,16 @@
        %09
-%09
 int inde
@@ -1202,33 +1202,32 @@
 x = 0;%0A        %09
-%09
 zip%5Bindex++%5D = c
@@ -1238,17 +1238,16 @@
        %09
-%09
 for (int
@@ -1279,17 +1279,16 @@
  n++) %7B%0A
-%09
 %09%09%09int c
@@ -1314,17 +1314,16 @@
 (n);%0A%09%09%09
-%09
 zip%5Binde
@@ -1335,17 +1335,16 @@
 = cn;%0A%09%09
-%09
 %7D%0A      
@@ -1346,17 +1346,16 @@
        %09
-%09
 zip%5Binde
@@ -1363,22 +1363,16 @@
 %5D = c2;%0A
-%09%09%7D%09%09%0A
 %09%09return

remove useless if