Updated rules system

This commit is contained in:
Andrea Cavalli 2018-05-09 22:54:00 +02:00
parent 43902161d2
commit b94ec86a55
3 changed files with 25 additions and 7 deletions

Binary file not shown.

View File

@ -12,7 +12,10 @@ import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.nio.file.StandardOpenOption; import java.nio.file.StandardOpenOption;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Stream;
import org.warp.picalculator.Error; import org.warp.picalculator.Error;
import org.warp.picalculator.Utils; import org.warp.picalculator.Utils;
import org.warp.picalculator.math.Function; import org.warp.picalculator.math.Function;
@ -40,12 +43,28 @@ public class RulesManager {
} }
try { try {
boolean compiledSomething = false; boolean compiledSomething = false;
final Path rulesPath = Utils.getResource("/rules.csv"); final Path defaultRulesPath = Utils.getResource("/default-rules.lst");
if (!Files.exists(rulesPath)) { if (!Files.exists(defaultRulesPath)) {
throw new FileNotFoundException("rules.csv not found!"); throw new FileNotFoundException("default-rules.lst not found!");
} }
List<String> ruleLines = Files.readAllLines(rulesPath); List<String> ruleLines = new ArrayList<String>();
ruleLines.remove(0); //Remove the headers Path rulesPath = Paths.get("rules/");
if (rulesPath.toFile().exists()) {
System.err.println("RULES EXISTS!!!!!!");
try (Stream<Path> paths = Files.walk(rulesPath)) {
paths
.filter(Files::isRegularFile)
.forEach((Path p) -> {
if (p.toString().endsWith(".java")) {
String path = rulesPath.relativize(p).toString();
path = path.substring(0, path.length() - ".java".length());
ruleLines.add(path);
System.err.println(path);
}
});
}
}
ruleLines.addAll(Files.readAllLines(defaultRulesPath));
boolean useCache = false; boolean useCache = false;
Path tDir = Paths.get(System.getProperty("java.io.tmpdir"), "WarpPi-Calculator").resolve("rules-rt"); Path tDir = Paths.get(System.getProperty("java.io.tmpdir"), "WarpPi-Calculator").resolve("rules-rt");

View File

@ -1,4 +1,3 @@
Rule file
functions/DivisionRule functions/DivisionRule
functions/EmptyNumberRule functions/EmptyNumberRule
functions/ExpressionRule functions/ExpressionRule