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

org.solidcoding.validation.predicates.StringLengthConstraintPredicateBuilder 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 StringLengthConstraintPredicateBuilder implements ChainingPredicate> {

    private final PredicateContainer originalPredicate;
    private final int first;

    StringLengthConstraintPredicateBuilder(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 StringPredicate to continue adding rules.
     */
    public Predicate and(Integer second) {
        if (second > first) {
            originalPredicate.addPredicate(x -> x.length() <= second && x.length() >= first);
        } else {
            originalPredicate.addPredicate(x -> x.length() <= first && x.length() >= second);
        }
        return originalPredicate;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy