package innovimax.mixthem.operation;

import innovimax.mixthem.MixException;
import innovimax.mixthem.arguments.ParamValue;
import innovimax.mixthem.arguments.RuleParam;
import innovimax.mixthem.arguments.TokenType;
import innovimax.mixthem.io.IToken;
import innovimax.mixthem.io.ITokenRange;
import innovimax.mixthem.io.Token;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.IntStream;

/**
* <p>Zips two or more characters.</p>
* <p>Zipping stops when a character is missing.</p>
* @author Innovimax
* @version 1.0
*/
public class DefaultCharZipping extends AbstractTokenZipping {
	
	/**
	* Constructor
	* @param selection The file index selection (maybe empty)
 	* @param params The list of parameters (maybe empty)
	* @see innovimax.mixthem.arguments.RuleParam
	* @see innovimax.mixthem.arguments.ParamValue
	*/
	public DefaultCharZipping(final Set<Integer> selection, final TokenType tokenType, final Map<RuleParam, ParamValue> params) {
		super(selection, tokenType, params);
	}
	
	@Override
	public void process(final ITokenRange tokenRange, final ITokenResult result) throws MixException {
		//System.out.println("RANGE="+tokenRange.toString());
		final List<IToken> tokens = new ArrayList<IToken>();
		IntStream.range(0, tokenRange.size()).forEach(channel -> {
			if (channel > 0) {
				IntStream.range(0, this.sep.length()).forEach(index -> {
					tokens.add(Token.createCharToken((int) this.sep.charAt(index)));
				});
			}
			tokens.add(Token.createCharToken(tokenRange.getToken(channel).asCharacter()));

		});
		if (tokens.size() > 0) {
			result.setResult(tokens);
		}
	}
	
}

@@ -417,16 +417,52 @@
 il.Set;%0A
+import java.util.stream.Collectors;%0A
 import j
@@ -488,16 +488,16 @@
 Stream;%0A
-
 %0A/**%0A* %3C
@@ -1257,16 +1257,18 @@
 g());%0A%09%09
+/*
 final Li
@@ -1622,21 +1622,560 @@
 r()));%0A%0A
-
 %09%09%7D);
+*/%0A%09%09final List%3CIToken%3E tokens = IntStream.range(0, tokenRange.size())%0A%09%09%09%09.mapToObj(channel -%3E %7B%0A%09%09%09%09%09final List%3CIToken%3E subtokens = new ArrayList%3CIToken%3E();%0A%09%09%09%09%09if (channel %3E 0) %7B%0A%09%09%09%09%09%09IntStream.range(0, this.sep.length())%0A%09%09%09%09%09%09%09.forEach(index -%3E %7B%0A%09%09%09%09%09%09%09%09subtokens.add(Token.createCharToken((int) this.sep.charAt(index)));%0A%09%09%09%09%09%09%09%7D);%0A%09%09%09%09%09%7D%0A%09%09%09%09%09subtokens.add(Token.createCharToken(tokenRange.getToken(channel).asCharacter()));%0A%09%09%09%09%09return subtokens.stream();%0A%09%09%09%09%7D)%0A%09%09%09%09.flatMap(stream -%3E stream)%0A%09%09%09%09.collect(Collectors.toList());
 %0A%09%09if (t

Update char zipping