org.solidcoding.validation.api.RuleDefinitionBuilder 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.Predicate;
final class RuleDefinitionBuilder implements RuleBuilder {
private final Predicate rule;
public RuleDefinitionBuilder(Predicate rule) {
this.rule = rule;
}
public RuleBuilder and(Predicate rule) {
return this;
}
public Rule otherWiseReport(String failMessage, Object... formatArguments) {
if (formatArguments != null) {
var actualMessage = String.format(failMessage, formatArguments);
return new RuleDefinition<>(rule, actualMessage);
}
return new RuleDefinition<>(rule, failMessage);
}
}