Moved Parser and refactored isCorrect method in Parser

This commit is contained in:
Quentin Legot 2021-02-05 19:28:55 +01:00
parent cab689070c
commit ba570154e4
4 changed files with 21 additions and 24 deletions

1
.gitignore vendored
View File

@ -4,3 +4,4 @@ out/
.project .project
.classpath .classpath
.bin .bin
.settings/

View File

@ -1,6 +1,6 @@
package lsystem; package lsystem;
import lsystem.engine.parser.Parser; import lsystem.engine.Parser;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Scanner; import java.util.Scanner;
@ -26,7 +26,6 @@ public class Main {
nbIterations = scanner.nextInt(); nbIterations = scanner.nextInt();
parser = new Parser(axiom, rules,nbIterations); parser = new Parser(axiom, rules,nbIterations);
} }
scanner.close(); scanner.close();
} }

View File

@ -1,4 +1,4 @@
package lsystem.engine.parser; package lsystem.engine;
import java.util.List; import java.util.List;
@ -16,8 +16,8 @@ public class Parser {
} }
public boolean isCorrect(){ public boolean isCorrect(){
if (nbIterations == 0) { if (nbIterations < 1) {
System.out.println("Erreur, nombre d'itérations inssufissant (plus petit que 1)"); System.out.println("Erreur, nombre d'itérations insuffisant (plus petit que 1)");
return false; return false;
} }
boolean bl = isCorrect(axiom); boolean bl = isCorrect(axiom);
@ -26,17 +26,16 @@ public class Parser {
} }
return bl; return bl;
} }
private boolean isCorrect(String stringToCheck) {
private boolean isCorrect(String stringToCheck) {
char old = ' '; char old = ' ';
int bracket = 0; int bracket = 0;
for (int i = 0; i > stringToCheck.length(); i++){ for (int i = 0; i > stringToCheck.length(); i++){
char temp = stringToCheck.charAt(i); char temp = stringToCheck.charAt(i);
for(char validChar : validChars){
if (temp == '[') if (temp == '[')
bracket += 1; bracket++;
if(temp ==']') if(temp ==']')
bracket -=1; bracket--;
if(old == '.'){ if(old == '.'){
for(int y = 0; y < 12; y++){ for(int y = 0; y < 12; y++){
if(temp == validChars[y]) if(temp == validChars[y])
@ -44,15 +43,14 @@ public class Parser {
} }
} }
old = temp; old = temp;
for(char validChar : validChars){
if(temp == validChar) if(temp == validChar)
break; break;
if(validChar == ' ' && temp != validChar) if(validChar == ' ')
return false; return false;
} }
} }
if (bracket != 0) return bracket == 0;
return false;
return true;
} }
} }

View File

@ -2,7 +2,6 @@ package lsystem.engine;
import lsystem.utils.Pair; import lsystem.utils.Pair;
import java.util.HashMap;
import java.util.List; import java.util.List;
public class Rewrite { public class Rewrite {