@Immutable
public class SphereResult<T>
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
<R> SphereResult<R> |
castErrorInternal()
If error, creates a new error result of given type (doesn't transform anything, just changes the type).
|
<T> T |
getError(java.lang.Class<T> exceptionClass)
If this is an erroneous result containing an exception of given type (or its subtype), returns it.
|
SphereBackendException |
getGenericError()
If this is an erroneous result, returns the exception representing the error returned by the backend.
|
com.google.common.base.Optional<SphereException> |
getSpecificErrorInternal()
Returns true if this result has a specific error.
|
T |
getValue()
Gets the success value of this result.
|
boolean |
isError()
Returns true if the request returned a status code of 4xx or 5xx.
|
<T> boolean |
isError(java.lang.Class<T> exceptionClass)
Returns true if this is an erroneous result containing an exception of given type or subtype.
|
boolean |
isSuccess()
Returns true if the request was successful and returned a status code of 2xx.
|
static <T> SphereResult<T> |
success(T value)
Creates a new successful result.
|
java.lang.String |
toString() |
<R> SphereResult<R> |
transform(com.google.common.base.Function<T,R> successFunc)
If successful, transforms the success value.
|
static <T> SphereResult<T> |
withSpecificError(SphereResultRaw<T> rawResult,
com.google.common.base.Function<SphereBackendException,SphereException> transformError)
Creates a
SphereResult with a generic and optionally also a specific error, based on the generic one. |
public boolean isSuccess()
public boolean isError()
public T getValue()
@Nonnull public SphereBackendException getGenericError()
IllegalStateException
.public <T> boolean isError(java.lang.Class<T> exceptionClass)
@Nullable public <T> T getError(java.lang.Class<T> exceptionClass)
public static <T> SphereResult<T> success(T value)
public <R> SphereResult<R> castErrorInternal()
public <R> SphereResult<R> transform(@Nonnull com.google.common.base.Function<T,R> successFunc)
public com.google.common.base.Optional<SphereException> getSpecificErrorInternal()
public static <T> SphereResult<T> withSpecificError(SphereResultRaw<T> rawResult, @Nullable com.google.common.base.Function<SphereBackendException,SphereException> transformError)
SphereResult
with a generic and optionally also a specific error, based on the generic one.transformError
- Function that further specifies the error.
The function can be null or return null if it doesn't wish to specify the error.public java.lang.String toString()
toString
in class java.lang.Object