Validation rule used to negate another rule.
Implements: IValidationRule
Description
The NotRule class allows you to negate a rule. Thus, when the embedded rule returns errors, then the negated rule returns no errors and vice versa.
Constructors
Creates a new validation rule and sets its values
public
NotRule(IValidationRule rule)
- rule: IValidationRule - rule to be negated.
Instance methods
validate
Validates a given value against this rule.
public
void validate(Schema path, Schema schema, Object value, List<ValidationResult> results)
- path: String - dot notation path to the value.
- schema: Schema - schema this rule is called from
- value: Object - value to be validated.
- results: List<ValidationResult> - list with validation results to add new results.
Examples
{@code
Schema schema = new Schema()
.withRule(new NotRule(
new ValueComparisonRule("EQ", 1)
));
schema.validate(1); // Result: error
schema.validate(5); // Result: no error
}