Interface Validator<T>
- Type Parameters:
T
- the type of object to validate
- All Known Implementing Classes:
ChangePasswordDtoValidator
,CreateHolidayDtoValidator
,CreateUserValidator
,EmailDtoValidator
,NewEmailDtoValidator
,NewPasswordDtoValidator
public interface Validator<T>
Generic Validator interface for validating objects of type T.
Provides static helper methods for common validation tasks such as string field validation and password validation.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Validates the given object.static void
validatePassword
(String password, String fieldName, List<String> regexs, Map<String, String> errors, int minLength) Validates a password string against multiple regex patterns and minimum length.static void
validateStringField
(String text, String regex, String message, String fieldName, Map<String, String> errors) Validates a string field against a given regex pattern.
-
Method Details
-
validate
Validates the given object. Implementations should throw an exception or handle errors as appropriate.- Parameters:
t
- the object to validate
-
validateStringField
static void validateStringField(String text, String regex, String message, String fieldName, Map<String, String> errors) Validates a string field against a given regex pattern. Checks if the string is null or empty and if it matches the regex pattern. Adds error messages to the provided errors map.- Parameters:
text
- the string value to validateregex
- the regex pattern the string must matchmessage
- the error message if the regex does not matchfieldName
- the name of the field being validated (used as key in errors map)errors
- map to collect validation errors
-
validatePassword
static void validatePassword(String password, String fieldName, List<String> regexs, Map<String, String> errors, int minLength) Validates a password string against multiple regex patterns and minimum length. Checks if the password is null or empty, verifies length, and validates presence of required character groups. Adds error messages to the provided errors map.- Parameters:
password
- the password string to validatefieldName
- the name of the password field (used as key in errors map)regexs
- list of regex patterns that the password must satisfy (e.g., lowercase, uppercase, digit, special char)errors
- map to collect validation errorsminLength
- minimum length required for the password
-