diff --git a/.gitignore b/.gitignore index 29668e3..be008f6 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ out/ /bin/ .project .classpath -.bin \ No newline at end of file +.bin +.settings/ \ No newline at end of file diff --git a/src/lsystem/Main.java b/src/lsystem/Main.java index d769669..d5c4035 100644 --- a/src/lsystem/Main.java +++ b/src/lsystem/Main.java @@ -1,6 +1,6 @@ package lsystem; -import lsystem.engine.parser.Parser; +import lsystem.engine.Parser; import java.util.ArrayList; import java.util.List; import java.util.Scanner; @@ -26,7 +26,6 @@ public class Main { nbIterations = scanner.nextInt(); parser = new Parser(axiom, rules,nbIterations); } - scanner.close(); } diff --git a/src/lsystem/engine/parser/Parser.java b/src/lsystem/engine/Parser.java similarity index 60% rename from src/lsystem/engine/parser/Parser.java rename to src/lsystem/engine/Parser.java index 75745ff..5699a7b 100644 --- a/src/lsystem/engine/parser/Parser.java +++ b/src/lsystem/engine/Parser.java @@ -1,4 +1,4 @@ -package lsystem.engine.parser; +package lsystem.engine; import java.util.List; @@ -16,8 +16,8 @@ public class Parser { } public boolean isCorrect(){ - if (nbIterations == 0) { - System.out.println("Erreur, nombre d'itérations inssufissant (plus petit que 1)"); + if (nbIterations < 1) { + System.out.println("Erreur, nombre d'itérations insuffisant (plus petit que 1)"); return false; } boolean bl = isCorrect(axiom); @@ -26,33 +26,31 @@ public class Parser { } return bl; } - private boolean isCorrect(String stringToCheck) { + private boolean isCorrect(String stringToCheck) { char old = ' '; int bracket = 0; - for (int i =0; i>stringToCheck.length();i++){ + for (int i = 0; i > stringToCheck.length(); i++){ char temp = stringToCheck.charAt(i); - for(char validChar : validChars){ - if (temp == '[') - bracket += 1; - if(temp ==']') - bracket -=1; - if(old == '.'){ - for(int y = 0;y<12;y++){ - if(temp == validChars[y]) - return false; - } + if (temp == '[') + bracket++; + if(temp ==']') + bracket--; + if(old == '.'){ + for(int y = 0; y < 12; y++){ + if(temp == validChars[y]) + return false; } - old = temp; + } + old = temp; + for(char validChar : validChars){ if(temp == validChar) break; - if(validChar == ' ' && temp != validChar) + if(validChar == ' ') return false; } } - if (bracket != 0) - return false; - return true; + return bracket == 0; } } diff --git a/src/lsystem/engine/Rewrite.java b/src/lsystem/engine/Rewrite.java index bb2842b..4a2c74f 100644 --- a/src/lsystem/engine/Rewrite.java +++ b/src/lsystem/engine/Rewrite.java @@ -2,7 +2,6 @@ package lsystem.engine; import lsystem.utils.Pair; -import java.util.HashMap; import java.util.List; public class Rewrite {