org.solidcoding.validation.predicates.ObjectPredicateBuilder 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 java.util.Objects;
import java.util.function.Predicate;
public final class ObjectPredicateBuilder extends PredicateContainer {
private ObjectPredicateBuilder() {
super();
}
private ObjectPredicateBuilder(Predicate predicate) {
super();
addPredicate(predicate);
}
/**
* Checks whether the actual value is present.
* @param the type upon which the validations are tested.
* @return Predicate to continue adding rules.
*/
public static Predicate isNotNull() {
return new ObjectPredicateBuilder<>(Objects::nonNull);
}
/**
* @param clazz the class of the object to validate. This is only a compiler flag to treat T as its instance.
* @param the type upon which the validations are tested.
* @return ObjectPredicate to continue adding rules.
*/
public static GenericPredicate isA(Class clazz) {
return new ObjectPredicateBuilder<>();
}
/**
* @param clazz the class of the object to validate. This is only a compiler flag to treat T as its instance.
* @param the type upon which the validations are tested.
* @return ObjectPredicate to continue adding rules.
*/
public static GenericPredicate isAn(Class clazz) {
return isA(clazz);
}
}