Interface ThrowingDoubleSupplier<X extends Throwable>
-
- Type Parameters:
X- The type of checked exception that can be thrown.
- 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 ThrowingDoubleSupplier<X extends Throwable>
Represents a supplier ofdouble-valued results. This is a checked-exception throwing equivalent ofDoubleSupplier.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description static <X extends Throwable>
ThrowingDoubleSupplier<X>checked(DoubleSupplier supplier)Returns a supplier that calls thesuppliersupplier.static <X extends Throwable>
ThrowingDoubleSupplier<X>checked(DoubleSupplier supplier, Class<X> errorType)Returns a supplier that calls thesuppliersupplier.doublegetAsDouble()Gets a result.static <X extends Throwable>
ThrowingDoubleSupplier<X>of(ThrowingDoubleSupplier<X> supplier)Factory method for turningThrowingDoubleSupplier-shaped lambdas intoThrowingDoubleSuppliers.default <E extends Throwable>
ThrowingDoubleSupplier<E>onErrorGetCheckedAsDouble(ThrowingDoubleSupplier<? extends E> fallback)Returns a supplier that calls this supplier.default DoubleSupplieronErrorGetUncheckedAsDouble(DoubleSupplier fallback)Returns a supplier that calls this supplier.default <E extends Throwable>
ThrowingDoubleSupplier<E>onErrorHandleChecked(ThrowingToDoubleFunction<? super X,? extends E> errorHandler)Returns a supplier that calls this supplier.default DoubleSupplieronErrorHandleUnchecked(ToDoubleFunction<? super X> errorHandler)Returns a supplier that calls this supplier.default DoubleSupplieronErrorReturn(double fallback)Returns a supplier that calls this supplier.default <E extends Throwable>
ThrowingDoubleSupplier<E>onErrorThrowAsChecked(Function<? super X,? extends E> errorMapper)Returns a supplier that calls this supplier.default <E extends RuntimeException>
DoubleSupplieronErrorThrowAsUnchecked(Function<? super X,? extends E> errorMapper)Returns a supplier that calls this supplier.default DoubleSupplierunchecked()Returns a supplier that applies this supplier to its input.static DoubleSupplierunchecked(ThrowingDoubleSupplier<?> supplier)Returns a supplier that calls thesuppliersupplier.
-
-
-
Method Detail
-
onErrorThrowAsChecked
default <E extends Throwable> ThrowingDoubleSupplier<E> onErrorThrowAsChecked(Function<? super X,? extends E> errorMapper)
Returns a supplier that calls this supplier. Any checked exception thrown by this supplier is transformed using the given error mapper, and the returned supplier throws the transformation result.- Type Parameters:
E- The type of checked exception to transform to.- Parameters:
errorMapper- The function to use to transform any checked exception thrown by this supplier.- Returns:
- A supplier that transforms any thrown checked exception.
- Throws:
NullPointerException- IferrorMapperisnull.
-
onErrorThrowAsUnchecked
default <E extends RuntimeException> DoubleSupplier onErrorThrowAsUnchecked(Function<? super X,? extends E> errorMapper)
Returns a supplier that calls this supplier. Any checked exception thrown by this supplier is transformed using the given error mapper, and the returned supplier throws the transformation result.- Type Parameters:
E- The type of unchecked exception to transform to.- Parameters:
errorMapper- The function to use to transform any checked exception thrown by this supplier.- Returns:
- A supplier that transforms any thrown checked exception.
- Throws:
NullPointerException- IferrorMapperisnull.
-
onErrorHandleChecked
default <E extends Throwable> ThrowingDoubleSupplier<E> onErrorHandleChecked(ThrowingToDoubleFunction<? super X,? extends E> errorHandler)
Returns a supplier that calls this supplier. Any checked exception thrown by this supplier is transformed using the given error handler, and the returned supplier returns the transformation result.- Type Parameters:
E- The type of checked exception that can be thrown by the given error handler.- Parameters:
errorHandler- The function to use to transform any checked exception thrown by this supplier.- Returns:
- A supplier that transforms any thrown checked exception.
- Throws:
NullPointerException- IferrorHandlerisnull.
-
onErrorHandleUnchecked
default DoubleSupplier onErrorHandleUnchecked(ToDoubleFunction<? super X> errorHandler)
Returns a supplier that calls this supplier. Any checked exception thrown by this supplier is transformed using the given error handler, and the returned supplier returns the transformation result.- Parameters:
errorHandler- The function to use to transform any checked exception thrown by this supplier.- Returns:
- A supplier that transforms any thrown checked exception.
- Throws:
NullPointerException- IferrorHandlerisnull.
-
onErrorGetCheckedAsDouble
default <E extends Throwable> ThrowingDoubleSupplier<E> onErrorGetCheckedAsDouble(ThrowingDoubleSupplier<? extends E> fallback)
Returns a supplier that calls this supplier. If this supplier throws any checked exception, it is discarded and the given fallback supplier is invoked.- Type Parameters:
E- The type of checked exception that can be thrown by the given fallback supplier.- Parameters:
fallback- The supplier to produce the value to return if this supplier throws any checked exception.- Returns:
- A supplier that invokes the
fallbacksupplier if this supplier throws any checked exception. - Throws:
NullPointerException- Iffallbackisnull.
-
onErrorGetUncheckedAsDouble
default DoubleSupplier onErrorGetUncheckedAsDouble(DoubleSupplier fallback)
Returns a supplier that calls this supplier. If this supplier throws any checked exception, it is discarded and the given fallback supplier is invoked.- Parameters:
fallback- The supplier to produce the value to return if this supplier throws any checked exception.- Returns:
- A supplier that invokes the
fallbacksupplier if this supplier throws any checked exception. - Throws:
NullPointerException- Iffallbackisnull.
-
onErrorReturn
default DoubleSupplier onErrorReturn(double fallback)
Returns a supplier that calls this supplier. If this supplier throws any checked exception, it is discarded and the given fallback value is returned.- Parameters:
fallback- The value to return if this supplier throws any checked exception.- Returns:
- A supplier that returns the
fallbackvalue if this supplier throws any checked exception.
-
unchecked
default DoubleSupplier unchecked()
Returns a supplier that applies this supplier to its input. Any checked exception thrown by this supplier is wrapped in anUncheckedExceptionwithout a stack trace.- Returns:
- A supplier that wraps any checked exception in an
UncheckedException.
-
of
static <X extends Throwable> ThrowingDoubleSupplier<X> of(ThrowingDoubleSupplier<X> supplier)
Factory method for turningThrowingDoubleSupplier-shaped lambdas intoThrowingDoubleSuppliers.- Type Parameters:
X- The type of checked exception that can be thrown.- Parameters:
supplier- The lambda to return asThrowingDoubleSupplier.- Returns:
- The given lambda as a
ThrowingDoubleSupplier. - Throws:
NullPointerException- Ifsupplierisnull.
-
unchecked
static DoubleSupplier unchecked(ThrowingDoubleSupplier<?> supplier)
Returns a supplier that calls thesuppliersupplier. Any checked exception thrown by thesuppliersupplier is wrapped in anUncheckedException.- Parameters:
supplier- The supplier to call when the returned supplier is invoked.- Returns:
- A supplier that wraps any checked exception in an
UncheckedException. - Throws:
NullPointerException- Iffunctionisnull.
-
checked
static <X extends Throwable> ThrowingDoubleSupplier<X> checked(DoubleSupplier supplier)
Returns a supplier that calls thesuppliersupplier. Any unchecked exception thrown by thesuppliersupplier is relayed to the caller. This method allows existingDoubleSupplierinstances to be used whereThrowingDoubleSupplieris expected.- Type Parameters:
X- The type of checked exception that can be thrown.- Parameters:
supplier- The supplier to call when the returned function is invoked.- Returns:
- A supplier that wraps any checked exception in an
UncheckedException. - Throws:
NullPointerException- Ifsupplierisnull.
-
checked
static <X extends Throwable> ThrowingDoubleSupplier<X> checked(DoubleSupplier supplier, Class<X> errorType)
Returns a supplier that calls thesuppliersupplier. AnyUncheckedExceptionthrown by thesuppliersupplier is unwrapped if its cause is an instance oferrorType, otherwise it is relayed to the caller.- Type Parameters:
X- The type of checked exception that can be thrown.- Parameters:
supplier- The supplier to call when the returned supplier is invoked.errorType- The type of checked exception that can be thrown.- Returns:
- A supplier that wraps any checked exception in an
UncheckedException. - Throws:
NullPointerException- IfsupplierorerrorTypeisnull.
-
-