com.compilit.validation.VoidRuleValidatableBuilder Maven / Gradle / Ivy
package com.compilit.validation;
import com.compilit.validation.api.VoidValidationBuilder;
import java.util.function.Function;
import org.slf4j.Logger;
final class VoidRuleValidatableBuilder extends AbstractLoggingValidatable implements VoidValidationBuilder {
private final Runnable runnable;
VoidRuleValidatableBuilder(final Subject subject, final Runnable runnable) {
super(subject);
this.runnable = runnable;
}
@Override
public boolean orElseLogMessage(final Logger logger) {
final var isValid = subject.validate();
if (isValid) {
runnable.run();
}
return super.orElseLogMessage(logger);
}
@Override
public Void orElseThrow(final Function throwableFunction) {
final var isValid = subject.validate();
if (!isValid) {
throw throwableFunction.apply(subject.getMessage());
}
runnable.run();
return null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy