Package mg.emberframework.core.data
Class ModelValidationResults
java.lang.Object
mg.emberframework.core.data.ModelValidationResults
Represents the validation results for a model's fields.
This class aggregates validation outcomes for individual fields, storing them
in a map where each key is a field name and the value is a FieldValidationResult
.
- Since:
- 1.0.0
- Version:
- 1.0.0
- Author:
- Sandratra NIAINA
-
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor.ModelValidationResults
(Map<String, FieldValidationResult> exceptions) Constructs a validation result with a pre-populated map of field exceptions. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addException
(String field, Exception exception) Adds an exception to a field's validation result.void
addFieldException
(String field, FieldValidationResult fieldExceptions) Adds a complete validation result for a field.boolean
Checks if any field contains a validation exception.getFieldExceptionMessage
(String field) Retrieves the exception message for a specific field.getFieldExceptionMessage
(String field, String separator) Retrieves the exception message for a specific field with a custom separator.Gets the map of field validation results.getFieldExceptions
(String field) Retrieves or creates the validation result for a specific field.getFieldExceptionValue
(String field) Retrieves the value associated with a field's validation result.void
setFieldExceptions
(Map<String, FieldValidationResult> fieldExceptions) Sets the map of field validation results.
-
Constructor Details
-
ModelValidationResults
public ModelValidationResults()Default constructor. -
ModelValidationResults
Constructs a validation result with a pre-populated map of field exceptions.- Parameters:
exceptions
- the map of field names to their validation results
-
-
Method Details
-
containsException
public boolean containsException()Checks if any field contains a validation exception.- Returns:
- true if at least one field has an exception, false otherwise
-
getFieldExceptionMessage
Retrieves the exception message for a specific field.- Parameters:
field
- the name of the field- Returns:
- the exception message for the field, or an empty string if none exists
-
getFieldExceptionMessage
Retrieves the exception message for a specific field with a custom separator.- Parameters:
field
- the name of the fieldseparator
- the separator to use between exception messages- Returns:
- the concatenated exception messages for the field
-
getFieldExceptionValue
Retrieves the value associated with a field's validation result.- Parameters:
field
- the name of the field- Returns:
- the value of the field from its validation result
-
addException
Adds an exception to a field's validation result.- Parameters:
field
- the name of the fieldexception
- the exception to add
-
addFieldException
Adds a complete validation result for a field.- Parameters:
field
- the name of the fieldfieldExceptions
- the validation result to associate with the field
-
getFieldExceptions
Retrieves or creates the validation result for a specific field.- Parameters:
field
- the name of the field- Returns:
- the existing or new
FieldValidationResult
for the field
-
getFieldExceptions
Gets the map of field validation results.- Returns:
- the field exceptions map
-
setFieldExceptions
Sets the map of field validation results.- Parameters:
fieldExceptions
- the map to set
-