Package rx

Class Notification<T>

  • Type Parameters:
    T - the actual value type held by the Notification

    public final class Notification<T>
    extends java.lang.Object
    An object representing a notification sent to an Observable.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  Notification.Kind
      Specifies the kind of the notification: an element, an error or a completion notification.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private Notification​(Notification.Kind kind, T value, java.lang.Throwable e)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void accept​(Observer<? super T> observer)
      Forwards this notification on to a specified Observer.
      static <T> Notification<T> createOnCompleted()
      Creates and returns a Notification of variety Kind.OnCompleted.
      static <T> Notification<T> createOnCompleted​(java.lang.Class<T> type)
      Creates and returns a Notification of variety Kind.OnCompleted.
      static <T> Notification<T> createOnError​(java.lang.Throwable e)
      Creates and returns a Notification of variety Kind.OnError, and assigns it an exception.
      static <T> Notification<T> createOnNext​(T t)
      Creates and returns a Notification of variety Kind.OnNext, and assigns it a value.
      boolean equals​(java.lang.Object obj)  
      Notification.Kind getKind()
      Retrieves the kind of this notification: OnNext, OnError, or OnCompleted
      java.lang.Throwable getThrowable()
      Retrieves the exception associated with this (onError) notification.
      T getValue()
      Retrieves the item associated with this (onNext) notification.
      int hashCode()  
      boolean hasThrowable()
      Indicates whether this notification has an exception associated with it.
      boolean hasValue()
      Indicates whether this notification has an item associated with it.
      boolean isOnCompleted()
      Indicates whether this notification represents an onCompleted event.
      boolean isOnError()
      Indicates whether this notification represents an onError event.
      boolean isOnNext()
      Indicates whether this notification represents an onNext event.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • throwable

        private final java.lang.Throwable throwable
      • value

        private final T value
      • ON_COMPLETED

        private static final Notification<java.lang.Void> ON_COMPLETED
    • Constructor Detail

      • Notification

        private Notification​(Notification.Kind kind,
                             T value,
                             java.lang.Throwable e)
    • Method Detail

      • createOnNext

        public static <T> Notification<T> createOnNext​(T t)
        Creates and returns a Notification of variety Kind.OnNext, and assigns it a value.
        Type Parameters:
        T - the actual value type held by the Notification
        Parameters:
        t - the item to assign to the notification as its value
        Returns:
        an OnNext variety of Notification
      • createOnError

        public static <T> Notification<T> createOnError​(java.lang.Throwable e)
        Creates and returns a Notification of variety Kind.OnError, and assigns it an exception.
        Type Parameters:
        T - the actual value type held by the Notification
        Parameters:
        e - the exception to assign to the notification
        Returns:
        an OnError variety of Notification
      • createOnCompleted

        public static <T> Notification<T> createOnCompleted()
        Creates and returns a Notification of variety Kind.OnCompleted.
        Type Parameters:
        T - the actual value type held by the Notification
        Returns:
        an OnCompleted variety of Notification
      • createOnCompleted

        public static <T> Notification<T> createOnCompleted​(java.lang.Class<T> type)
        Creates and returns a Notification of variety Kind.OnCompleted.
        Type Parameters:
        T - the actual value type held by the Notification
        Parameters:
        type -
        Returns:
        an OnCompleted variety of Notification
      • getThrowable

        public java.lang.Throwable getThrowable()
        Retrieves the exception associated with this (onError) notification.
        Returns:
        the Throwable associated with this (onError) notification
      • getValue

        public T getValue()
        Retrieves the item associated with this (onNext) notification.
        Returns:
        the item associated with this (onNext) notification
      • hasValue

        public boolean hasValue()
        Indicates whether this notification has an item associated with it.
        Returns:
        a boolean indicating whether or not this notification has an item associated with it
      • hasThrowable

        public boolean hasThrowable()
        Indicates whether this notification has an exception associated with it.
        Returns:
        a boolean indicating whether this notification has an exception associated with it
      • getKind

        public Notification.Kind getKind()
        Retrieves the kind of this notification: OnNext, OnError, or OnCompleted
        Returns:
        the kind of the notification: OnNext, OnError, or OnCompleted
      • isOnError

        public boolean isOnError()
        Indicates whether this notification represents an onError event.
        Returns:
        a boolean indicating whether this notification represents an onError event
      • isOnCompleted

        public boolean isOnCompleted()
        Indicates whether this notification represents an onCompleted event.
        Returns:
        a boolean indicating whether this notification represents an onCompleted event
      • isOnNext

        public boolean isOnNext()
        Indicates whether this notification represents an onNext event.
        Returns:
        a boolean indicating whether this notification represents an onNext event
      • accept

        public void accept​(Observer<? super T> observer)
        Forwards this notification on to a specified Observer.
        Parameters:
        observer - the target observer to call onXXX methods on based on the kind of this Notification instance
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object