org.solidcoding.validation.predicates.DecimalNumberConstraintPredicate 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 DecimalNumberConstraintPredicate implements ChainingPredicate> {
private final PredicateContainer originalPredicate;
private final double first;
DecimalNumberConstraintPredicate(Double first, PredicateContainer originalPredicate) {
this.first = first;
this.originalPredicate = originalPredicate;
}
/**
* @param second the second of the (inclusive) constraints. Can be either the high constraint or the low
* constraint.
* @return DecimalNumberPredicate to continue adding rules.
*/
public Predicate and(Double second) {
if (second > first) {
originalPredicate.addPredicate(x -> x <= second && x >= first);
} else {
originalPredicate.addPredicate(x -> x <= first && x >= second);
}
return originalPredicate;
}
}