Class OsidStreams

java.lang.Object
net.okapia.osid.torrefacto.streams.OsidStreams

public class OsidStreams extends Object
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 Type
    Method
    Description
    static void
    go(Runnable runnable)
    Runs the given runnable, converting any UncheckedOperationFailedException back to a checked OperationFailedException.
    static <T> T
    go(Supplier<T> supplier)
    Runs the given supplier, converting any UncheckedOperationFailedException back to a checked OperationFailedException.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • go

      public static <T> T go(Supplier<T> supplier) throws OperationFailedException
      Runs the given supplier, converting any UncheckedOperationFailedException back to a checked OperationFailedException.
      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

      public static void go(Runnable runnable) throws OperationFailedException
      Runs the given runnable, converting any UncheckedOperationFailedException back to a checked OperationFailedException.
      Parameters:
      runnable - the stream operation to execute
      Throws:
      OperationFailedException - if the stream raised one