Interface Specification<T>
-
- Type Parameters:
T- the type of the candidate object the specification applies to.
- All Known Subinterfaces:
SubstitutableSpecification<T>
- All Known Implementing Classes:
AndSpecification,FalseSpecification,IdentitySpecification,NotSpecification,OrSpecification,TrueSpecification
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
@FunctionalInterface public interface Specification<T>
ASpecificationis a pattern that is able to tell if a candidate object matches some criteria. The specification has a methodisSatisfiedBy(Object)that returns true if all criteria are met by the candidate.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default Specification<T>and(Specification<? super T> other)Compose this specification with another specification through a logical AND.static <T> Specification<T>any()Special value for an always true specification.default Predicate<T>asPredicate()Express this specification as a JavaPredicate.booleanisSatisfiedBy(T candidate)Evaluates if the candidate object passed as argument satisfies the specification.default Specification<T>negate()Negate this specification.static <T> Specification<T>none()Special value for an always false specification.default Specification<T>or(Specification<? super T> other)Compose this specification with another specification through a logical OR.
-
-
-
Method Detail
-
any
static <T> Specification<T> any()
Special value for an always true specification.- Type Parameters:
T- the type of the candidate object the specification applies to.- Returns:
- a
TrueSpecification.
-
none
static <T> Specification<T> none()
Special value for an always false specification.- Type Parameters:
T- the type of the candidate object the specification applies to.- Returns:
- a
FalseSpecification.
-
and
default Specification<T> and(Specification<? super T> other)
Compose this specification with another specification through a logical AND.- Parameters:
other- the other specification.- Returns:
- an
AndSpecificationcomposing this specification with the specification passed as argument.
-
negate
default Specification<T> negate()
Negate this specification.- Returns:
- a
NotSpecificationnegating this specification.
-
or
default Specification<T> or(Specification<? super T> other)
Compose this specification with another specification through a logical OR.- Parameters:
other- the other specification.- Returns:
- an
OrSpecificationcomposing this specification with the specification passed as argument.
-
asPredicate
default Predicate<T> asPredicate()
Express this specification as a JavaPredicate.- Returns:
- the
Predicatecorresponding to this specification.
-
isSatisfiedBy
boolean isSatisfiedBy(T candidate)
Evaluates if the candidate object passed as argument satisfies the specification.- Parameters:
candidate- the candidate object to check.- Returns:
- true if the candidate object satisfies the specification, false otherwise.
-
-