org.everit.json.schema.ArraySchemaValidatingVisitor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of everit-json-schema Show documentation
Show all versions of everit-json-schema Show documentation
Implementation of the JSON Schema Core Draft v4 specification built with the org.json API
package org.everit.json.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 org.json.JSONArray;
class ArraySchemaValidatingVisitor extends Visitor {
private final ValidatingVisitor owner;
private JSONArray arraySubject;
private ArraySchema arraySchema;
private int subjectLength;
public ArraySchemaValidatingVisitor(ValidatingVisitor owner) {
this.owner = requireNonNull(owner, "owner cannot be null");
}
@Override
void visitArraySchema(ArraySchema arraySchema) {
owner.ifPassesTypeCheck(JSONArray.class, arraySchema.requiresArray(), arraySchema.isNullable(),
arraySubject -> {
this.arraySubject = arraySubject;
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 - 2025 Weber Informatics LLC | Privacy Policy