Top Description Inners Constructors Methods
org.junit.platform.commons.function

public abstract Class Try<V extends @Nullable Object>

extends Object
Class Inheritance
Known Direct Subclasses
org.junit.platform.commons.function.Try.Success, org.junit.platform.commons.function.Try.Failure
Annotations
@API
status:MAINTAINED
since:1.4
Static Imports
org.apiguardian.api.API.Status.EXPERIMENTAL, .API.Status.MAINTAINED

A container object which may either contain a nullable value in case of success or an exception in case of failure.

Instances of this class should be returned by methods instead of Optional when callers might want to report the exception via logging or by wrapping it in another exception at a later point in time, e.g. via getOrThrow(Function).

Moreover, it makes it particularly convenient to attach follow-up actions should the Try have been successful (cf. andThen and andThenTry) or fallback actions should it not have been (cf. orElse and orElseTry).

Since
1.4

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class
public static interface
Try.Transformer<S extends @Nullable Object, T extends @Nullable Object>

A transformer for values of type S to type T.

Constructor Summary

AccessConstructor and Description
private
Try()

Method Summary

Modifier and TypeMethod and Description
public abstract <U> Try<U>

Returns:

a succeeded or failed Try; never null
andThen
(Function<V, Try<U>>
the function to apply; must not be null
function
)

If this Try is a success, apply the supplied function to its value and return the resulting Try; if this Try is a failure, do nothing.

public abstract <U> Try<U>

Returns:

a succeeded or failed Try; never null
andThenTry
(Try.Transformer<V, U>
the transformer to try; must not be null
transformer
)

If this Try is a success, apply the supplied transformer to its value and return a new successful or failed Try depending on the transformer's outcome; if this Try is a failure, do nothing.

public static <V extends @Nullable Object> Try<V>

Returns:

a succeeded or failed Try depending on the outcome of the supplied action; never null
call
(Callable<V>
the action to try; must not be null
action
)

Call the supplied Callable and return a successful Try that contains the returned value or, in case an exception was thrown, a failed Try that contains the exception.

private static <T> T
checkNotNull(@Nullable T input, String title)

public static <V> Try<V>

Returns:

a failed Try that contains the supplied value; never null
failure
(Exception
the exception to wrap; must not be null
cause
)

Convert the supplied exception into a failed Try.

public abstract V

Returns:

the contained value, if available; potentially null
get
()

If this Try is a success, get the contained value; if this Try is a failure, throw the contained exception.

public final @NonNull V

Returns:

the contained value, if available
getNonNull
()

If this Try is a success, get the contained value; if this Try is a failure, throw the contained exception.

public final <E extends Exception> @NonNull V

Returns:

the contained value, if available and not null
getNonNullOrThrow
(Function<@Nullable Exception, E>
the transformer to be called with the contained exception, if available; must not be null
exceptionTransformer
)

If this Try is a success, get the contained value; if this Try is a failure, call the supplied Function with the contained exception and throw the resulting Exception.

public abstract <E extends Exception> V

Returns:

the contained value, if available
getOrThrow
(Function<? super Exception, E>
the transformer to be called with the contained exception, if available; must not be null
exceptionTransformer
)

If this Try is a success, get the contained value; if this Try is a failure, call the supplied Function with the contained exception and throw the resulting Exception.

public abstract Try<V>

Returns:

the same Try for method chaining
ifFailure
(Consumer<Exception>
the consumer to be called with the contained exception, if available; must not be null
causeConsumer
)

If this Try is a failure, call the supplied Consumer with the contained exception; otherwise, do nothing.

public abstract Try<V>

Returns:

the same Try for method chaining
ifSuccess
(Consumer<V>
the consumer to be called with the contained value, if available; must not be null
valueConsumer
)

If this Try is a success, call the supplied Consumer with the contained value; otherwise, do nothing.

private static <V> Try<V>
of(Callable<Try<V>> action)

public abstract Try<V>

Returns:

a succeeded or failed Try; never null
orElse
(Supplier<Try<V>>
the supplier to call; must not be null
supplier
)

If this Try is a failure, call the supplied supplier and return the resulting Try; if this Try is a success, do nothing.

public abstract Try<V>

Returns:

a succeeded or failed Try; never null
orElseTry
(Callable<V>
the action to try; must not be null
action
)

If this Try is a failure, call the supplied action and return a new successful or failed Try depending on the action's outcome; if this Try is a success, do nothing.

public static <V extends @Nullable Object> Try<V>

Returns:

a succeeded Try that contains the supplied value; never null
success
(V
the value to wrap; potentially null
value
)

