package innovimax.mixthem.operation;

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

import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.Map;
import java.util.List;

/**
* <p>Abstract class for all character operation.</p>
* @see ICopyOperation
* @author Innovimax
* @version 1.0
*/
public abstract class AbstractCopyOperation extends AbstractOperation implements ICopyOperation {
	
	protected final static int BUFFER_SIZE = 1024;	
	private final CopyMode copyMode;

	/**
	* Constructor
	* @param copyMode The copy mode to process
 	* @param params The list of parameters (maybe empty)
	* @see innovimax.mixthem.arguments.RuleParam
	* @see innovimax.mixthem.arguments.ParamValue
	*/
	public AbstractCopyOperation(final CopyMode copyMode, final Map<RuleParam, ParamValue> params) {
		super(params);
		this.copyMode = copyMode;
	}

	@Override
	public void processFiles(final List<InputResource> inputs, final OutputStream output) throws MixException, IOException {		
		switch(copyMode) {
			case FIRST:
				process(inputs.get(0), output);
				break;
			case SECOND:
				process(inputs.get(1), output);
				break;
			case UMPTEENTH:
				int index = params.get(RuleParam.FILE_INDEX).asInt() - 1;
				process(inputs.get(index), output);
				break;
			case ALL:
			default:
				if (params.containsKey(RuleParam.FILE_LIST)) {                    
                    			Arrays.stream(params.get(RuleParam.FILE_LIST).asIntArray())
						.mapToObj(i -> inputs.get(i-1))
						.forEach(input -> {
						try {
			 				process(input, output);
						} catch (IOException e) {
							throw new RuntimeException(e);
						}
					});
					
				} else {
					inputs.stream().forEach(input -> {
						try {
			 				process(input, output);
						} catch (IOException e) {
							throw new RuntimeException(e);
						}
					});
				}
		}
	}

}

@@ -333,16 +333,51 @@
 il.List;
+%0Aimport java.util.stream.IntStream;
 %0A%0A/**%0A* 
@@ -1472,16 +1472,46 @@
 efault:%0A
+%09%09%09%09final IntStream indexes; %0A
 %09%09%09%09if (
@@ -1556,52 +1556,24 @@
 )) %7B
-                    %0A                    %09%09%09
+%0A%09%09%09%09%09indexes = 
 Arra
@@ -1631,242 +1631,142 @@
 y())
+;
 %0A
-%09
 %09%09%09%09
-%09.mapToObj(i -%3E inputs.get(i-1))%0A%09%09%09%09%09%09.forEach(input -%3E %7B%0A%09%09%09%09%09%09try %7B%0A%09%09%09 %09%09%09%09process(input, output
+%7D else %7B%0A%09%09%09%09%09indexes = IntStream.range(1, inputs.size()
 );%0A%09%09%09%09
+%7D
 %09%09
-%7D catch (IOException e) %7B%0A%09%09%09%09%09%09%09throw new RuntimeException(e);%0A%09%09%09%09%09%09%7D%0A%09%09%09%09%09%7D);%0A%09%09%09%09%09%0A%09%09%09%09%7D else %7B%0A%09%09%09%09%09inputs.stream(
+%09%09%0A                    %09%09indexes.mapToObj(i -%3E inputs.get(i-1)
 ).fo
@@ -1782,17 +1782,16 @@
 ut -%3E %7B%0A
-%09
 %09%09%09%09%09try
@@ -1800,17 +1800,16 @@
 %0A%09%09%09 %09%09%09
-%09
 process(
@@ -1824,17 +1824,16 @@
 utput);%0A
-%09
 %09%09%09%09%09%7D c
@@ -1861,17 +1861,16 @@
 %7B%0A%09%09%09%09%09%09
-%09
 throw ne
@@ -1901,25 +1901,21 @@
 %09%09%09%09
-%09
 %7D%0A
-%09
 %09%09%09%09%7D);
-%0A
 %09%09%09%09
-%7D
 %0A%09%09%7D

Update AbstractCopyOperation.java