com.dimajix.shaded.everit.schema.ArraySchemaValidatingVisitor Maven / Gradle / Ivy
package com.dimajix.shaded.everit.schema;
import static java.lang.String.format;
import static java.util.Objects.requireNonNull;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.function.IntFunction;
import java.util.stream.IntStream;
import com.dimajix.shaded.json.JSONArray;
class ArraySchemaValidatingVisitor extends Visitor {
private final Object subject;
private final ValidatingVisitor owner;
private JSONArray arraySubject;
private ArraySchema arraySchema;
private int subjectLength;
public ArraySchemaValidatingVisitor(Object subject, ValidatingVisitor owner) {
this.subject = subject;
this.owner = requireNonNull(owner, "owner cannot be null");
}
@Override void visitArraySchema(ArraySchema arraySchema) {
if (owner.passesTypeCheck(JSONArray.class, arraySchema.requiresArray(), arraySchema.isNullable())) {
this.arraySubject = (JSONArray) subject;
this.subjectLength = arraySubject.length();
this.arraySchema = arraySchema;
super.visitArraySchema(arraySchema);
}
}
@Override void visitMinItems(Integer minItems) {
if (minItems != null && subjectLength < minItems) {
owner.failure("expected minimum item count: " + minItems + ", found: " + subjectLength, "minItems");
}
}
@Override void visitMaxItems(Integer maxItems) {
if (maxItems != null && maxItems < subjectLength) {
owner.failure("expected maximum item count: " + maxItems + ", found: " + subjectLength, "maxItems");
}
}
@Override void visitUniqueItems(boolean uniqueItems) {
if (!uniqueItems || subjectLength == 0) {
return;
}
Collection
© 2015 - 2024 Weber Informatics LLC | Privacy Policy