
br.com.fluentvalidator.context.ValidationResult Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-fluent-validator Show documentation
Show all versions of java-fluent-validator Show documentation
A Java validation framework leveraging fluent interface style.
The newest version!
package br.com.fluentvalidator.context;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Optional;
import br.com.fluentvalidator.exception.ValidationException;
public final class ValidationResult {
private final boolean valid;
private final Collection errors;
/**
*
* @return
*/
public static ValidationResult ok() {
return new ValidationResult(true, new ArrayList<>());
}
/**
*
* @param messages
* @return
*/
public static ValidationResult fail(final Collection messages) {
return new ValidationResult(false, Optional.ofNullable(messages).orElse(new ArrayList<>()));
}
private ValidationResult(final boolean valid, final Collection messages) {
this.valid = valid;
errors = Collections.unmodifiableCollection(messages);
}
/**
*
* @param clazz
*/
public void isInvalidThrow(final Class clazz) {
if (!isValid()) {
throw ValidationException.create(clazz, this);
}
}
/**
*
* @return
*/
public boolean isValid() {
return valid;
}
/**
*
* @return
*/
public Collection getErrors() {
return errors;
}
@Override
public String toString() {
final StringBuilder builder = new StringBuilder();
builder.append("ValidationResult [valid=");
builder.append(valid);
builder.append(", ");
builder.append("errors=");
builder.append(errors);
builder.append("]");
return builder.toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy