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

org.jtwig.plural.model.limits.IntervalPredicate Maven / Gradle / Ivy

There is a newer version: 5.87.0.RELEASE
Show newest version
package org.jtwig.plural.model.limits;

import com.google.common.base.Predicate;

public class IntervalPredicate implements Predicate {
    private final Predicate leftLimit;
    private final Predicate rightLimit;

    public IntervalPredicate(Predicate leftLimit, Predicate rightLimit) {
        if (leftLimit instanceof StaticLowerLimit && rightLimit instanceof StaticUpperLimit) {
            int lowerLimit = ((StaticLowerLimit) leftLimit).getLimit();
            int upperLimit = ((StaticUpperLimit) rightLimit).getLimit();
            if (lowerLimit > upperLimit) {
                throw new IllegalArgumentException(String.format("Invalid interval starting with %d and ending in %d", lowerLimit, upperLimit));
            }
        }
        this.leftLimit = leftLimit;
        this.rightLimit = rightLimit;
    }

    @Override
    public boolean apply(Integer input) {
        return leftLimit.apply(input) && rightLimit.apply(input);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy