
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 com.liferay.search.experiences.service
Show all versions of com.liferay.search.experiences.service
Liferay Search Experiences Service
The newest version!
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 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 - 2025 Weber Informatics LLC | Privacy Policy