How to simplify the code if there are many logical operators "||"
if (Boolean.TRUE.equals(fileBeforeCompressTmp1Passport > 10485760
|| fileAfterCompressionTmp1Passport < 10240
|| fileBeforeCompressTmp1Passport < fileAfterCompressionTmp1Passport
|| fileBeforeCompressTmp1Medical > 10485760
|| fileAfterCompressionTmp1Medical < 10240
|| fileBeforeCompressTmp1Medical < fileAfterCompressionTmp1Medical
|| value.phone().toString().length() != 10
|| validationRegExp.onlyNumbersRegExp(value.phone().toString())
|| serviceJpa.existsLogisticsPersonByPhone(value.phone())
|| value.email().length() < 8
|| value.email().length() > 58
|| validationRegExp.emailValidationRegExp(value.email())
|| value.password().length() < 6
|| value.password().length() > 24
|| validationRegExp.passwordValidationRegExp(value.password())
|| value.surname().length() < 1
|| value.surname().length() > 45
|| validationRegExp.onlyLettersCyrillic(value.surname())
|| value.name().length() < 1
|| value.name().length() > 45
|| validationRegExp.onlyLettersCyrillic(value.name())
|| value.middleName().length() < 1
|| value.middleName().length() > 45
|| validationRegExp.onlyLettersCyrillic(value.middleName())
|| value.dateBirth().toString().length() != 10
|| validationRegExp.validationDateRegExp(formattedString)
|| value.numberPassport().toString().length() != 10
|| validationRegExp.onlyNumbersRegExp(value.numberPassport().toString())
|| serviceJpa.existsLogisticsPersonByNumberPassport(value.numberPassport())
|| value.region().length() != 7
|| validationRegExp.onlyLettersCyrillic(value.region())
|| value.city().length() < 2
|| value.city().length() > 25
|| validationRegExp.onlyLettersCyrillic(value.city())
) {
Files.deleteIfExists(ofPassport);
return ResponseEntity.ok(new MessageResponse(HttpStatus.OK.value(), STATIC_OK));
}
Below I show two methods, they are "emailValidationRegExp" and "passwordValidationRegExp". These methods validate the email address and password using a regular expression. "Bohemian" asked me to show them, so I show these methods.
private static final Pattern patternEmail = Pattern.compile("^[\\w.-]*@[\\w-]*+.+\\w$");
private static final Pattern patternPassword = Pattern.compile("^[0-9a-zA-Z@#$]+$");
public boolean emailValidationRegExp(String email) {
Matcher matcherEmail = patternEmail.matcher(email);
return !matcherEmail.matches();
}
public boolean passwordValidationRegExp(String password) {
Matcher matcherPassword = patternPassword.matcher(password);
return !matcherPassword.matches();
}