Enum Class DisposableHelper

java.lang.Object
java.lang.Enum<DisposableHelper>
io.reactivex.rxjava3.internal.disposables.DisposableHelper
All Implemented Interfaces:
Disposable, Serializable, Comparable<DisposableHelper>, Constable

public enum DisposableHelper extends Enum<DisposableHelper> implements Disposable
Utility methods for working with Disposables atomically.
  • Enum Constant Details

    • DISPOSED

      public static final DisposableHelper DISPOSED
      The singleton instance representing a terminal, disposed state, don't leak it.
  • Constructor Details

    • DisposableHelper

      private DisposableHelper()
  • Method Details

    • values

      public static DisposableHelper[] 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

      public static DisposableHelper valueOf(String name)
      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 name
      NullPointerException - if the argument is null
    • isDisposed

      public static boolean isDisposed(Disposable d)
      Checks if the given Disposable is the common DISPOSED enum value.
      Parameters:
      d - the disposable to check
      Returns:
      true if d is DISPOSED
    • set

      public static boolean set(AtomicReference<Disposable> field, Disposable d)
      Atomically sets the field and disposes the old contents.
      Parameters:
      field - the target field
      d - the new Disposable to set
      Returns:
      true if successful, false if the field contains the DISPOSED instance.
    • setOnce

      public static boolean setOnce(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. 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 field
      d - the disposable to set, not null
      Returns:
      true if the operation succeeded, false
    • replace

      public static boolean replace(AtomicReference<Disposable> field, Disposable d)
      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 change
      d - 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

      public static boolean dispose(AtomicReference<Disposable> field)
      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

      public static boolean validate(Disposable current, Disposable next)
      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 null
      next - 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

      public static boolean trySet(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 contains DISPOSED.
      Parameters:
      field - the target field
      d - the disposable to set
      Returns:
      true if successful, false otherwise
    • dispose

      public void dispose()
      Description copied from interface: Disposable
      Dispose the resource, the operation should be idempotent.
      Specified by:
      dispose in interface Disposable
    • isDisposed

      public boolean isDisposed()
      Description copied from interface: Disposable
      Returns true if this resource has been disposed.
      Specified by:
      isDisposed in interface Disposable
      Returns:
      true if this resource has been disposed