Convert the supplied value into a succeeded Try.

public abstract Optional<V>

Returns:

an Optional; never null but potentially empty
toOptional
()

If this Try is a failure, return an empty Optional; if this Try is a success, wrap the contained value using Optional#ofNullable(Object).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

Tryback to summary
private Try()

Method Detail

andThenback to summary
public abstract <U> Try<U> andThen(Function<V, Try<U>> function)

If this Try is a success, apply the supplied function to its value and return the resulting Try; if this Try is a failure, do nothing.

Parameters
function:Function<V, Try<U>>

the function to apply; must not be null

Returns:Try<U>

a succeeded or failed Try; never null

andThenTryback to summary
public abstract <U> Try<U> andThenTry(Try.Transformer<V, U> transformer)

If this Try is a success, apply the supplied transformer to its value and return a new successful or failed Try depending on the transformer's outcome; if this Try is a failure, do nothing.

Parameters
transformer:Try.Transformer<V, U>

the transformer to try; must not be null

Returns:Try<U>

a succeeded or failed Try; never null

callback to summary
public static <V extends @Nullable Object> Try<V> call(Callable<V> action)

Call the supplied Callable and return a successful Try that contains the returned value or, in case an exception was thrown, a failed Try that contains the exception.

Parameters
action:Callable<V>

the action to try; must not be null

Returns:Try<V>

a succeeded or failed Try depending on the outcome of the supplied action; never null

See Also
success(Object), failure(Exception)
checkNotNullback to summary
private static <T> T checkNotNull(@Nullable T input, String title)
Annotations
@Contract:null, _ -> fail; !null, _ -> param1
failureback to summary
public static <V> Try<V> failure(Exception cause)

Convert the supplied exception into a failed Try.

Parameters
cause:Exception

the exception to wrap; must not be null

Returns:Try<V>

a failed Try that contains the supplied value; never null

getback to summary
public abstract V get() throws Exception

If this Try is a success, get the contained value; if this Try is a failure, throw the contained exception.

Returns:V

the contained value, if available; potentially null

Exceptions
Exception:
if this Try is a failure
getNonNullback to summary
public final @NonNull V getNonNull() throws Exception

If this Try is a success, get the contained value; if this Try is a failure, throw the contained exception.

Returns:@NonNull V

the contained value, if available

Annotations
@API
status:EXPERIMENTAL
since:6.0
Exceptions
Exception:
if this Try is a failure or the contained value is null
Since
6.0
getNonNullOrThrowback to summary
public final <E extends Exception> @NonNull V getNonNullOrThrow(Function<@Nullable Exception, E> exceptionTransformer) throws Function-:E

If this Try is a success, get the contained value; if this Try is a failure, call the supplied Function with the contained exception and throw the resulting Exception.

Parameters
exceptionTransformer:Function<@Nullable Exception, E>

the transformer to be called with the contained exception, if available; must not be null

Returns:@NonNull V

the contained value, if available and not null

Annotations
@API
status:EXPERIMENTAL
since:6.0
Exceptions
Function-:E:
if this Try is a failure or the contained value is null
getOrThrowback to summary
public abstract <E extends Exception> V getOrThrow(Function<? super Exception, E> exceptionTransformer) throws Function-:E

If this Try is a success, get the contained value; if this Try is a failure, call the supplied Function with the contained exception and throw the resulting Exception.

Parameters
exceptionTransformer:Function<? super Exception, E>

the transformer to be called with the contained exception, if available; must not be null

Returns:V

the contained value, if available

Exceptions
Function-:E:
if this Try is a failure
ifFailureback to summary
public abstract Try<V> ifFailure(Consumer<Exception> causeConsumer)

If this Try is a failure, call the supplied Consumer with the contained exception; otherwise, do nothing.

Parameters
causeConsumer:Consumer<Exception>

the consumer to be called with the contained exception, if available; must not be null

Returns:Try<V>

the same Try for method chaining

ifSuccessback to summary
public abstract Try<V> ifSuccess(Consumer<V> valueConsumer)

If this Try is a success, call the supplied Consumer with the contained value; otherwise, do nothing.

Parameters
valueConsumer:Consumer<V>

the consumer to be called with the contained value, if available; must not be null

Returns:Try<V>

the same Try for method chaining

ofback to summary
private static <V> Try<V> of(Callable<Try<V>> action)
orElseback to summary
public abstract Try<V> orElse(Supplier<Try<V>> supplier)

If this Try is a failure, call the supplied supplier and return the resulting Try; if this Try is a success, do nothing.

