Interface PredicateWithException<T,E extends Exception>
-
- Type Parameters:
T
- the type of the input to the predicateE
- the type of the potential exception of the function
- All Superinterfaces:
ExceptionHandlerSupport<Predicate<T>,Predicate<T>,PredicateWithException<T,E>>
,PrimitiveReturnExceptionHandlerSupport<Predicate<T>,PredicateWithException<T,E>>
- 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 PredicateWithException<T,E extends Exception> extends PrimitiveReturnExceptionHandlerSupport<Predicate<T>,PredicateWithException<T,E>>
Represents a predicate (boolean-valued function) of one argument and may throw an exception.General contract
boolean test(T t) throws E
- The functional method.- uncheck - Return a
Predicate<T>
- lift - Return a
Predicate<T>
- ignore - Return a
Predicate<T>
- See Also:
Predicate
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default PredicateWithException<T,E>
and(PredicateWithException<? super T,? extends E> other)
Returns a composed predicate that represents a short-circuiting logical AND of this predicate and another.default boolean
defaultValue()
Defines the default value returned by the ignore and ignored method.static <T,E extends Exception>
PredicateWithException<T,E>failing(Supplier<E> exceptionBuilder)
Returns a predicate that always throw exception.static <T,E extends Exception>
Predicate<T>ignored(PredicateWithException<T,E> predicate)
Converts aPredicateWithException
to a liftedPredicate
returningfalse
in case of exception.static <T,E extends Exception>
Predicate<T>ignored(PredicateWithException<T,E> predicate, boolean defaultValue)
Converts aPredicateWithException
to a liftedPredicate
returning a default value in case of exception.static <T,E extends Exception>
Predicate<T>lifted(PredicateWithException<T,E> predicate)
Converts aPredicateWithException
to a liftedPredicate
returningfalse
in case of exception.default PredicateWithException<T,E>
negate()
Returns a predicate that represents the logical negation of this predicate.static <T,E extends Exception>
PredicateWithException<T,E>negate(PredicateWithException<T,E> predicate)
Negate aPredicateWithException
.default PredicateWithException<T,E>
or(PredicateWithException<? super T,? extends E> other)
Returns a composed predicate that represents a short-circuiting logical OR of this predicate and another.boolean
test(T t)
Evaluates this predicate on the given argument.static <T,E extends Exception>
Predicate<T>unchecked(PredicateWithException<T,E> predicate)
Converts aPredicateWithException
to aPredicate
that wraps exception toRuntimeException
.static <T,E extends Exception>
Predicate<T>unchecked(PredicateWithException<T,E> predicate, Function<Exception,RuntimeException> exceptionMapper)
Converts aPredicateWithException
to aPredicate
that wraps exception toRuntimeException
by using the provided mapping function.default Predicate<T>
uncheckOrIgnore(boolean uncheck)
Used internally to implements the ignore or uncheck operation.-
Methods inherited from interface ch.powerunit.extensions.exceptions.ExceptionHandlerSupport
documented, exceptionMapper
-
Methods inherited from interface ch.powerunit.extensions.exceptions.PrimitiveReturnExceptionHandlerSupport
ignore, lift, uncheck
-
-
-
-
Method Detail
-
test
boolean test(T t) throws E extends Exception
Evaluates this predicate on the given argument.- Parameters:
t
- the input argument- Returns:
true
if the input argument matches the predicate, otherwisefalse
- Throws:
E
- any exceptionE extends Exception
- See Also:
Predicate.test(Object)
-
uncheckOrIgnore
default Predicate<T> uncheckOrIgnore(boolean uncheck)
Description copied from interface:PrimitiveReturnExceptionHandlerSupport
Used internally to implements the ignore or uncheck operation.- Specified by:
uncheckOrIgnore
in interfacePrimitiveReturnExceptionHandlerSupport<T,E extends Exception>
- Parameters:
uncheck
- create unchecked version of the function when true, else ignored version.- Returns:
- the function
-
and
default PredicateWithException<T,E> and(PredicateWithException<? super T,? extends E> other)
Returns a composed predicate that represents a short-circuiting logical AND of this predicate and another. When evaluating the composed predicate, if this predicate isfalse
, then theother
predicate is not evaluated.Any exceptions thrown during evaluation of either predicate are relayed to the caller; if evaluation of this predicate throws an exception, the
other
predicate will not be evaluated.- Parameters:
other
- a predicate that will be logically-ANDed with this predicate- Returns:
- a composed predicate that represents the short-circuiting logical AND
of this predicate and the
other
predicate - Throws:
NullPointerException
- if other is null- See Also:
or(PredicateWithException)
,negate()
-
negate
default PredicateWithException<T,E> negate()
Returns a predicate that represents the logical negation of this predicate.- Returns:
- a predicate that represents the logical negation of this predicate
- See Also:
and(PredicateWithException)
,or(PredicateWithException)
-
negate
static <T,E extends Exception> PredicateWithException<T,E> negate(PredicateWithException<T,E> predicate)
Negate aPredicateWithException
.- Type Parameters:
T
- the type of the input to the predicateE
- the type of the potential exception- Parameters:
predicate
- to be negate- Returns:
- the negated predicate
- Throws:
NullPointerException
- if predicate is null- See Also:
negate()
-
or
default PredicateWithException<T,E> or(PredicateWithException<? super T,? extends E> other)
Returns a composed predicate that represents a short-circuiting logical OR of this predicate and another. When evaluating the composed predicate, if this predicate istrue
, then theother
predicate is not evaluated.Any exceptions thrown during evaluation of either predicate are relayed to the caller; if evaluation of this predicate throws an exception, the
other
predicate will not be evaluated.- Parameters:
other
- a predicate that will be logically-ORed with this predicate- Returns:
- a composed predicate that represents the short-circuiting logical OR
of this predicate and the
other
predicate - Throws:
NullPointerException
- if other is null- See Also:
and(PredicateWithException)
,negate()
-
failing
static <T,E extends Exception> PredicateWithException<T,E> failing(Supplier<E> exceptionBuilder)
Returns a predicate that always throw exception.- Type Parameters:
T
- the type of the input to the predicateE
- the type of the exception- Parameters:
exceptionBuilder
- the supplier to create the exception- Returns:
- a predicate that always throw exception
-
unchecked
static <T,E extends Exception> Predicate<T> unchecked(PredicateWithException<T,E> predicate)
Converts aPredicateWithException
to aPredicate
that wraps exception toRuntimeException
.- Type Parameters:
T
- the type of the input to the predicateE
- the type of the potential exception- Parameters:
predicate
- to be unchecked- Returns:
- the unchecked exception
- Throws:
NullPointerException
- if predicate is null- See Also:
PrimitiveReturnExceptionHandlerSupport.uncheck()
,unchecked(PredicateWithException, Function)
-
unchecked
static <T,E extends Exception> Predicate<T> unchecked(PredicateWithException<T,E> predicate, Function<Exception,RuntimeException> exceptionMapper)
Converts aPredicateWithException
to aPredicate
that wraps exception toRuntimeException
by using the provided mapping function.- Type Parameters:
T
- the type of the input object to the functionE
- the type of the potential exception- Parameters:
predicate
- the be uncheckedexceptionMapper
- a function to convert the exception to the runtime exception.- Returns:
- the unchecked exception
- Throws:
NullPointerException
- if predicate or exceptionMapper is null- See Also:
PrimitiveReturnExceptionHandlerSupport.uncheck()
,unchecked(PredicateWithException)
-
lifted
static <T,E extends Exception> Predicate<T> lifted(PredicateWithException<T,E> predicate)
Converts aPredicateWithException
to a liftedPredicate
returningfalse
in case of exception.- Type Parameters:
T
- the type of the input to the predicateE
- the type of the potential exception- Parameters:
predicate
- to be lifted- Returns:
- the lifted predicate
- Throws:
NullPointerException
- if predicate is null- See Also:
PrimitiveReturnExceptionHandlerSupport.lift()
-
ignored
static <T,E extends Exception> Predicate<T> ignored(PredicateWithException<T,E> predicate)
Converts aPredicateWithException
to a liftedPredicate
returningfalse
in case of exception.- Type Parameters:
T
- the type of the input to the predicateE
- the type of the potential exception- Parameters:
predicate
- to be lifted- Returns:
- the lifted predicate
- Throws:
NullPointerException
- if predicate is null- See Also:
PrimitiveReturnExceptionHandlerSupport.ignore()
-
ignored
static <T,E extends Exception> Predicate<T> ignored(PredicateWithException<T,E> predicate, boolean defaultValue)
Converts aPredicateWithException
to a liftedPredicate
returning a default value in case of exception.- Type Parameters:
T
- the type of the input to the predicateE
- the type of the potential exception- Parameters:
predicate
- to be lifteddefaultValue
- value in case of exception- Returns:
- the lifted predicate
- Throws:
NullPointerException
- if predicate is null- Since:
- 3.0.0
- See Also:
PrimitiveReturnExceptionHandlerSupport.ignore()
,ignored(PredicateWithException)
-
defaultValue
default boolean defaultValue()
Defines the default value returned by the ignore and ignored method.- Returns:
- the default value for the ignore/ignored method.
- Since:
- 3.0.0
-
-