org.solidcoding.validation.predicates.NumberConstraintPredicateBuilder 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.predicates;
import org.solidcoding.validation.api.ChainingPredicate;
import java.util.function.Predicate;
final class NumberConstraintPredicateBuilder implements ChainingPredicate> {
private final PredicateContainer originalPredicate;
private final int first;
NumberConstraintPredicateBuilder(Integer first, PredicateContainer originalPredicate) {
this.first = first;
this.originalPredicate = originalPredicate;
}
/**
* @param second second of the constraints. Can be either the high constraint or the low
* constraint.
* @return IntegerPredicate to continue adding rules.
*/
public Predicate and(Integer second) {
if (second > first) {
originalPredicate.addPredicate(x -> x <= second && x >= first);
} else {
originalPredicate.addPredicate(x -> x <= first && x >= second);
}
return originalPredicate;
}
}