First INIT
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
|
||||
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<DqflError> errors;
|
||||
|
||||
public DqflValidationResult(final List<DqflError> 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<DqflError> getErrors()
|
||||
{
|
||||
return this.errors;
|
||||
}
|
||||
|
||||
public List<DqflError> getErrorsOnly()
|
||||
{
|
||||
return this.errors.stream().filter(DqflError::isError).toList();
|
||||
}
|
||||
|
||||
public List<DqflError> 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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user