Add a commmand validator.

This commit is contained in:
2023-10-29 14:13:12 +02:00
parent bc694a6e81
commit c4f5cc9582
2 changed files with 49 additions and 0 deletions
@@ -0,0 +1,22 @@
package space.kklochko.jdbc_hospital_example.cli.validators;
import java.util.regex.Pattern;
public class CommandValidator extends Validator {
String command;
String formatRegEx = "(readAll|insert|update|remove)\\s(indicator|patient|department)\\(.*\\)";
public CommandValidator(String command) {
this.command = command;
}
public boolean isValid() {
Pattern pattern = Pattern.compile(formatRegEx);
return pattern.matcher(command).matches();
}
public String getMessage() {
return "Please, check the format: `command item(arg1=value1, ...)`. Or check the `help`";
}
}