package innovimax.mixthem.operation;

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

import java.util.Map;

/**
* <p>Alternates two lines.</p>
* @see ILineOperation
* @author Innovimax
* @version 1.0
*/
public class DefaultLineAlternation extends AbstractLineOperation {
	
	/**
 	* @param params The list of parameters (maybe empty)
	* @see innovimax.mixthem.operation.RuleParam
	* @see innovimax.mixthem.operation.ParamValue
	*/
	public DefaultLineAlternation(Map<RuleParam, ParamValue> params) {
		super(params);
	}	

	/**
 	* Returns the alternated line.
	* @param line1 The first line to alternate
 	* @param line2 The second line to alternate
 	* @return The alternated line
 	* @throws MixException - If an mixing error occurs
 	*/
	@Override
	public String process(String line1, String line2) throws MixException {
    //TODO
		System.out.println(line1);
    System.out.println(line2);
		return null;
	}

}

@@ -185,16 +185,41 @@
 til.Map;
+%0Aimport java.util.Random;
 %0A%0A/**%0A* 
@@ -379,14 +379,198 @@
 n %7B%0A
-%09%0A%09/**
+%0A%09private final static int DEFAULT_RANDOM_SEED = 1789;%0A%09%0A%09private final AltMode mode;%0A%09private boolean first;%0A%09private final Random random;%0A%0A%09/**%0A%09* @param mode The alternate mode to process
 %0A %09*
@@ -620,16 +620,17 @@
 e empty)
+%09
 %0A%09* @see
@@ -750,16 +750,30 @@
 rnation(
+AltMode mode, 
 Map%3CRule
@@ -818,16 +818,240 @@
 arams);%0A
+%09%09this.mode = mode;%0A%09%09this.first = true;%0A%09%09this.random = new Random(DEFAULT_RANDOM_SEED);%0A%09%09if (this.params.containsKey(RuleParam._RANDOM_SEED)) %7B%0A%09%09%09this.random.setSeed(this.params.get(RuleParam._RANDOM_SEED).asInt());%0A%09%09%7D%0A
 %09%7D%09%0A%0A%09/*
@@ -1353,78 +1353,206 @@
 n %7B%0A
-    //TODO%0A%09%09System.out.println(line1);%0A    System.out.println(line2);
+%09%09String line = null;%0A%09%09switch (this.mode) %7B%0A%09%09%09case _RANDOM:%0A%09%09%09%09line = this.random.nextBoolean() ? line1 : line2;%0A%09%09%09%09break;%0A%09%09%09case _NORMAL:%0A%09%09%09default:%0A%09%09%09%09line = this.first ? line1 : line2;%0A%09%09%7D
 %0A%09%09r
@@ -1557,20 +1557,20 @@
 %09return 
-null
+line
 ;%0A%09%7D%0A%0A%7D%0A

implement alt-line operation