Class OsidStreams
java.lang.Object
net.okapia.osid.torrefacto.streams.OsidStreams
Bridges an
OsidList's checked OperationFailedException
across a Java Stream pipeline.
A Stream lambda cannot throw a checked exception, so list
operations inside a pipeline wrap an OperationFailedException
in an unchecked UncheckedOperationFailedException. Running
the pipeline inside go(java.util.function.Supplier) or
go(Runnable) catches that wrapper at the boundary and
rethrows the original checked exception, so callers see the OSID
exception they expect:
Asset asset = OsidStreams.go(() -> assets.stream()
.filter(...)
.findFirst()
.orElse(null));
This class is not instantiable.-
Method Summary
Modifier and TypeMethodDescriptionstatic voidRuns the given runnable, converting anyUncheckedOperationFailedExceptionback to a checkedOperationFailedException.static <T> TRuns the given supplier, converting anyUncheckedOperationFailedExceptionback to a checkedOperationFailedException.
-
Method Details
-
go
Runs the given supplier, converting anyUncheckedOperationFailedExceptionback to a checkedOperationFailedException.- Type Parameters:
T- the element type- Parameters:
supplier- the stream operation to execute- Returns:
- the result of the supplier
- Throws:
OperationFailedException- if the stream raised one
-
go
Runs the given runnable, converting anyUncheckedOperationFailedExceptionback to a checkedOperationFailedException.- Parameters:
runnable- the stream operation to execute- Throws:
OperationFailedException- if the stream raised one
-