Class FunctionalUtils

java.lang.Object
software.amazon.awssdk.utils.FunctionalUtils

public final class FunctionalUtils extends Object
  • Method Details

    • runAndLogError

      public static void runAndLogError(org.slf4j.Logger log, String errorMsg, FunctionalUtils.UnsafeRunnable runnable)
      Runs a given FunctionalUtils.UnsafeRunnable and logs an error without throwing.
      Parameters:
      errorMsg - Message to log with exception thrown.
      runnable - Action to perform.
    • noOpConsumer

      public static <T> Consumer<T> noOpConsumer()
      Type Parameters:
      T - Type of object to be consumed.
      Returns:
      A Consumer that does nothing.
    • noOpRunnable

      public static Runnable noOpRunnable()
      Returns:
      A Runnable that does nothing.
    • safeConsumer

      public static <I> Consumer<I> safeConsumer(FunctionalUtils.UnsafeConsumer<I> unsafeConsumer)
      A wrapper around a Consumer that throws a checked exception.
      Parameters:
      unsafeConsumer - - something that acts like a consumer but throws an exception
      Returns:
      a consumer that is wrapped in a try-catch converting the checked exception into a runtime exception
    • safeFunction

      public static <T, R> Function<T,R> safeFunction(FunctionalUtils.UnsafeFunction<T,R> unsafeFunction)
      Takes a functional interface that throws an exception and returns a Function that deals with that exception by wrapping in a runtime exception. Useful for APIs that use the standard Java functional interfaces that don't throw checked exceptions.
      Type Parameters:
      T - Input
      R - Output
      Parameters:
      unsafeFunction - Functional interface that throws checked exception.
      Returns:
      New Function that handles checked exception.
    • safeSupplier

      public static <T> Supplier<T> safeSupplier(FunctionalUtils.UnsafeSupplier<T> unsafeSupplier)
      A wrapper around a BiConsumer that throws a checked exception.
      Parameters:
      unsafeSupplier - - something that acts like a BiConsumer but throws an exception
      Returns:
      a consumer that is wrapped in a try-catch converting the checked exception into a runtime exception
    • safeRunnable

      public static Runnable safeRunnable(FunctionalUtils.UnsafeRunnable unsafeRunnable)
      A wrapper around a Runnable that throws a checked exception.
      Parameters:
      unsafeRunnable - Something that acts like a Runnable but throws an exception
      Returns:
      A Runnable that is wrapped in a try-catch converting the checked exception into a runtime exception
    • toFunction

      public static <I, O> Function<I,O> toFunction(Supplier<O> supplier)
    • invokeSafely

      public static <T> T invokeSafely(FunctionalUtils.UnsafeSupplier<T> unsafeSupplier)
    • invokeSafely

      public static void invokeSafely(FunctionalUtils.UnsafeRunnable unsafeRunnable)