Class Checked

java.lang.Object
io.atlassian.fugue.Checked

public class Checked extends Object
Helpers to work with functions that may throw exceptions. Used with Try.
Since:
4.4.0
  • Constructor Details

    • Checked

      private Checked()
  • Method Details

    • lift

      public static <A, B, E extends Exception> Function<A,Try<B>> lift(Checked.Function<A,B,E> f)
      Lifts a function that potentially throws into a function that either returns a Success of the value or a failure containing the thrown exception.
      Type Parameters:
      A - the function argument type
      B - the function return type
      E - The type of exception potentially thrown
      Parameters:
      f - a function that can throw
      Returns:
      the argument function lifted into returning a Try
    • delayedLift

      public static <A, B, E extends Exception> Function<A,Try<B>> delayedLift(Checked.Function<A,B,E> f)
      Lifts a function that potentially throws into a function that either returns a delayed Try, which, when evaluated, returns a Success of the result or a failure containing the thrown exception.
      Type Parameters:
      A - the function argument type
      B - the function return type
      E - The type of exception potentially thrown
      Parameters:
      f - a function that can throw
      Returns:
      the argument function lifted into returning a delayed Try
    • of

      @Deprecated public static <A, E extends Exception> Try<A> of(Checked.Supplier<A,E> s)
      Deprecated.
      since 4.6 This is being replaced with now(Supplier) to make it clear that the supplier is evaluated immediately. If the evaluation needs to be delayed, use delay(Supplier).
      Create a new Try representing the result of a potentially exception throwing operation. If the provided supplier throws an exception this will return a failure wrapping the exception, otherwise a success of the supplied value will be returned.
      Type Parameters:
      A - the type of value s supplies
      E - The type of exception potentially thrown
      Parameters:
      s - a supplier that may throw an exception
      Returns:
      If s throws an exception this will return a failure wrapping the exception, otherwise a success of the supplied value.
    • now

      public static <A, E extends Exception> Try<A> now(Checked.Supplier<A,E> s)
      Create a new Try representing the result of a potentially exception throwing operation. The provided supplier is evaluated immediately. If the provided supplier throws an exception this will return a failure wrapping the exception, otherwise a success of the supplied value will be returned.
      Type Parameters:
      A - the type of value s supplies
      E - The type of exception potentially thrown
      Parameters:
      s - a supplier that may throw an exception
      Returns:
      If s throws an exception this will return a failure wrapping the exception, otherwise a success of the supplied value.
    • delay

      public static <A, E extends Exception> Try<A> delay(Checked.Supplier<A,E> s)
      Create a new delayed Try representing a delayed evaluation of a potentially exception throwing operation. The provided supplier is only called when the delayed Try is evaluated. The provided supplier is called only once no matter how many times the returned delayed Try is evaluated. If the provided supplier throws an exception the evaluation of the delayed Try will return a failure wrapping the exception, otherwise a success of the supplied value will be returned.
      Type Parameters:
      A - the type of value s supplies
      E - The type of exception potentially thrown
      Parameters:
      s - a supplier that may throw an exception
      Returns:
      a delayed Try. If s throws an exception this, when evaluated, will return a failure wrapping the exception, otherwise a success of the supplied value.