Parameters
supplier:Supplier<Try<V>>

the supplier to call; must not be null

Returns:Try<V>

a succeeded or failed Try; never null

orElseTryback to summary
public abstract Try<V> orElseTry(Callable<V> action)

If this Try is a failure, call the supplied action and return a new successful or failed Try depending on the action's outcome; if this Try is a success, do nothing.

Parameters
action:Callable<V>

the action to try; must not be null

Returns:Try<V>

a succeeded or failed Try; never null

successback to summary
public static <V extends @Nullable Object> Try<V> success(V value)

Convert the supplied value into a succeeded Try.

Parameters
value:V

the value to wrap; potentially null

Returns:Try<V>

a succeeded Try that contains the supplied value; never null

toOptionalback to summary
public abstract Optional<V> toOptional()

If this Try is a failure, return an empty Optional; if this Try is a success, wrap the contained value using Optional#ofNullable(Object).

Returns:Optional<V>

an Optional; never null but potentially empty

org.junit.platform.commons.function back to summary

private final Class Try.Failure<V extends @Nullable Object>

extends Try<V extends @Nullable Object>
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final Exception

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public <U> Try<U>
andThen(Function<V, Try<U>> function)

Implements abstract org.junit.platform.commons.function.Try.andThen.

If this Try is a success, apply the supplied function to its value and return the resulting Try; if this Try is a failure, do nothing.

public <U> Try<U>
andThenTry(Try.Transformer<V, U> transformer)

Implements abstract org.junit.platform.commons.function.Try.andThenTry.

If this Try is a success, apply the supplied transformer to its value and return a new successful or failed Try depending on the transformer's outcome; if this Try is a failure, do nothing.

public boolean
equals(Object that)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public V
get()

Implements abstract org.junit.platform.commons.function.Try.get.

If this Try is a success, get the contained value; if this Try is a failure, throw the contained exception.

public <E extends Exception> V
getOrThrow(Function<? super Exception, E> exceptionTransformer)

Implements abstract org.junit.platform.commons.function.Try.getOrThrow.

If this Try is a success, get the contained value; if this Try is a failure, call the supplied Function with the contained exception and throw the resulting Exception.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public Try<V>
ifFailure(Consumer<Exception> causeConsumer)

Implements abstract org.junit.platform.commons.function.Try.ifFailure.

If this Try is a failure, call the supplied Consumer with the contained exception; otherwise, do nothing.

public Try<V>
ifSuccess(Consumer<V> valueConsumer)

Implements abstract org.junit.platform.commons.function.Try.ifSuccess.

If this Try is a success, call the supplied Consumer with the contained value; otherwise, do nothing.

public Try<V>
orElse(Supplier<Try<V>> supplier)

Implements abstract org.junit.platform.commons.function.Try.orElse.

If this Try is a failure, call the supplied supplier and return the resulting Try; if this Try is a success, do nothing.

public Try<V>
orElseTry(Callable<V> action)

Implements abstract org.junit.platform.commons.function.Try.orElseTry.

If this Try is a failure, call the supplied action and return a new successful or failed Try depending on the action's outcome; if this Try is a success, do nothing.

public Optional<V>
toOptional()

Implements abstract org.junit.platform.commons.function.Try.toOptional.

If this Try is a failure, return an empty Optional; if this Try is a success, wrap the contained value using Optional#ofNullable(Object).

private <U> Try<U>
Inherited from org.junit.platform.commons.function.Try:
callfailuregetNonNullgetNonNullOrThrowsuccess

Field Detail

causeback to summary
private final Exception cause

Constructor Detail

Failureback to summary
pack-priv Failure(Exception cause)

Method Detail

andThenback to summary
public <U> Try<U> andThen(Function<V, Try<U>> function)

Implements abstract org.junit.platform.commons.function.Try.andThen.

Doc from org.junit.platform.commons.function.Try.andThen.

If this Try is a success, apply the supplied function to its value and return the resulting Try; if this Try is a failure, do nothing.

Annotations
@Override
andThenTryback to summary
public <U> Try<U> andThenTry(Try.Transformer<V, U> transformer)

Implements abstract org.junit.platform.commons.function.Try.andThenTry.

Doc from org.junit.platform.commons.function.Try.andThenTry.

If this Try is a success, apply the supplied transformer to its value and return a new successful or failed Try depending on the transformer's outcome; if this Try is a failure, do nothing.

Annotations
@Override
equalsback to summary
public boolean equals(Object that)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Annotations
@Override
getback to summary
public V get() throws Exception

Implements abstract org.junit.platform.commons.function.Try.get.

