org.solidcoding.validation.api.VoidEndingValidator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of solidcoding-validation Show documentation
Show all versions of solidcoding-validation Show documentation
A small package that enables validation of (business) rules through a fluent API.
package org.solidcoding.validation.api;
import java.util.function.Function;
final class VoidEndingValidator extends AbstractLoggingValidator implements VoidValidator {
private final Runnable runnable;
VoidEndingValidator(Runnable runnable, ContinuingValidator validator) {
super(validator);
this.runnable = runnable;
}
@Override
public Void orElseThrow(Function throwableFunction) {
var isValid = validator.validate();
if (!isValid) {
throw throwableFunction.apply(validator.getMessage());
}
runnable.run();
return null;
}
}