Record Class ValidationResult
java.lang.Object
java.lang.Record
com.pragma.archetype.domain.model.validation.ValidationResult
public record ValidationResult(boolean valid, List<String> errors, List<String> warnings)
extends Record
Result of a validation operation.
Uses Java 21 features for clean implementation.
-
Constructor Summary
ConstructorsConstructorDescriptionValidationResult(boolean valid, List<String> errors, List<String> warnings) Creates an instance of aValidationResultrecord class. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanIndicates whether some other object is "equal to" this one.errors()Returns the value of theerrorsrecord component.static ValidationResultCreates a failed validation result with a single error.static ValidationResultCreates a failed validation result with multiple errors.Gets all error messages as a single string.Gets all warning messages as a single string.Gets the first error message, or empty string if valid.final inthashCode()Returns a hash code value for this object.booleanChecks if there are warnings.booleanChecks if validation failed.static ValidationResultsuccess()Creates a successful validation result.static ValidationResultsuccessWithWarnings(List<String> warnings) Creates a successful validation result with warnings.final StringtoString()Returns a string representation of this record class.booleanvalid()Returns the value of thevalidrecord component.warnings()Returns the value of thewarningsrecord component.
-
Constructor Details
-
ValidationResult
Creates an instance of aValidationResultrecord class.- Parameters:
valid- the value for thevalidrecord componenterrors- the value for theerrorsrecord componentwarnings- the value for thewarningsrecord component
-
-
Method Details
-
success
Creates a successful validation result. -
successWithWarnings
Creates a successful validation result with warnings. -
failure
Creates a failed validation result with a single error. -
failure
Creates a failed validation result with multiple errors. -
isInvalid
public boolean isInvalid()Checks if validation failed. -
hasWarnings
public boolean hasWarnings()Checks if there are warnings. -
getFirstError
Gets the first error message, or empty string if valid. -
getAllErrors
Gets all error messages as a single string. -
getAllWarnings
Gets all warning messages as a single string. -
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with '=='. -
valid
public boolean valid()Returns the value of thevalidrecord component.- Returns:
- the value of the
validrecord component
-
errors
Returns the value of theerrorsrecord component.- Returns:
- the value of the
errorsrecord component
-
warnings
Returns the value of thewarningsrecord component.- Returns:
- the value of the
warningsrecord component
-