org.solidcoding.validation.predicates.NumberPredicateBuilder 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;
public final class NumberPredicateBuilder extends PredicateContainer implements NumberPredicate {
private NumberPredicateBuilder() {
}
private NumberPredicateBuilder(Predicate rule) {
addPredicate(rule);
}
/**
* Checks whether the actual value is present.*
* @return Predicate to continue adding rules.
*/
public static Predicate isNotNull() {
return ObjectPredicateBuilder.isNotNull();
}
/**
* @return IntegerPredicate to continue adding rules.
*/
public static NumberPredicate is() {
return new NumberPredicateBuilder();
}
/**
* @param value the exact expected value.
* @return IntegerPredicate to continue adding rules.
*/
public static Predicate is(int value) {
return new NumberPredicateBuilder(x -> x == value);
}
/**
* @param amountOfDigits the exact amount of digits of the Integer.
* @return IntegerPredicate to continue adding rules.
*/
public static Predicate hasAmountOfDigits(int amountOfDigits) {
return new NumberPredicateBuilder(x -> String.valueOf(x).length() == amountOfDigits);
}
/**
* Checks whether the given Integers are present anywhere in the value.
*
* @param value the exact value that needs to be present in the toString of the original value.
* @param values the optional exact values that needs to be present in the toString of the original value.
* @return NumberPredicate to continue adding rules.
*/
public static Predicate contains(Integer value, Integer... values) {
return PredicateContainer.contains(value, (Object[]) values);
}
/**
* Checks whether the given Integers are not present anywhere in the value.
*
* @param value the exact value that may not be present in the toString of the original value.
* @param values the optional exact values that may not be present in the toString of the original value.
* @return NumberPredicate to continue adding rules.
*/
public static Predicate doesNotContain(Integer value, Integer... values) {
return PredicateContainer.doesNotContain(value, (Object[]) values);
}
@Override
public ChainingPredicate> between(int first) {
return new NumberConstraintPredicateBuilder(first, this);
}
}