public class ValidationResult extends Object
| Modifier and Type | Method and Description |
|---|---|
static ValidationResult |
fail(ErrorDescription onErrorMessage) |
String |
getErrorCode() |
String |
getErrorMessage() |
boolean |
isValid() |
static ValidationResult |
ok()
this method return a
ValidationResult which is valid. |
void |
throwIfInvalid(String myTestedParam)
This method is very handy if you'd like to catch and violation without the need of using if statements.
|
public String getErrorCode()
public String getErrorMessage()
public boolean isValid()
public static ValidationResult ok()
ValidationResult which is valid. It is normaly used by the Validation
implementations which return the ValidationResult at the end of the validation of an value.ValidationResultpublic static ValidationResult fail(ErrorDescription onErrorMessage)
onErrorMessage - is set in the returned ValidationResultValidationResult containting the error messagepublic void throwIfInvalid(String myTestedParam) throws ValidationException
ValidationResult result = validation.test(testedValue);
if (!result.isValid()) {
//do something
}
result = nextValidation.test(testedValue);
if (!result.isValid() {
// do something
}
instead you can use this method.
validation.test(testedValue).throwIfInvalid("testedValue");
nextValidation.test(otherValue).throwIfInvalid("otherValue");
Somewhere for sure you have to catch it and do something.myTestedParam - the description what was tested. It is used in the exception messageValidationException - only if the method isValid() returns falseCopyright © 2018. All rights reserved.