package de.dogfire.dqfl.error; import java.util.ArrayList; import java.util.Collections; import java.util.List; /** * Ergebnis einer DQFL-Validierung. */ public final class DqflValidationResult { private final List errors; public DqflValidationResult(final List errors) { this.errors = Collections.unmodifiableList(new ArrayList<>(errors)); } public boolean isValid() { return this.errors.stream().noneMatch(DqflError::isError); } public boolean hasWarnings() { return this.errors.stream().anyMatch(e -> !e.isError()); } public List getErrors() { return this.errors; } public List getErrorsOnly() { return this.errors.stream().filter(DqflError::isError).toList(); } public List getWarningsOnly() { return this.errors.stream().filter(e -> !e.isError()).toList(); } @Override public String toString() { if(this.isValid() && !this.hasWarnings()) { return "Validation OK"; } final StringBuilder sb = new StringBuilder("Validation "); sb.append(this.isValid() ? "OK (with warnings)" : "FAILED"); for(final DqflError error : this.errors) { sb.append("\n ").append(error); } return sb.toString(); } }