Class OnlyOneExistsRule

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

public class OnlyOneExistsRule extends Object implements IValidationRule
Validation rule that check that at exactly one of the object properties is not null.

### Example ###

 
 Schema schema = new Schema()
      .withRule(new OnlyOneExistsRule("field1", "field2"));

 schema.validate({ field1: 1, field2: "A" });     // Result: only one of properties field1, field2 must exist
 schema.validate({ field1: 1 });                  // Result: no errors
 schema.validate({ });                            // Result: only one of properties field1, field2 must exist
 
 
See Also:
  • Constructor Details

    • OnlyOneExistsRule

      public OnlyOneExistsRule(String... properties)
      Creates a new validation rule and sets its values
      Parameters:
      properties - a list of property names where at only one property must exist
  • 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.