Enum Class DisposableHelper
- All Implemented Interfaces:
Disposable,Serializable,Comparable<DisposableHelper>,Constable
Utility methods for working with Disposables atomically.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>> -
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionThe singleton instance representing a terminal, disposed state, don't leak it. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoiddispose()Dispose the resource, the operation should be idempotent.static booleandispose(AtomicReference<Disposable> field) Atomically disposes the Disposable in the field if not already disposed.booleanReturns true if this resource has been disposed.static booleanChecks if the given Disposable is the commonDISPOSEDenum value.static booleanreplace(AtomicReference<Disposable> field, Disposable d) Atomically replaces the Disposable in the field with the given new Disposable but does not dispose the old one.static voidReports that the disposable is already set to the RxJavaPlugins error handler.static booleanset(AtomicReference<Disposable> field, Disposable d) Atomically sets the field and disposes the old contents.static booleansetOnce(AtomicReference<Disposable> field, Disposable d) Atomically sets the field to the given non-null Disposable and returns true or returns false if the field is non-null.static booleantrySet(AtomicReference<Disposable> field, Disposable d) Atomically tries to set the given Disposable on the field if it is null or disposes it if the field containsDISPOSED.static booleanvalidate(Disposable current, Disposable next) Verifies that current is null, next is not null, otherwise signals errors to the RxJavaPlugins and returns false.static DisposableHelperReturns the enum constant of this class with the specified name.static DisposableHelper[]values()Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
DISPOSED
The singleton instance representing a terminal, disposed state, don't leak it.
-
-
Constructor Details
-
DisposableHelper
private DisposableHelper()
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum class has no constant with the specified nameNullPointerException- if the argument is null
-
isDisposed
Checks if the given Disposable is the commonDISPOSEDenum value.- Parameters:
d- the disposable to check- Returns:
- true if d is
DISPOSED
-
set
Atomically sets the field and disposes the old contents.- Parameters:
field- the target fieldd- the new Disposable to set- Returns:
- true if successful, false if the field contains the
DISPOSEDinstance.
-
setOnce
Atomically sets the field to the given non-null Disposable and returns true or returns false if the field is non-null. If the target field contains the common DISPOSED instance, the supplied disposable is disposed. If the field contains other non-null Disposable, an IllegalStateException is signalled to the RxJavaPlugins.onError hook.- Parameters:
field- the target fieldd- the disposable to set, not null- Returns:
- true if the operation succeeded, false
-
replace
Atomically replaces the Disposable in the field with the given new Disposable but does not dispose the old one.- Parameters:
field- the target field to changed- the new disposable, null allowed- Returns:
- true if the operation succeeded, false if the target field contained the common DISPOSED instance and the given disposable (if not null) is disposed.
-
dispose
Atomically disposes the Disposable in the field if not already disposed.- Parameters:
field- the target field- Returns:
- true if the current thread managed to dispose the Disposable
-
validate
Verifies that current is null, next is not null, otherwise signals errors to the RxJavaPlugins and returns false.- Parameters:
current- the current Disposable, expected to be nullnext- the next Disposable, expected to be non-null- Returns:
- true if the validation succeeded
-
reportDisposableSet
public static void reportDisposableSet()Reports that the disposable is already set to the RxJavaPlugins error handler. -
trySet
Atomically tries to set the given Disposable on the field if it is null or disposes it if the field containsDISPOSED.- Parameters:
field- the target fieldd- the disposable to set- Returns:
- true if successful, false otherwise
-
dispose
public void dispose()Description copied from interface:DisposableDispose the resource, the operation should be idempotent.- Specified by:
disposein interfaceDisposable
-
isDisposed
public boolean isDisposed()Description copied from interface:DisposableReturns true if this resource has been disposed.- Specified by:
isDisposedin interfaceDisposable- Returns:
- true if this resource has been disposed
-