ResultTransform

Kotlin|Java

public abstract classResultTransform<R extends Result, S extends Result>


Transforms aResult by making a subsequent API call.

See also
then

Summary

Public constructors

Public methods

final @NonNullPendingResult<S>

Creates a failed result with the givenStatus.

@NonNullStatus

Called when the PendingResult to be transformed returns a failure.

abstract @NullablePendingResult<S>

Transforms the result of a successful API call.

Public constructors

ResultTransform

public ResultTransform()

Public methods

createFailedResult

public final @NonNullPendingResult<S> createFailedResult(@NonNullStatus status)

Creates a failed result with the givenStatus. In the event of an error duringonSuccess, call this method and return the failed result.

Note: thePendingResult generated by this method must be returned directly fromonSuccess. It is an error to call any methods on this PendingResult.

onFailure

public @NonNullStatus onFailure(@NonNullStatus status)

Called when the PendingResult to be transformed returns a failure. Default implementation simply propagates the failure, but subclasses may override for custom failure handling. This method is called on the main thread, unless overridden bysetHandler.

Parameters
@NonNullStatus status

The status of the failure.

Returns
@NonNullStatus

The status of the result of the transformation. Must not be success or null.

onSuccess

@WorkerThread
public abstract @NullablePendingResult<S> onSuccess(@NonNull R result)

Transforms the result of a successful API call. This method is called on a background thread and should not access UI elements.

Parameters
@NonNull R result

The successful result to be transformed. Never null. If this result is it will be automatically released after this transform is applied; it is not necessary to release the result inside onSuccess. It is an error to set callbacks on this result. Any callbacks set on this result will be overridden and will not be called.

Returns
@NullablePendingResult<S>

The result of the transformation. Normally the result of another API call. To shortcut execution and directly yield a failure, return either:

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2024-10-31 UTC.