Class PropertiesComparisonRule

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

public class PropertiesComparisonRule extends Object implements IValidationRule
Validation rule that compares two object properties.

### Example ###

 

 Schema schema = new ObjectSchema().withRule(new PropertiesComparisonRule("field1", "NE", "field2"));

 schema.validate(Map.of("field1", 1, "field2", 2)); // Result: no errors
 schema.validate(Map.of("field1", 1, "field2", 1)); // Result: field1 shall not be equal to field2
 schema.validate(Map.of()); // Result: no errors

 
 
See Also:
  • Constructor Details

    • PropertiesComparisonRule

      public PropertiesComparisonRule(String property1, String operation, String property2)
      Creates a new validation rule and sets its arguments.
      Parameters:
      property1 - a name of the first property to compare.
      operation - a comparison operation.
      property2 - a name of the second property to compare.
      See Also:
  • 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.