Class ArraySchema

java.lang.Object
org.pipservices3.commons.validate.Schema
org.pipservices3.commons.validate.ArraySchema
Direct Known Subclasses:
ProjectionParamsSchema

public class ArraySchema extends Schema
Schema to validate arrays.

### Example ###

 
 ArraySchema schema = new ArraySchema(TypeCode.String);

 schema.validate(new String[]{"A", "B", "C"});    // Result: no errors
 schema.validate(new int[] {1, 2, 3});          // Result: element type mismatch
 schema.validate("A");                // Result: type mismatch
 
 
  • Constructor Details

    • ArraySchema

      public ArraySchema()
      Creates a new instance of validation schema.
    • ArraySchema

      public ArraySchema(Object valueType)
      Creates a new instance of validation schema and sets its values.
      Parameters:
      valueType - a type of array elements. Null means that elements may have any type.
    • ArraySchema

      public ArraySchema(Object valueType, boolean required, List<IValidationRule> rules)
      Creates a new instance of validation schema and sets its values.
      Parameters:
      valueType - a type of array elements. Null means that elements may have any type.
      required - (optional) true to always require non-null values.
      rules - (optional) a list with validation rules.
  • Method Details

    • getValueType

      public Object getValueType()
      Gets the type of array elements. Null means that elements may have any type.
      Returns:
      the type of array elements.
    • setValueType

      public void setValueType(Object value)
      Sets the type of array elements. Null means that elements may have any type.
      Parameters:
      value - a type of array elements.
    • performValidation

      protected void performValidation(String path, Object value, List<ValidationResult> results)
      Validates a given value against the schema and configured validation rules.
      Overrides:
      performValidation in class Schema
      Parameters:
      path - a dot notation path to the value.
      value - a value to be validated.
      results - a list with validation results to add new results.