Enum DisposableHelper

    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
      DISPOSED
      The singleton instance representing a terminal, disposed state, don't leak it.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private DisposableHelper()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void dispose()
      Dispose the resource, the operation should be idempotent.
      static boolean dispose​(java.util.concurrent.atomic.AtomicReference<Disposable> field)
      Atomically disposes the Disposable in the field if not already disposed.
      boolean isDisposed()
      Returns true if this resource has been disposed.
      static boolean isDisposed​(Disposable d)
      Checks if the given Disposable is the common DISPOSED enum value.
      static boolean replace​(java.util.concurrent.atomic.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 void reportDisposableSet()
      Reports that the disposable is already set to the RxJavaPlugins error handler.
      static boolean set​(java.util.concurrent.atomic.AtomicReference<Disposable> field, Disposable d)
      Atomically sets the field and disposes the old contents.
      static boolean setOnce​(java.util.concurrent.atomic.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 boolean trySet​(java.util.concurrent.atomic.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.
      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.
      static DisposableHelper valueOf​(java.lang.String name)
      Returns the enum constant of this type with the specified name.
      static DisposableHelper[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
      • Methods inherited from class java.lang.Enum

        clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, wait, wait, wait
    • Enum Constant Detail

      • DISPOSED

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

      • DisposableHelper

        private DisposableHelper()
    • Method Detail

      • values

        public static DisposableHelper[] values()
        Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
        for (DisposableHelper c : DisposableHelper.values())
            System.out.println(c);
        
        Returns:
        an array containing the constants of this enum type, in the order they are declared
      • valueOf

        public static DisposableHelper valueOf​(java.lang.String name)
        Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (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:
        java.lang.IllegalArgumentException - if this enum type has no constant with the specified name
        java.lang.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​(java.util.concurrent.atomic.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​(java.util.concurrent.atomic.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​(java.util.concurrent.atomic.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​(java.util.concurrent.atomic.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​(java.util.concurrent.atomic.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