package innovimax.mixthem.operation;

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

import java.util.Map;

/**
* <p>Alternate two characters.</p>
* @see ICharOperation
* @author Innovimax
* @version 1.0
*/
public class DefaultCharAlternation extends AbstractCharOperation {
	
	private boolean first;
	
	/**
	* Constructor
 	* @param params The list of parameters (maybe empty)
	* @see innovimax.mixthem.arguments.RuleParam
	* @see innovimax.mixthem.arguments.ParamValue
	*/
	public DefaultCharAlternation(Map<RuleParam, ParamValue> params) {
		super(params);
		this.first = true;
	}
	
	/**
 	* Returns the alternated char.
	* @param c1 The first character to alternate
 	* @param c2 The second character to alternate	
 	* @return The alternated char
 	* @throws MixException - If an mixing error occurs
 	*/
	@Override
	public int[] process(int c1, int c2) throws MixException, ProcessException {		
		int[] result = new int[1];
		result[0] = this.first ? c1 : c2;
		this.first = !this.first;
		return result;
	}

}

@@ -669,231 +669,8 @@
 %7D%0A%09%0A
-%09/**%0A %09* Returns the alternated char.%0A%09* @param c1 The first character to alternate%0A %09* @param c2 The second character to alternate%09%0A %09* @return The alternated char%0A %09* @throws MixException - If an mixing error occurs%0A %09*/%0A
 %09@Ov
@@ -785,16 +785,114 @@
 int%5B1%5D;%0A
+%09%09if (c1 == -1) %7B%0A%09%09%09result%5B0%5D = c2;%0A%09%09%7D else if (c2 == -1) %7B%0A%09%09%09result%5B0%5D = c1;%0A%09%09%7D else %7B%09%09%09%09%09%0A%09
 %09%09result
@@ -919,16 +919,17 @@
 1 : c2;%0A
+%09
 %09%09this.f
@@ -947,16 +947,23 @@
 s.first;
+%09%09%09%0A%09%09%7D
 %0A%09%09retur

update alt-char operation