package innovimax.mixthem.operation;

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

import java.util.Arrays;
import java.util.Map;
import java.util.stream.IntStream;

/**
* <p>Alternate two characters.</p>
* @see ICharOperation
* @author Innovimax
* @version 1.0
*/
public class DefaultCharAlternation extends AbstractCharOperation {
	
	private boolean odd;
	
	/**
	* 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.odd = true;
	}
	
	@Override
	public IntStream process(int c1, int c2) throws MixException {		
		int[] result = new int[1];
		if (c1 == -1) {
			result[0] = c2;
		} else if (c2 == -1) {
			result[0] = c1;
		} else {					
			result[0] = this.odd ? c1 : c2;
			this.odd = !this.odd;			
		}
		return Arrays.stream(result);
	}

}

@@ -744,18 +744,8 @@
 lic 
-IntStream 
 proc
@@ -762,16 +762,35 @@
 , int c2
+, CharResult result
 ) throws
@@ -804,18 +804,34 @@
 eption %7B
+%0A
 %09%09
+result.reset();
 %0A%09%09int%5B%5D
@@ -831,22 +831,21 @@
 %09%09int%5B%5D 
-result
+array
  = new i
@@ -868,30 +868,29 @@
 == -1) %7B%0A%09%09%09
-result
+array
 %5B0%5D = c2;%0A%09%09
@@ -911,30 +911,29 @@
 == -1) %7B%0A%09%09%09
-result
+array
 %5B0%5D = c1;%0A%09%09
@@ -949,22 +949,21 @@
 %09%09%09%09%0A%09%09%09
-result
+array
 %5B0%5D = th
@@ -1020,13 +1020,23 @@
 %09%09re
-turn 
+sult.setResult(
 Arra
@@ -1045,22 +1045,22 @@
 .stream(
-result
+array)
 );%0A%09%7D%0A%0A%7D

Update DefaultCharAlternation.java