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 ofPredicatethat returnsOptionalBooleaninstead of the raw value.OptionalPredicateis typically obtained fromExceptionHandler.predicate(Predicate), in which case its return value is empty when the underlyingPredicatethrows 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 thisOptionalPredicateto plainPredicateusing default value.default Predicate<T>orElseGet(BooleanSupplier source)OptionalBooleantest(T t)Variation ofPredicate.test(Object)that returnsOptionalBoolean.
-
-
-
Method Detail
-
test
OptionalBoolean test(T t)
Variation ofPredicate.test(Object)that returnsOptionalBoolean. If thisOptionalPredicateis obtained fromExceptionHandler.predicate(Predicate), theOptionalBooleanwill be empty only if the underlyingPredicatethrows. Otherwise the returnedOptionalBooleanjust wraps the return value of underlyingPredicate.- Parameters:
-
t- seePredicate.test(Object) - Returns:
-
OptionalBooleantypically 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 thisOptionalPredicateto plainPredicateusing default value. The returnedPredicatewill unwrap present value from theOptionalBooleanif possible, or returnresultif theOptionalBooleanis empty.- Parameters:
-
result- default value to return instead of an emptyOptionalBoolean - Returns:
-
plain
Predicatethat either unwrapsOptionalBooleanor returns default value - See Also:
-
orElseGet(BooleanSupplier),OptionalBoolean.orElse(boolean)
-
orElseGet
default Predicate<T> orElseGet(BooleanSupplier source)
Converts thisOptionalPredicateto plainPredicateusing fallbackBooleanSupplier. The returnedPredicatewill unwrap present value from theOptionalBooleanif possible, or fall back to callingsourceif theOptionalBooleanis empty.- Parameters:
-
source-BooleanSupplierto query for fallback value whenOptionalBooleanis empty - Returns:
-
plain
Predicatethat either unwrapsOptionalBooleanor falls back tosource - See Also:
-
orElse(boolean),OptionalBoolean.orElseGet(BooleanSupplier)
-
-