クラス Try

java.lang.Object
org.nkjmlab.util.java.function.Try

public final class Try extends Object
  • メソッドの詳細

    • createBiConsumer

      public static <T, S> BiConsumer<T,S> createBiConsumer(Try.ThrowableBiConsumer<T,S> onTry, Consumer<Exception> exceptionConsumer)
      型パラメータ:
      T -
      S -
      パラメータ:
      onTry -
      exceptionConsumer -
      戻り値:
    • createBiConsumerWithThrow

      public static <T, S, X extends RuntimeException> BiConsumer<T,S> createBiConsumerWithThrow(Try.ThrowableBiConsumer<T,S> onTry, Function<Exception,? extends X> exeptionThrower) throws X
      型パラメータ:
      T -
      S -
      X -
      パラメータ:
      onTry -
      exeptionThrower -
      戻り値:
      例外:
      X
    • createConsumer

      public static <T, R> Consumer<T> createConsumer(Try.ThrowableConsumer<T> onTry, Consumer<Exception> exceptionConsumer)
      型パラメータ:
      T -
      R -
      パラメータ:
      onTry -
      exceptionConsumer -
      戻り値:
    • createConsumerWithThrow

      public static <T, X extends RuntimeException> Consumer<T> createConsumerWithThrow(Try.ThrowableConsumer<T> onTry, Function<Exception,? extends X> exeptionThrower) throws X
      型パラメータ:
      T -
      X -
      パラメータ:
      onTry -
      exeptionThrower -
      戻り値:
      例外:
      X
    • createFunction

      public static <T, R> Function<T,R> createFunction(Try.ThrowableFunction<T,R> onTry, Function<Exception,R> exceptionHandler)
      型パラメータ:
      T -
      R -
      パラメータ:
      onTry -
      exceptionHandler -
      戻り値:
    • createFunctionWithThrow

      public static <T, R, X extends RuntimeException> Function<T,R> createFunctionWithThrow(Try.ThrowableFunction<T,R> onTry, Function<Exception,? extends X> exceptionThrower) throws X
      型パラメータ:
      T -
      R -
      X -
      パラメータ:
      onTry -
      exceptionThrower -
      戻り値:
      例外:
      X
    • createRunnable

      public static Runnable createRunnable(Try.ThrowableRunnable onTry, Consumer<Exception> exceptionConsumer)
      パラメータ:
      onTry -
      exceptionConsumer -
      戻り値:
    • createRunnableWithThrow

      public static <X extends RuntimeException> Runnable createRunnableWithThrow(Try.ThrowableRunnable onTry, Function<Exception,? extends X> exceptionThrower) throws X
      型パラメータ:
      X -
      パラメータ:
      onTry -
      exceptionThrower -
      戻り値:
      例外:
      X
    • createSupplier

      public static <T> Supplier<T> createSupplier(Try.ThrowableSupplier<T> onTry, Function<Exception,T> exceptionHandler)
      型パラメータ:
      T -
      パラメータ:
      onTry -
      exceptionHandler -
      戻り値:
    • createSupplierWithThrow

      public static <T, X extends RuntimeException> Supplier<T> createSupplierWithThrow(Try.ThrowableSupplier<T> onTry, Function<Exception,? extends X> exceptionThrower) throws X
      型パラメータ:
      T -
      X -
      パラメータ:
      onTry -
      exceptionThrower -
      戻り値:
      例外:
      X
    • getOrElse

      public static <T> T getOrElse(Try.ThrowableSupplier<T> onTry, T other)
      Tries to get a value or gets other value if an exception occurs.
      型パラメータ:
      T -
      パラメータ:
      onTry -
      other -
      戻り値:
    • getOrElseGet

      public static <T, X extends RuntimeException> T getOrElseGet(Try.ThrowableSupplier<T> onTry, Function<Exception,T> ohterSupplier)
      Tries to get a value or get other value if an exception occurs..
      型パラメータ:
      T -
      X -
      パラメータ:
      onTry -
      ohterSupplier -
      戻り値:
    • getOrElseThrow

      public static <T, X extends RuntimeException> T getOrElseThrow(Try.ThrowableSupplier<T> onTry, Function<Exception,? extends X> exceptionSupplier) throws X
      Tries to get a value or throws an exception if an exception occurs.
      型パラメータ:
      T -
      X -
      パラメータ:
      onTry -
      exceptionSupplier -
      戻り値:
      例外:
      X
    • getOrElseNull

      public static <T> T getOrElseNull(Try.ThrowableSupplier<T> onTry)
      Tries to get a value or gets null if an exception occurs.
      型パラメータ:
      T -
      パラメータ:
      onTry -
      戻り値:
    • rethrow

      public static <T extends Throwable> RuntimeException rethrow(Throwable throwable) throws T
      Rethrows an exception.
      型パラメータ:
      T -
      パラメータ:
      throwable -
      戻り値:
      例外:
      T
    • runOrElseDo

      public static void runOrElseDo(Try.ThrowableRunnable onTry, Consumer<Exception> exceptionHandler)
      Tries to run and applies the exception handler if an exception occurs.
      パラメータ:
      onTry -
      exceptionHandler -
    • runOrElseThrow

      public static <T, X extends RuntimeException> void runOrElseThrow(Try.ThrowableRunnable onTry, Function<Exception,? extends X> exceptionThrower) throws X
      Tries to run and applies the exception thrower if an exception occurs.
      型パラメータ:
      T -
      X -
      パラメータ:
      onTry -
      exceptionThrower -
      例外:
      X