Doc from org.junit.platform.commons.function.Try.get.

If this Try is a success, get the contained value; if this Try is a failure, throw the contained exception.

Annotations
@Contract: -> fail
@Override
Exceptions
Exception:
if this Try is a failure
getOrThrowback to summary
public <E extends Exception> V getOrThrow(Function<? super Exception, E> exceptionTransformer) throws Function-:E

Implements abstract org.junit.platform.commons.function.Try.getOrThrow.

Doc from org.junit.platform.commons.function.Try.getOrThrow.

If this Try is a success, get the contained value; if this Try is a failure, call the supplied Function with the contained exception and throw the resulting Exception.

Annotations
@Contract:_ -> fail
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Annotations
@Override
ifFailureback to summary
public Try<V> ifFailure(Consumer<Exception> causeConsumer)

Implements abstract org.junit.platform.commons.function.Try.ifFailure.

Doc from org.junit.platform.commons.function.Try.ifFailure.

If this Try is a failure, call the supplied Consumer with the contained exception; otherwise, do nothing.

Annotations
@Override
ifSuccessback to summary
public Try<V> ifSuccess(Consumer<V> valueConsumer)

Implements abstract org.junit.platform.commons.function.Try.ifSuccess.

Doc from org.junit.platform.commons.function.Try.ifSuccess.

If this Try is a success, call the supplied Consumer with the contained value; otherwise, do nothing.

Annotations
@Override
orElseback to summary
public Try<V> orElse(Supplier<Try<V>> supplier)

Implements abstract org.junit.platform.commons.function.Try.orElse.

Doc from org.junit.platform.commons.function.Try.orElse.

If this Try is a failure, call the supplied supplier and return the resulting Try; if this Try is a success, do nothing.

Annotations
@Override
orElseTryback to summary
public Try<V> orElseTry(Callable<V> action)

Implements abstract org.junit.platform.commons.function.Try.orElseTry.

Doc from org.junit.platform.commons.function.Try.orElseTry.

If this Try is a failure, call the supplied action and return a new successful or failed Try depending on the action's outcome; if this Try is a success, do nothing.

Annotations
@Override
toOptionalback to summary
public Optional<V> toOptional()

Implements abstract org.junit.platform.commons.function.Try.toOptional.

Doc from org.junit.platform.commons.function.Try.toOptional.

If this Try is a failure, return an empty Optional; if this Try is a success, wrap the contained value using Optional#ofNullable(Object).

Annotations
@Override
uncheckedCastback to summary
private <U> Try<U> uncheckedCast()
Annotations
@SuppressWarnings:unchecked
org.junit.platform.commons.function back to summary

private final Class Try.Success<V extends @Nullable Object>

extends Try<V extends @Nullable Object>
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final V

Constructor Summary

AccessConstructor and Description
pack-priv
Success(V value)

Method Summary

Modifier and TypeMethod and Description
public <U> Try<U>
andThen(Function<V, Try<U>> function)

Implements abstract org.junit.platform.commons.function.Try.andThen.

If this Try is a success, apply the supplied function to its value and return the resulting Try; if this Try is a failure, do nothing.

public <U> Try<U>
andThenTry(Try.Transformer<V, U> transformer)

Implements abstract org.junit.platform.commons.function.Try.andThenTry.

If this Try is a success, apply the supplied transformer to its value and return a new successful or failed Try depending on the transformer's outcome; if this Try is a failure, do nothing.

public boolean
equals(Object that)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public V
get()

Implements abstract org.junit.platform.commons.function.Try.get.

If this Try is a success, get the contained value; if this Try is a failure, throw the contained exception.

public <E extends Exception> V
getOrThrow(Function<? super Exception, E> exceptionTransformer)

Implements abstract org.junit.platform.commons.function.Try.getOrThrow.

If this Try is a success, get the contained value; if this Try is a failure, call the supplied Function with the contained exception and throw the resulting Exception.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public Try<V>
ifFailure(Consumer<Exception> causeConsumer)

Implements abstract org.junit.platform.commons.function.Try.ifFailure.

If this Try is a failure, call the supplied Consumer with the contained exception; otherwise, do nothing.

public Try<V>
ifSuccess(Consumer<V> valueConsumer)

Implements abstract org.junit.platform.commons.function.Try.ifSuccess.

If this Try is a success, call the supplied Consumer with the contained value; otherwise, do nothing.

public Try<V>
orElse(Supplier<Try<V>> supplier)

Implements abstract org.junit.platform.commons.function.Try.orElse.

If this Try is a failure, call the supplied supplier and return the resulting Try; if this Try is a success, do nothing.

