package innovimax.mixthem;

import innovimax.mixthem.arguments.Rule;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Stream;

/**
* Provides different runs for testing a rule according to the additional parameters
* @author Innovimax
* @version 1.0
*/
public class RuleRuns {
	
	final private static String DEFAULT_OUTPUT_FILE = "default";

  	/**
  	* Returns a list of test runs for the rule.
  	* @param url The URL of rule additional parameters file
  	* @return Returns a list of test runs for the rule
    	*/	
	public static List<RuleRun> getRuns(URL url) throws FileNotFoundException, IOException {
    		List<RuleRun> runs = new LinkedList<RuleRun>();
    		runs.add(new RuleRun(Collections.emptyList()));
		if (url != null) {
			File file = new File(url.getFile());			
			BufferedReader reader = Files.newBufferedReader(file.toPath(), StandardCharsets.UTF_8);
			Stream<String> entries = reader.lines();
			entries.forEach(entry -> {
				String[] parts = entry.split("\\s");
				if (parts.length > 1) {
					String suffix = parts[0];
					List<String> params = Arrays.asList(Arrays.copyOfRange(parts, 1, parts.length));
					if (suffix.equals(DEFAULT_OUTPUT_FILE)) {
						runs.add(new RuleRun(-1, null, params));
					} else {
						runs.add(new RuleRun(-1, suffix, params));
					}
				}
			});
		}
    		return runs;
  	}

}

@@ -56,20 +56,113 @@
 guments.
-Rule
+ParamValue;%0Aimport innovimax.mixthem.arguments.Rule;%0Aimport innovimax.mixthem.arguments.RuleParam
 ;%0A%0Aimpor
@@ -437,26 +437,23 @@
 va.util.
-LinkedList
+HashMap
 ;%0Aimport
@@ -463,20 +463,19 @@
 va.util.
-List
+Map
 ;%0Aimport
@@ -929,16 +929,27 @@
 getRuns(
+Rule rule, 
 URL url)
@@ -1047,16 +1047,92 @@
 Run%3E();%0A
+%09%09Map%3CRuleParam, ParamValue%3E params = new HashMap%3CRuleParam, ParamValue%3E();%0A
     %09%09ru
@@ -1154,31 +1154,14 @@
 Run(
-Collections.emptyList()
+params
 ));%0A
@@ -1498,88 +1498,468 @@
 %09%09%09%09
-List%3CString%3E params = Arrays.asList(Arrays.copyOfRange(parts, 1, parts.length));
+map.clear();%0A%09%09%09%09%09switch (rule) %7B%0A%09%09%09%09%09%09case _RANDOM_ALT_LINE:%0A%09%09%09%09%09%09%09int seed = Integer.parseInt(parts%5B1%5D);%0A%09%09%09%09%09%09%09map.put(RuleParam._RANDOM_SEED, new ParamValue(seed));%0A%09%09%09%09%09%09%09break;%0A%09%09%09%09%09%09case _JOIN:%0A%09%09%09%09%09%09%09int col = Integer.parseInt(parts%5B1%5D);%0A%09%09%09%09%09%09%09map.put(RuleParam._JOIN_COL1, new ParamValue(col));%0A%09%09%09%09%09%09%09if (parts.length %3E 2) %7B%0A%09%09%09%09%09%09%09%09col = Integer.parseInt(parts%5B2%5D);%0A%09%09%09%09%09%09%09%09map.put(RuleParam._JOIN_COL2, new ParamValue(col));%0A%09%09%09%09%09%09%09%7D%09%09%09%09%09%0A%09%09%09%09%09%7D
 %0A%09%09%09
@@ -2029,20 +2029,16 @@
 RuleRun(
--1, 
 null, pa
@@ -2090,12 +2090,8 @@
 Run(
--1, 
 suff

use map params in rule runs