
org.everit.json.schema.CollectingFailureReporter 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 java.util.ArrayList;
import java.util.List;
class CollectingFailureReporter extends ValidationFailureReporter {
private List failures = new ArrayList<>(1);
CollectingFailureReporter(Schema schema) {
super(schema);
}
@Override
public void failure(ValidationException exc) {
failures.add(exc);
}
public void validationFinished() {
ValidationException.throwFor(schema, failures);
}
public ValidationException inContextOfSchema(Schema schema, Runnable task) {
int failureCountBefore = failures.size();
super.inContextOfSchema(schema, task);
int failureCountAfter = failures.size(), newFailureCount = failureCountAfter - failureCountBefore;
if (newFailureCount == 0) {
return null;
} else if (newFailureCount == 1) {
return failures.remove(failures.size() - 1);
} else {
List newFailures = new ArrayList<>(failures.subList(failureCountBefore, failures.size()));
int toBeRemoved = newFailureCount, lastIndex = failureCountAfter;
while (toBeRemoved-- > 0) {
failures.remove(--lastIndex);
}
return ValidationException.createWrappingException(schema, newFailures);
}
}
int failureCount() {
return failures.size();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy