Interface SupplierWithException<T,E extends Exception>
-
- Type Parameters:
T
- the type of results supplied by this supplierE
- the type of the potential exception of the operation
- All Superinterfaces:
ExceptionHandlerSupport<Supplier<T>,Supplier<Optional<T>>,SupplierWithException<T,E>>
,ObjectReturnExceptionHandlerSupport<Supplier<T>,Supplier<Optional<T>>,Supplier<CompletionStage<T>>,T,SupplierWithException<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 SupplierWithException<T,E extends Exception> extends ObjectReturnExceptionHandlerSupport<Supplier<T>,Supplier<Optional<T>>,Supplier<CompletionStage<T>>,T,SupplierWithException<T,E>>
Represents a supplier of results that may thrown exception.There is no requirement that a new or distinct result be returned each time the supplier is invoked.
General contract
T get() throws E
- The functional method.- uncheck - Return a
Supplier<T>
- lift - Return a
Supplier<Optional<T>>
- ignore - Return a
Supplier<T>
- See Also:
Supplier
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default <T1> FunctionWithException<T1,T,E>
asFunction()
Converts aSupplierWithException
to aFunctionWithException
.static <T,R,E extends Exception>
FunctionWithException<T,R,E>asFunction(SupplierWithException<R,E> supplier)
Converts aSupplierWithException
to aFunctionWithException
.static <T,E extends Exception>
SupplierWithException<T,E>failing(Supplier<E> exceptionBuilder)
Returns a supplier that always throw exception.T
get()
Gets a result.default Supplier<T>
ignore()
Converts thisSupplierWithException
to a liftedSupplier
returningnull
(or the value redefined by the methodObjectReturnExceptionHandlerSupport.defaultValue()
) in case of exception.static <T,E extends Exception>
Supplier<T>ignored(SupplierWithException<T,E> supplier)
Converts aSupplierWithException
to a liftedSupplier
returningnull
in case of exception.static <T,E extends Exception>
Supplier<T>ignored(SupplierWithException<T,E> supplier, T defaultValue)
Converts aSupplierWithException
to a liftedSupplier
returning a default value in case of exception.default Supplier<Optional<T>>
lift()
Converts thisSupplierWithException
to a liftedSupplier
usingOptional
as return value.static <T,E extends Exception>
Supplier<Optional<T>>lifted(SupplierWithException<T,E> supplier)
Converts aSupplierWithException
to a liftedSupplier
usingOptional
as return value.default Supplier<CompletionStage<T>>
stage()
Convert thisSupplierWithException
to a liftedSupplier
returnCompletionStage
as return value.static <T,E extends Exception>
Supplier<CompletionStage<T>>staged(SupplierWithException<T,E> supplier)
Convert thisSupplierWithException
to a liftedSupplier
returnCompletionStage
as return value.default Supplier<T>
uncheck()
Converts thisSupplierWithException
to aSupplier
that wraps exception toRuntimeException
.static <T,E extends Exception>
Supplier<T>unchecked(SupplierWithException<T,E> supplier)
Converts aSupplierWithException
to aSupplier
that wraps exception toRuntimeException
.static <T,E extends Exception>
Supplier<T>unchecked(SupplierWithException<T,E> supplier, Function<Exception,RuntimeException> exceptionMapper)
Converts aSupplierWithException
to aSupplier
that wraps exception toRuntimeException
by using the provided mapping function.-
Methods inherited from interface ch.powerunit.extensions.exceptions.ExceptionHandlerSupport
documented, exceptionMapper
-
Methods inherited from interface ch.powerunit.extensions.exceptions.ObjectReturnExceptionHandlerSupport
defaultValue, notThrowingHandler, throwingHandler
-
-
-
-
Method Detail
-
get
T get() throws E extends Exception
Gets a result.- Returns:
- the result.
- Throws:
E
- any exceptionE extends Exception
- See Also:
Supplier.get()
-
uncheck
default Supplier<T> uncheck()
Converts thisSupplierWithException
to aSupplier
that wraps exception toRuntimeException
.- Specified by:
uncheck
in interfaceExceptionHandlerSupport<Supplier<T>,Supplier<Optional<T>>,SupplierWithException<T,E extends Exception>>
- Specified by:
uncheck
in interfaceObjectReturnExceptionHandlerSupport<Supplier<T>,Supplier<Optional<T>>,Supplier<CompletionStage<T>>,T,SupplierWithException<T,E extends Exception>>
- Returns:
- the unchecked supplier
- See Also:
unchecked(SupplierWithException)
,unchecked(SupplierWithException, Function)
-
lift
default Supplier<Optional<T>> lift()
Converts thisSupplierWithException
to a liftedSupplier
usingOptional
as return value.- Specified by:
lift
in interfaceExceptionHandlerSupport<Supplier<T>,Supplier<Optional<T>>,SupplierWithException<T,E extends Exception>>
- Specified by:
lift
in interfaceObjectReturnExceptionHandlerSupport<Supplier<T>,Supplier<Optional<T>>,Supplier<CompletionStage<T>>,T,SupplierWithException<T,E extends Exception>>
- Returns:
- the lifted supplier
- See Also:
lifted(SupplierWithException)
-
ignore
default Supplier<T> ignore()
Converts thisSupplierWithException
to a liftedSupplier
returningnull
(or the value redefined by the methodObjectReturnExceptionHandlerSupport.defaultValue()
) in case of exception.- Specified by:
ignore
in interfaceExceptionHandlerSupport<Supplier<T>,Supplier<Optional<T>>,SupplierWithException<T,E extends Exception>>
- Specified by:
ignore
in interfaceObjectReturnExceptionHandlerSupport<Supplier<T>,Supplier<Optional<T>>,Supplier<CompletionStage<T>>,T,SupplierWithException<T,E extends Exception>>
- Returns:
- the supplier that ignore error
- See Also:
ignored(SupplierWithException)
-
stage
default Supplier<CompletionStage<T>> stage()
Convert thisSupplierWithException
to a liftedSupplier
returnCompletionStage
as return value.- Specified by:
stage
in interfaceObjectReturnExceptionHandlerSupport<Supplier<T>,Supplier<Optional<T>>,Supplier<CompletionStage<T>>,T,SupplierWithException<T,E extends Exception>>
- Returns:
- the lifted supplier
- See Also:
staged(SupplierWithException)
-
failing
static <T,E extends Exception> SupplierWithException<T,E> failing(Supplier<E> exceptionBuilder)
Returns a supplier that always throw exception.- Type Parameters:
T
- the type of the return object to the operationE
- the type of the exception- Parameters:
exceptionBuilder
- the supplier to create the exception- Returns:
- an operation that always throw exception
-
unchecked
static <T,E extends Exception> Supplier<T> unchecked(SupplierWithException<T,E> supplier)
Converts aSupplierWithException
to aSupplier
that wraps exception toRuntimeException
.- Type Parameters:
T
- the type of the output object to the operationE
- the type of the potential exception- Parameters:
supplier
- to be unchecked- Returns:
- the unchecked exception
- Throws:
NullPointerException
- if supplier is null- See Also:
uncheck()
,unchecked(SupplierWithException, Function)
-
unchecked
static <T,E extends Exception> Supplier<T> unchecked(SupplierWithException<T,E> supplier, Function<Exception,RuntimeException> exceptionMapper)
Converts aSupplierWithException
to aSupplier
that wraps exception toRuntimeException
by using the provided mapping function.- Type Parameters:
T
- the type of the output object to the operationE
- the type of the potential exception- Parameters:
supplier
- the be uncheckedexceptionMapper
- a function to convert the exception to the runtime exception.- Returns:
- the unchecked exception
- Throws:
NullPointerException
- if supplier or exceptionMapper is null- See Also:
uncheck()
,unchecked(SupplierWithException)
-
lifted
static <T,E extends Exception> Supplier<Optional<T>> lifted(SupplierWithException<T,E> supplier)
Converts aSupplierWithException
to a liftedSupplier
usingOptional
as return value.- Type Parameters:
T
- the type of the output object to the functionE
- the type of the potential exception- Parameters:
supplier
- to be lifted- Returns:
- the lifted function
- Throws:
NullPointerException
- if supplier is null- See Also:
lift()
-
ignored
static <T,E extends Exception> Supplier<T> ignored(SupplierWithException<T,E> supplier)
Converts aSupplierWithException
to a liftedSupplier
returningnull
in case of exception.- Type Parameters:
T
- the type of the output object to the functionE
- the type of the potential exception- Parameters:
supplier
- to be lifted- Returns:
- the lifted supplier
- Throws:
NullPointerException
- if supplier is null- See Also:
ignore()
-
ignored
static <T,E extends Exception> Supplier<T> ignored(SupplierWithException<T,E> supplier, T defaultValue)
Converts aSupplierWithException
to a liftedSupplier
returning a default value in case of exception.- Type Parameters:
T
- the type of the output object to the functionE
- the type of the potential exception- Parameters:
supplier
- to be lifteddefaultValue
- the default value in case of exception- Returns:
- the lifted supplier
- Throws:
NullPointerException
- if supplier is null- Since:
- 3.0.0
- See Also:
ignore()
,ignored(SupplierWithException)
-
staged
static <T,E extends Exception> Supplier<CompletionStage<T>> staged(SupplierWithException<T,E> supplier)
Convert thisSupplierWithException
to a liftedSupplier
returnCompletionStage
as return value.- Type Parameters:
T
- the type of the output object to the functionE
- the type of the potential exception- Parameters:
supplier
- to be lifted- Returns:
- the lifted supplier
- Throws:
NullPointerException
- if supplier is null- See Also:
stage()
-
asFunction
static <T,R,E extends Exception> FunctionWithException<T,R,E> asFunction(SupplierWithException<R,E> supplier)
Converts aSupplierWithException
to aFunctionWithException
.- Type Parameters:
T
- the input type of the functionR
- the result type of the functionE
- the type of the potential exception- Parameters:
supplier
- the supplier to be converted- Returns:
- the function
- Throws:
NullPointerException
- if consumer is null- Since:
- 1.2.0
-
asFunction
default <T1> FunctionWithException<T1,T,E> asFunction()
Converts aSupplierWithException
to aFunctionWithException
.- Type Parameters:
T1
- the input parameter of the function- Returns:
- the function
- Since:
- 1.2.0
-
-