Package io.atlassian.fugue
Class Checked
- java.lang.Object
-
- io.atlassian.fugue.Checked
-
public class Checked extends java.lang.ObjectHelpers to work with functions that may throw exceptions. Used withTry.- Since:
- 4.4.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceChecked.Function<A,B,E extends java.lang.Exception>Represents aChecked.Functionthat may throw an exception.static interfaceChecked.Supplier<A,E extends java.lang.Exception>Represents aChecked.Supplierthat may throw an exception.
-
Constructor Summary
Constructors Modifier Constructor Description privateChecked()
-
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 withnow(Supplier)to make it clear that the supplier is evaluated immediately.
-
-
-
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 typeB- the function return typeE- 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 typeB- the function return typeE- 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 withnow(Supplier)to make it clear that the supplier is evaluated immediately. If the evaluation needs to be delayed, usedelay(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 suppliesE- 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 suppliesE- 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 suppliesE- 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.
-
-