T
- The type of the value represented by this instancepublic final class Success<T> extends Object implements Try<T>, Serializable
Try
. Try
.Constructor and Description |
---|
Success(T value)
Creates a 'successful' instance with the provided value.
|
Modifier and Type | Method and Description |
---|---|
Try<Throwable> |
failed()
Returns a
Failure with an UnsupportedOperationException . |
Try<T> |
filter(java.util.function.Predicate<T> predicate)
Applies the predicate to the value of this instance, if it matches this is returned else a
Failure . |
<R> Try<R> |
flatMap(java.util.function.Function<T,Try<R>> function)
Applies the value to the function and returns the
Try generated by the function. |
T |
get()
Returns the value held by this instance.
|
T |
getOrElse(java.util.function.Supplier<T> supplier)
Returns the value provided in the constructor.
|
boolean |
isSuccess()
Always returns
true . |
Iterator<T> |
iterator()
Returns an iterator containing the single value of this instance.
|
<R> Try<R> |
map(java.util.function.Function<T,R> function)
Applies the value to the function and returns the
Try representing the mapped value. |
Try<T> |
orElse(java.util.function.Supplier<Try<T>> supplier)
Always returns this.
|
Try<T> |
recover(java.util.function.Function<Throwable,T> function)
Always returns this .
|
Try<T> |
recoverWith(java.util.function.Function<Throwable,Try<T>> function)
Always returns this .
|
java.util.stream.Stream<T> |
stream()
Returns a stream of size one containing the value of this instance.
|
String |
toString()
Returns a String representation of the instance.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
apply, apply, asOption, isFailure, iterator, orNull, stream
forEach, spliterator
public Success(T value)
value
- The value represented by this instancepublic boolean isSuccess()
true
.public T getOrElse(java.util.function.Supplier<T> supplier)
public Try<T> orElse(java.util.function.Supplier<Try<T>> supplier)
public T get()
public Try<Throwable> failed()
Failure
with an UnsupportedOperationException
. public <R> Try<R> map(java.util.function.Function<T,R> function)
Try
representing the mapped value.public <R> Try<R> flatMap(java.util.function.Function<T,Try<R>> function)
Try
generated by the function.public Try<T> filter(java.util.function.Predicate<T> predicate)
Failure
.public Try<T> recover(java.util.function.Function<Throwable,T> function)
public Try<T> recoverWith(java.util.function.Function<Throwable,Try<T>> function)
recoverWith
in interface Try<T>
function
- The function to apply in case of a Failure
public String toString()
public final Iterator<T> iterator()
public final java.util.stream.Stream<T> stream()
Copyright © 2015, Peter Nerg Apache License v2.0