Module com.machinezoo.noexception
Interface OptionalPredicate<T>
-
- Type Parameters:
-
T
- seePredicate
- 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 OptionalPredicate<T>
Variation ofPredicate
that returnsOptionalBoolean
instead of the raw value.OptionalPredicate
is typically obtained fromExceptionHandler.predicate(Predicate)
, in which case its return value is empty when the underlyingPredicate
throws an exception. See noexception tutorial.- See Also:
-
ExceptionHandler.predicate(Predicate)
,Predicate
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default Predicate<T>
orElse(boolean result)
Converts thisOptionalPredicate
to plainPredicate
using default value.default Predicate<T>
orElseGet(BooleanSupplier source)
OptionalBoolean
test(T t)
Variation ofPredicate.test(Object)
that returnsOptionalBoolean
.
-
-
-
Method Detail
-
test
OptionalBoolean test(T t)
Variation ofPredicate.test(Object)
that returnsOptionalBoolean
. If thisOptionalPredicate
is obtained fromExceptionHandler.predicate(Predicate)
, theOptionalBoolean
will be empty only if the underlyingPredicate
throws. Otherwise the returnedOptionalBoolean
just wraps the return value of underlyingPredicate
.- Parameters:
-
t
- seePredicate.test(Object)
- Returns:
-
OptionalBoolean
typically wrapping return value ofPredicate.test(Object)
, or an emptyOptionalBoolean
(typically signifying an exception) - See Also:
-
ExceptionHandler.predicate(Predicate)
,Predicate.test(Object)
-
orElse
default Predicate<T> orElse(boolean result)
Converts thisOptionalPredicate
to plainPredicate
using default value. The returnedPredicate
will unwrap present value from theOptionalBoolean
if possible, or returnresult
if theOptionalBoolean
is empty.- Parameters:
-
result
- default value to return instead of an emptyOptionalBoolean
- Returns:
-
plain
Predicate
that either unwrapsOptionalBoolean
or returns default value - See Also:
-
orElseGet(BooleanSupplier)
,OptionalBoolean.orElse(boolean)
-
orElseGet
default Predicate<T> orElseGet(BooleanSupplier source)
Converts thisOptionalPredicate
to plainPredicate
using fallbackBooleanSupplier
. The returnedPredicate
will unwrap present value from theOptionalBoolean
if possible, or fall back to callingsource
if theOptionalBoolean
is empty.- Parameters:
-
source
-BooleanSupplier
to query for fallback value whenOptionalBoolean
is empty - Returns:
-
plain
Predicate
that either unwrapsOptionalBoolean
or falls back tosource
- See Also:
-
orElse(boolean)
,OptionalBoolean.orElseGet(BooleanSupplier)
-
-