Package 

Class NotificationLite


  • 
    public final class NotificationLite
    
                        

    For use in internal operators that need something like materialize and dematerialize wholly within the implementation of the operator but don't want to incur the allocation cost of actually creating rx.Notification objects for every onNext and onCompleted.

    An object is allocated inside error to wrap the Throwable but this shouldn't affect performance because exceptions should be exceptionally rare.

    • Method Summary

      Modifier and Type Method Description
      static <T> Object next(T t) Creates a lite {@code onNext} notification for the value passed in without doing any allocation.
      static Object completed() Creates a lite {@code onCompleted} notification without doing any allocation.
      static Object error(Throwable e) Create a lite {@code onError} notification.
      static <T> boolean accept(Observer<out Object> o, Object n) Unwraps the lite notification and calls the appropriate method on the Observer.
      static boolean isCompleted(Object n) Indicates whether or not the lite notification represents an {@code onCompleted} event.
      static boolean isError(Object n) Indicates whether or not the lite notification represents an {@code onError} event.
      static boolean isNull(Object n) Indicates whether or not the lite notification represents a wrapped {@code null}{@code onNext} event.
      static boolean isNext(Object n) Indicates whether or not the lite notification represents an {@code onNext} event.
      static <T> T getValue(Object n) Returns the item corresponding to this {@code OnNext} lite notification.
      static Throwable getError(Object n) Returns the Throwable corresponding to this {@code OnError} lite notification.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • next

         static <T> Object next(T t)

        Creates a lite {@code onNext} notification for the value passed in without doing any allocation. Canbe unwrapped and sent with the accept method.

        Parameters:
        t - the item emitted to {@code onNext}
      • completed

         static Object completed()

        Creates a lite {@code onCompleted} notification without doing any allocation. Can be unwrapped andsent with the accept method.

      • error

         static Object error(Throwable e)

        Create a lite {@code onError} notification. This call creates an object to wrap the Throwable,but since there should only be one of these, the performance impact should be small. Can be unwrapped andsent with the accept method.

        Parameters:
        e - the {@code Throwable} in the {@code onError} notification
      • accept

         static <T> boolean accept(Observer<out Object> o, Object n)

        Unwraps the lite notification and calls the appropriate method on the Observer.

        Parameters:
        o - the Observer to call {@code onNext}, {@code onCompleted}, or {@code onError}.
        n - the lite notification
      • isCompleted

         static boolean isCompleted(Object n)

        Indicates whether or not the lite notification represents an {@code onCompleted} event.

        Parameters:
        n - the lite notification
      • isError

         static boolean isError(Object n)

        Indicates whether or not the lite notification represents an {@code onError} event.

        Parameters:
        n - the lite notification
      • isNull

         static boolean isNull(Object n)

        Indicates whether or not the lite notification represents a wrapped {@code null}{@code onNext} event.

        Parameters:
        n - the lite notification
      • isNext

         static boolean isNext(Object n)

        Indicates whether or not the lite notification represents an {@code onNext} event.

        Parameters:
        n - the lite notification
      • getValue

         static <T> T getValue(Object n)

        Returns the item corresponding to this {@code OnNext} lite notification. Bad things happen if you passthis an {@code OnComplete} or {@code OnError} notification type. For performance reasons, this methoddoes not check for this, so you are expected to prevent such a mishap.

        Parameters:
        n - the lite notification (of type {@code Kind.OnNext})
      • getError

         static Throwable getError(Object n)

        Returns the Throwable corresponding to this {@code OnError} lite notification. Bad things happenif you pass this an {@code OnComplete} or {@code OnNext} notification type. For performance reasons, thismethod does not check for this, so you are expected to prevent such a mishap.

        Parameters:
        n - the lite notification (of type {@code Kind.OnError})