Class Checked


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

      Constructors 
      Modifier Constructor Description
      private Checked()  
    • Method Summary

      All Methods Static Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static <A,​E extends java.lang.Exception>
      Try<A>
      delay​(Checked.Supplier<A,​E> s)
      Create a new delayed Try representing a delayed evaluation of a potentially exception throwing operation.
      static <A,​B,​E extends java.lang.Exception>
      java.util.function.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.
      static <A,​B,​E extends java.lang.Exception>
      java.util.function.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.
      static <A,​E extends java.lang.Exception>
      Try<A>
      now​(Checked.Supplier<A,​E> s)
      Create a new Try representing the result of a potentially exception throwing operation.
      static <A,​E extends java.lang.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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Checked

        private Checked()
    • Method Detail

      • lift

        public static <A,​B,​E extends java.lang.Exception> java.util.function.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 java.lang.Exception> java.util.function.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 java.lang.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 java.lang.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 java.lang.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.