package jcgp.backend.parser; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.util.Scanner; import jcgp.backend.function.FunctionSet; import jcgp.backend.modules.problem.Problem; public class FunctionParser { private FunctionSet functionSet; private FunctionParser(Problem problem) { this.functionSet = problem.getFunctionSet(); } public static void parseFunctions(File file, Problem problem) { FunctionParser pp = new FunctionParser(problem); FileReader fr; try { fr = new FileReader(file); } catch (FileNotFoundException e) { e.printStackTrace(); return; } Scanner in = new Scanner(fr); while (in.hasNextLine()) { String line = in.nextLine(); if (line.substring(line.length() - 1).matches("[0-9]")) { pp.parseAndSet(line.split("[^0-9]+")); } } in.close(); } private void parseAndSet(String[] splitString) { int functionIndex = Integer.parseInt(splitString[splitString.length - 1]); if (Integer.parseInt(splitString[0]) != 0) { functionSet.enableFunction(functionIndex); } else { functionSet.disableFunction(functionIndex); } } }