Class OrRule

java.lang.Object
org.pipservices3.commons.validate.OrRule
All Implemented Interfaces:
IValidationRule

public class OrRule extends Object implements IValidationRule
Validation rule to combine rules with OR logical operation. When one of rules returns no errors, than this rule also returns no errors. When all rules return errors, than the rule returns all errors.

### Example ###

 
 Schema schema = new Schema()
      .withRule(new OrRule(
          new ValueComparisonRule("LT", 1),
          new ValueComparisonRule("GT", 10)
      ));

 schema.validate(0);          // Result: no error
 schema.validate(5);          // Result: 5 must be less than 1 or 5 must be more than 10
 schema.validate(20);         // Result: no error
 
 
See Also:
  • Constructor Details

    • OrRule

      public OrRule(IValidationRule... rules)
      Creates a new validation rule and sets its values.
      Parameters:
      rules - a list of rules to join with OR operator
  • Method Details

    • validate

      public void validate(String path, Schema schema, Object value, List<ValidationResult> results)
      Validates a given value against this rule.
      Specified by:
      validate in interface IValidationRule
      Parameters:
      path - a dot notation path to the value.
      schema - a schema this rule is called from
      value - a value to be validated.
      results - a list with validation results to add new results.