All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.solidcoding.validation.predicates.NumberConstraintPredicateBuilder Maven / Gradle / Ivy

There is a newer version: 2.0.1
Show newest version
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;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy