Package javascalautils
Class Failure<T>
- java.lang.Object
-
- javascalautils.Failure<T>
-
- Type Parameters:
T- The type of the exception represented by this instance
- All Implemented Interfaces:
java.io.Serializable,java.lang.Iterable<T>,Try<T>
public final class Failure<T> extends java.lang.Object implements Try<T>, java.io.Serializable
Represents the failure implementation ofTry.
Acts as a carrier for the result/throwable of a unsuccessful computation.
For examples on usage refer to the documentation forTry.- Since:
- 1.0
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description Failure(java.lang.Throwable throwable)Creates a Failure for the provided Throwable.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Try<java.lang.Throwable>failed()Returns aSuccesswith theThrowablethis instance represents.Try<T>filter(java.util.function.Predicate<T> predicate)Always returns this.<R> Try<R>flatMap(ThrowableFunction1<T,Try<R>> function)Always returns this.Tget()Always throws theThrowablethis instance represents.TgetOrElse(java.util.function.Supplier<T> supplier)Always returns the value provided by the supplier.booleanisSuccess()Always returnsfalse.java.util.Iterator<T>iterator()Always returns an empty iterator.<R> Try<R>map(ThrowableFunction1<T,R> function)Always returns this.Try<T>orElse(java.util.function.Supplier<Try<T>> supplier)Always returns the value provided by the supplier.Try<T>recover(ThrowableFunction1<java.lang.Throwable,T> function)Try<T>recoverWith(ThrowableFunction1<java.lang.Throwable,Try<T>> function)Applies the provided function to the Throwable of thisFailureand returns the result.java.util.stream.Stream<T>stream()Always returns an empty stream.java.lang.StringtoString()Returns a String representation of the instance.
-
-
-
Method Detail
-
isSuccess
public boolean isSuccess()
Always returnsfalse.
-
getOrElse
public T getOrElse(java.util.function.Supplier<T> supplier)
Always returns the value provided by the supplier.
As per definition this is a failure without any data to return.
-
orElse
public Try<T> orElse(java.util.function.Supplier<Try<T>> supplier)
Always returns the value provided by the supplier.
As per definition this is a failure without any data to return.
-
get
public T get() throws java.lang.Throwable
Always throws theThrowablethis instance represents.
As per definition this is a failure without any data to return.
-
failed
public Try<java.lang.Throwable> failed()
Returns aSuccesswith theThrowablethis instance represents.
-
map
public <R> Try<R> map(ThrowableFunction1<T,R> function)
Always returns this.
As per definition this is a failure without any data to map.
-
flatMap
public <R> Try<R> flatMap(ThrowableFunction1<T,Try<R>> function)
Always returns this.
As per definition this is a failure without any data to map.
-
filter
public Try<T> filter(java.util.function.Predicate<T> predicate)
Always returns this.
As per definition this is a failure without any data to filter.
-
recover
public Try<T> recover(ThrowableFunction1<java.lang.Throwable,T> function)
-
recoverWith
public Try<T> recoverWith(ThrowableFunction1<java.lang.Throwable,Try<T>> function)
Applies the provided function to the Throwable of thisFailureand returns the result.- Specified by:
recoverWithin interfaceTry<T>- Parameters:
function- The function to apply in case of aFailure- Returns:
- The recovered Try
- Since:
- 1.4
-
toString
public java.lang.String toString()
Returns a String representation of the instance.- Overrides:
toStringin classjava.lang.Object- Since:
- 1.0
-
iterator
public final java.util.Iterator<T> iterator()
Always returns an empty iterator.- Specified by:
iteratorin interfacejava.lang.Iterable<T>- Returns:
- An empty iterator
- Since:
- 1.0
-
stream
public final java.util.stream.Stream<T> stream()
Always returns an empty stream.- Returns:
- An empty stream
- Since:
- 1.0
-
-