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.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
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 Map<Rule, List<RuleRun>> runMap;

  /*
  * Creates the rule run maker.
  */
  public RuleRuns() {
    runMap = new HashMap<Rule, List<RuleRun>>();
    for (Rule rule : Rule.values()) {
      List<RuleRun> runs = new ArrayList<RuleRun>();
      if (rule.hasParams()) {
        switch (rule) {
          case _RANDOM_ALT_LINE:
            runs.add(new RuleRun(1, Collections.emptyList()));
            runs.add(new RuleRun(1, Collections.singletonList("1789")));
            break;
          case _JOIN:
	    runs.add(new RuleRun(3, "first", Collections.emptyList()));
	    runs.add(new RuleRun(3, "same", Collections.singletonList("2")));
            runs.add(new RuleRun(3, "diff", Arrays.asList("4", "3")));			
            break;
	}
      } else {
        runs.add(new RuleRun(Collections.emptyList()));
      }
      runMap.put(rule, runs);
    }
  }

  /**
  * Returns a list of test runs for the rule.
  * @param rule The rule to test
  * @return Returns a list of test runs for the rule
    */	
  public List<RuleRun> getRuns(Rule rule) {
    return runMap.get(rule);
  }

  	/**
  	* Returns a list of test runs for the rule.
  	* @param params The URL of rule additional parameters file
  	* @return Returns a list of test runs for the rule
    	*/	
	public List<RuleRun> getRuns(URL params) throws FileNotFoundException, IOException {
    		List<RuleRun> runs = new LinkedList<RuleRun>();
    		runs.add(new RuleRun(Collections.emptyList()));
		if (params != null) {
			File file = new File(params.getFile());			
			BufferedReader reader = Files.newBufferedReader(file.toPath(), StandardCharsets.UTF_8);
			Stream<String> entries = reader.lines();
			entries.forEach(e -> System.out.println("LINE=" + e));
		}
    		return runs;
  	}

}

@@ -637,16 +637,73 @@
 leRuns %7B
+%0A%09%0A%09final private static DEFAULT_OUTPUT_FILE = %22default%22;
 %0A%0A  fina
@@ -2392,43 +2392,378 @@
 ch(e
- -%3E System.out.println(%22LINE=%22 + e)
+ntry -%3E %7B%0A%09%09%09%09String%5B%5D parts = entry.split(%22%5C%5Cs%22);%0A%09%09%09%09if (parts.length %3E 1) %7B%0A%09%09%09%09%09String suffix = parts%5B0%5D;%0A%09%09%09%09%09List%3CString%3E params = Arrays.asList(Arrays.copyOfRange(parts, 1, parts.length));%0A%09%09%09%09%09if (suffix.equals(DEFAULT_OUTPUT_FILE)) %7B%0A%09%09%09%09%09%09runs.add(new RuleRun(-1, null, params));%0A%09%09%09%09%09%7D else %7B%0A%09%09%09%09%09%09runs.add(new RuleRun(-1, suffix, params));%0A%09%09%09%09%09%7D%0A%09%09%09%09%7D%0A%09%09%09%7D
 );%0A%09

create rule runs from file