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 aSupplierWithExceptionto aFunctionWithException.static <T,R,E extends Exception>
FunctionWithException<T,R,E>asFunction(SupplierWithException<R,E> supplier)Converts aSupplierWithExceptionto aFunctionWithException.static <T,E extends Exception>
SupplierWithException<T,E>failing(Supplier<E> exceptionBuilder)Returns a supplier that always throw exception.Tget()Gets a result.default Supplier<T>ignore()Converts thisSupplierWithExceptionto a liftedSupplierreturningnull(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 aSupplierWithExceptionto a liftedSupplierreturningnullin case of exception.static <T,E extends Exception>
Supplier<T>ignored(SupplierWithException<T,E> supplier, T defaultValue)Converts aSupplierWithExceptionto a liftedSupplierreturning a default value in case of exception.default Supplier<Optional<T>>lift()Converts thisSupplierWithExceptionto a liftedSupplierusingOptionalas return value.static <T,E extends Exception>
Supplier<Optional<T>>lifted(SupplierWithException<T,E> supplier)Converts aSupplierWithExceptionto a liftedSupplierusingOptionalas return value.default Supplier<CompletionStage<T>>stage()Convert thisSupplierWithExceptionto a liftedSupplierreturnCompletionStageas return value.static <T,E extends Exception>
Supplier<CompletionStage<T>>staged(SupplierWithException<T,E> supplier)Convert thisSupplierWithExceptionto a liftedSupplierreturnCompletionStageas return value.default Supplier<T>uncheck()Converts thisSupplierWithExceptionto aSupplierthat wraps exception toRuntimeException.static <T,E extends Exception>
Supplier<T>unchecked(SupplierWithException<T,E> supplier)Converts aSupplierWithExceptionto aSupplierthat wraps exception toRuntimeException.static <T,E extends Exception>
Supplier<T>unchecked(SupplierWithException<T,E> supplier, Function<Exception,RuntimeException> exceptionMapper)Converts aSupplierWithExceptionto aSupplierthat wraps exception toRuntimeExceptionby 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 thisSupplierWithExceptionto aSupplierthat wraps exception toRuntimeException.- Specified by:
uncheckin interfaceExceptionHandlerSupport<Supplier<T>,Supplier<Optional<T>>,SupplierWithException<T,E extends Exception>>- Specified by:
uncheckin 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 thisSupplierWithExceptionto a liftedSupplierusingOptionalas return value.- Specified by:
liftin interfaceExceptionHandlerSupport<Supplier<T>,Supplier<Optional<T>>,SupplierWithException<T,E extends Exception>>- Specified by:
liftin 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 thisSupplierWithExceptionto a liftedSupplierreturningnull(or the value redefined by the methodObjectReturnExceptionHandlerSupport.defaultValue()) in case of exception.- Specified by:
ignorein interfaceExceptionHandlerSupport<Supplier<T>,Supplier<Optional<T>>,SupplierWithException<T,E extends Exception>>- Specified by:
ignorein 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 thisSupplierWithExceptionto a liftedSupplierreturnCompletionStageas return value.- Specified by:
stagein 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 aSupplierWithExceptionto aSupplierthat 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 aSupplierWithExceptionto aSupplierthat wraps exception toRuntimeExceptionby 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 aSupplierWithExceptionto a liftedSupplierusingOptionalas 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 aSupplierWithExceptionto a liftedSupplierreturningnullin 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 aSupplierWithExceptionto a liftedSupplierreturning 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 thisSupplierWithExceptionto a liftedSupplierreturnCompletionStageas 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 aSupplierWithExceptionto 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 aSupplierWithExceptionto aFunctionWithException.- Type Parameters:
T1- the input parameter of the function- Returns:
- the function
- Since:
- 1.2.0
-
-