Class Validation
java.lang.Object
org.brapi.schematools.core.validiation.Validation
Provides the results of a validation
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<U> Response<U> Returns this Validation as a ResponseassertClass(Object value, List<Class<?>> classes) Checks that the provided value is one of the provided classesassertMutuallyExclusive(Object value, String... properties) Validate that only one of the provided properties is non-nullassertNotNull(Object value, String errorMessage, Object... args) Checks if the value is non-null.Gets concatenated a list of all error messages ornullif there are no errors.Gets a list of all error messages or an empty list if there are no errors.booleanisValid()Was the validation successful,<T extends Validatable>
ValidationMerge the objects to Validation, by calling theValidatable.validate()method in each object and adding any errors to this ValidationMerge the Response to Validation, by adding any errors to this Validationmerge(Validatable validatable) Merge the objects to Validation, by calling theValidatable.validate()method and adding any errors to this Validationmerge(Validatable validatable, String prefixMessage) Merge the objects to Validation, by calling theValidatable.validate()method and adding any errors to this ValidationmergeOnCondition(boolean condition, Validatable validatable) If the condition is true, merge the objects to Validation, by calling theValidatable.validate()method and adding any errors to this ValidationmergeOnCondition(boolean condition, Validatable validatable, String prefixMessage) If the condition is true, merge the objects to Validation, by calling theValidatable.validate()method and adding any errors to this Validationstatic Validationvalid()Get a valid instant of the Validation
-
Constructor Details
-
Validation
public Validation()
-
-
Method Details
-
valid
Get a valid instant of the Validation- Returns:
- a valid instant of the Validation
-
assertNotNull
Checks if the value is non-null.- Parameters:
value- the value to be testederrorMessage- the error message to be used if the value is nullargs- argument for te error message, SeeString.format(String, Object...)to see the options- Returns:
- The validation with the appended error if there was one generated.
-
assertMutuallyExclusive
Validate that only one of the provided properties is non-null- Parameters:
value- the value to be testedproperties- the array of properties to be checked- Returns:
- this Validation
-
assertClass
Checks that the provided value is one of the provided classes- Parameters:
value- the value to be checkedclasses- the list of permitted classes that the provided value must adhere to- Returns:
- this Validation
-
isValid
public boolean isValid()Was the validation successful,- Returns:
trueif the validation was successful,falseotherwise
-
merge
Merge the objects to Validation, by calling theValidatable.validate()method and adding any errors to this Validation- Parameters:
validatable- the object to be validated- Returns:
- this Validation
-
merge
Merge the Response to Validation, by adding any errors to this Validation- Parameters:
response- the object to be validated- Returns:
- this Validation
-
merge
Merge the objects to Validation, by calling theValidatable.validate()method and adding any errors to this Validation- Parameters:
validatable- the object to be validatedprefixMessage- prefix any errors with this message- Returns:
- this Validation
-
mergeOnCondition
If the condition is true, merge the objects to Validation, by calling theValidatable.validate()method and adding any errors to this Validation- Parameters:
condition- iftruemerge, otherwise don'tvalidatable- the object to be validated- Returns:
- this Validation
-
mergeOnCondition
public Validation mergeOnCondition(boolean condition, Validatable validatable, String prefixMessage) If the condition is true, merge the objects to Validation, by calling theValidatable.validate()method and adding any errors to this Validation- Parameters:
condition- iftruemerge, otherwise don'tvalidatable- the object to be validatedprefixMessage- prefix any errors with this message- Returns:
- this Validation
-
getErrorMessages
Gets a list of all error messages or an empty list if there are no errors.- Returns:
- a list of all error messages or an empty list if there are no errors.
-
getAllErrorsMessage
Gets concatenated a list of all error messages ornullif there are no errors.- Returns:
- a concatenated a list of all error messages or
nullif there are no errors.
-
merge
Merge the objects to Validation, by calling theValidatable.validate()method in each object and adding any errors to this Validation- Type Parameters:
T- the class of Validatable object- Parameters:
validatableList- the options to be validated- Returns:
- this Validation
-
asResponse
Returns this Validation as a Response- Type Parameters:
U- The type of the result- Returns:
- this Validation as a Response
-