public Try<V>
orElseTry(Callable<V> action)

Implements abstract org.junit.platform.commons.function.Try.orElseTry.

If this Try is a failure, call the supplied action and return a new successful or failed Try depending on the action's outcome; if this Try is a success, do nothing.

public Optional<V>
toOptional()

Implements abstract org.junit.platform.commons.function.Try.toOptional.

If this Try is a failure, return an empty Optional; if this Try is a success, wrap the contained value using Optional#ofNullable(Object).

Inherited from org.junit.platform.commons.function.Try:
callfailuregetNonNullgetNonNullOrThrowsuccess

Field Detail

valueback to summary
private final V value

Constructor Detail

Successback to summary
pack-priv Success(V value)

Method Detail

andThenback to summary
public <U> Try<U> andThen(Function<V, Try<U>> function)

Implements abstract org.junit.platform.commons.function.Try.andThen.

Doc from org.junit.platform.commons.function.Try.andThen.

If this Try is a success, apply the supplied function to its value and return the resulting Try; if this Try is a failure, do nothing.

Annotations
@Override
andThenTryback to summary
public <U> Try<U> andThenTry(Try.Transformer<V, U> transformer)

Implements abstract org.junit.platform.commons.function.Try.andThenTry.

Doc from org.junit.platform.commons.function.Try.andThenTry.

If this Try is a success, apply the supplied transformer to its value and return a new successful or failed Try depending on the transformer's outcome; if this Try is a failure, do nothing.

Annotations
@Override
equalsback to summary
public boolean equals(Object that)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Annotations
@Override
getback to summary
public V get()

Implements abstract org.junit.platform.commons.function.Try.get.

Doc from org.junit.platform.commons.function.Try.get.

If this Try is a success, get the contained value; if this Try is a failure, throw the contained exception.

Annotations
@Override
getOrThrowback to summary
public <E extends Exception> V getOrThrow(Function<? super Exception, E> exceptionTransformer)

Implements abstract org.junit.platform.commons.function.Try.getOrThrow.

Doc from org.junit.platform.commons.function.Try.getOrThrow.

If this Try is a success, get the contained value; if this Try is a failure, call the supplied Function with the contained exception and throw the resulting Exception.

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Annotations
@Override
ifFailureback to summary
public Try<V> ifFailure(Consumer<Exception> causeConsumer)

Implements abstract org.junit.platform.commons.function.Try.ifFailure.

Doc from org.junit.platform.commons.function.Try.ifFailure.

If this Try is a failure, call the supplied Consumer with the contained exception; otherwise, do nothing.

Annotations
@Override
ifSuccessback to summary
public Try<V> ifSuccess(Consumer<V> valueConsumer)

Implements abstract org.junit.platform.commons.function.Try.ifSuccess.

Doc from org.junit.platform.commons.function.Try.ifSuccess.

If this Try is a success, call the supplied Consumer with the contained value; otherwise, do nothing.

Annotations
@Override
orElseback to summary
public Try<V> orElse(Supplier<Try<V>> supplier)

Implements abstract org.junit.platform.commons.function.Try.orElse.

Doc from org.junit.platform.commons.function.Try.orElse.

If this Try is a failure, call the supplied supplier and return the resulting Try; if this Try is a success, do nothing.

Annotations
@Override
orElseTryback to summary
public Try<V> orElseTry(Callable<V> action)

Implements abstract org.junit.platform.commons.function.Try.orElseTry.

Doc from org.junit.platform.commons.function.Try.orElseTry.

If this Try is a failure, call the supplied action and return a new successful or failed Try depending on the action's outcome; if this Try is a success, do nothing.

Annotations
@Override
toOptionalback to summary
public Optional<V> toOptional()

Implements abstract org.junit.platform.commons.function.Try.toOptional.

Doc from org.junit.platform.commons.function.Try.toOptional.

If this Try is a failure, return an empty Optional; if this Try is a success, wrap the contained value using Optional#ofNullable(Object).

Annotations
@Override
org.junit.platform.commons.function back to summary

public Interface Try.Transformer<S extends @Nullable Object, T extends @Nullable Object>

Annotations
@FunctionalInterface

A transformer for values of type S to type T.

The Transformer interface is similar to Function, except that a Transformer may throw an exception.

Method Summary

Modifier and TypeMethod and Description
public T
apply(S value)

Apply this transformer to the supplied value.

Method Detail

applyback to summary
public T apply(S value) throws Exception

Apply this transformer to the supplied value.

Exceptions
Exception:
if the transformation fails