Module io.jenetics.base
Package io.jenetics.internal.util
Interface Lifecycle.ExtendedCloseable<E extends Exception>
- Type Parameters:
E
- the exception thrown by theclose()
method
- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
Lifecycle.IOResources
,Lifecycle.IOValue
,Lifecycle.Resources
,Lifecycle.Value
- Enclosing class:
- Lifecycle
- 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 static interface Lifecycle.ExtendedCloseable<E extends Exception>
extends AutoCloseable
Extends the
AutoCloseable
with methods for wrapping the thrown
exception into unchecked exceptions or ignoring them.-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
static <E extends Exception>
Lifecycle.ExtendedCloseable<E>of
(Lifecycle.ThrowingRunnable<? extends E> release) Wraps a givenrelease
method and returns anLifecycle.ExtendedCloseable
.static <E extends Exception>
Lifecycle.ExtendedCloseable<E>of
(Lifecycle.ThrowingRunnable<? extends E>... releases) Create a newExtendedCloseable
object with the given initial release methods>.static <E extends Exception>
Lifecycle.ExtendedCloseable<E>of
(Collection<? extends Lifecycle.ThrowingRunnable<? extends E>> releases) Create a newExtendedCloseable
object with the given initial release methods>.default void
Calls theclose()
method and ignores every thrown exception.default void
silentClose
(Throwable previousError) Calls theclose()
method and ignores every thrown exception.default void
uncheckedClose
(Function<? super E, ? extends RuntimeException> mapper) Calls theclose()
method and wraps thrownException
into anRuntimeException
, mapped by the givenmapper
.
-
Method Details
-
close
- Specified by:
close
in interfaceAutoCloseable
- Throws:
E extends Exception
-
uncheckedClose
Calls theclose()
method and wraps thrownException
into anRuntimeException
, mapped by the givenmapper
.- Throws:
RuntimeException
- if theclose()
method throws anException
-
silentClose
Calls theclose()
method and ignores every thrown exception. -
silentClose
Calls theclose()
method and ignores every thrown exception. If the givenpreviousError
is non-null, the thrown exception is appended to the list of suppressed exceptions.- Parameters:
previousError
- the error, which triggers the close of the givencloseables
-
of
static <E extends Exception> Lifecycle.ExtendedCloseable<E> of(Lifecycle.ThrowingRunnable<? extends E> release) Wraps a givenrelease
method and returns anLifecycle.ExtendedCloseable
.- Parameters:
release
- the release method to wrap- Returns:
- a new extended closeable with the given underlying
release
method - Throws:
NullPointerException
- if the givenrelease
method isnull
-
of
static <E extends Exception> Lifecycle.ExtendedCloseable<E> of(Collection<? extends Lifecycle.ThrowingRunnable<? extends E>> releases) Create a newExtendedCloseable
object with the given initial release methods>. The given list of objects is closed in reversed order.- Parameters:
releases
- the initial release methods- Returns:
- a new closeable object which collects the given
releases
- Throws:
NullPointerException
- if one of thereleases
isnull
- See Also:
-
of
@SafeVarargs static <E extends Exception> Lifecycle.ExtendedCloseable<E> of(Lifecycle.ThrowingRunnable<? extends E>... releases) Create a newExtendedCloseable
object with the given initial release methods>. The given list of objects is closed in reversed order.- Parameters:
releases
- the release methods- Returns:
- a new closeable object which collects the given
releases
- Throws:
NullPointerException
- if one of thereleases
isnull
- See Also:
-