Package com.faunadb.client.types
Class Result<T>
- java.lang.Object
-
- com.faunadb.client.types.Result<T>
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static <T> Result<T>fail(String error)Creates failure resultstatic <T> Result<T>fail(String error, Throwable cause)Creates failure result with an exceptionabstract <U> Result<U>flatMap(Function<T,Result<U>> fn)Apply the function passed on the result value.abstract Tget()Extracts the resulting value or throw an exception if the operation has failed.abstract Optional<T>getOptional()Gets anOptionaltype containing the result value if the operation was successful.abstract TgetOrElse(Supplier<T> defaultValue)Gets the result value or return the a default value if the operation has failedabstract booleanisFailure()abstract booleanisSuccess()abstract <U> Result<U>map(Function<T,U> fn)Apply the function passed on the result value.TorElseGet(Supplier<T> defaultValue)Gets the result value or return the a default value if the operation has failedTorNull()Extracts the resulting value or returns null if the operation has failed.static <T> Result<T>success(T value)Creates a successful result
-
-
-
Method Detail
-
success
public static <T> Result<T> success(T value)
Creates a successful result- Type Parameters:
T- the type of the result- Parameters:
value- result's value- Returns:
- a successful result
-
fail
public static <T> Result<T> fail(String error)
Creates failure result- Type Parameters:
T- the type of the result- Parameters:
error- the error message- Returns:
- a failure result
-
fail
public static <T> Result<T> fail(String error, Throwable cause)
Creates failure result with an exception- Type Parameters:
T- the type of the result- Parameters:
error- the error messagecause- the exception that caused this failure- Returns:
- a failure result
-
isSuccess
public abstract boolean isSuccess()
- Returns:
- true if the operation was successful
-
isFailure
public abstract boolean isFailure()
- Returns:
- true if the operation has failed
-
get
public abstract T get()
Extracts the resulting value or throw an exception if the operation has failed.- Returns:
- the result value
- Throws:
IllegalStateException- if the operation has failed
-
getOptional
public abstract Optional<T> getOptional()
Gets anOptionaltype containing the result value if the operation was successful.- Returns:
- an
Optionalwith the result value, if success
-
getOrElse
public abstract T getOrElse(Supplier<T> defaultValue)
Gets the result value or return the a default value if the operation has failed- Parameters:
defaultValue- default value to return case this represents a failure- Returns:
- the result value of the default value
-
orElseGet
public T orElseGet(Supplier<T> defaultValue)
Gets the result value or return the a default value if the operation has failed- Parameters:
defaultValue- default value to return case this represents a failure- Returns:
- the result value of the default value
-
map
public abstract <U> Result<U> map(Function<T,U> fn)
Apply the function passed on the result value.- Type Parameters:
U- the type of the result- Parameters:
fn- the map function to be applied- Returns:
- if this is a successful result, return a new successful result with the map function result. If this is a failure, returns a new failure with the same error message.
-
flatMap
public abstract <U> Result<U> flatMap(Function<T,Result<U>> fn)
Apply the function passed on the result value.- Type Parameters:
U- the type of the result- Parameters:
fn- the map function to be applied- Returns:
- if this is a successful result, returns the map function result. If this is a failure, returns a new failure with the same error message.
-
orNull
public T orNull()
Extracts the resulting value or returns null if the operation has failed.- Returns:
- the result value or null
-
-