Class Notification<T>

  • Type Parameters:
    T - the value type

    public final class Notification<T>
    extends java.lang.Object
    Represents the reactive signal types: onNext, onError and onComplete and holds their parameter values (a value, a Throwable, nothing).
    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) static Notification<java.lang.Object> COMPLETE
      The singleton instance for createOnComplete.
      (package private) java.lang.Object value  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private Notification​(@Nullable java.lang.Object value)
      Not meant to be implemented externally.
    • Field Detail

      • value

        final java.lang.Object value
      • COMPLETE

        static final Notification<java.lang.Object> COMPLETE
        The singleton instance for createOnComplete.
    • Constructor Detail

      • Notification

        private Notification​(@Nullable
                             @Nullable java.lang.Object value)
        Not meant to be implemented externally.
        Parameters:
        value - the value to carry around in the notification, not null
    • Method Detail

      • isOnComplete

        public boolean isOnComplete()
        Returns true if this notification is an onComplete signal.
        Returns:
        true if this notification is an onComplete signal
      • isOnError

        public boolean isOnError()
        Returns true if this notification is an onError signal and getError() returns the contained Throwable.
        Returns:
        true if this notification is an onError signal
        See Also:
        getError()
      • isOnNext

        public boolean isOnNext()
        Returns true if this notification is an onNext signal and getValue() returns the contained value.
        Returns:
        true if this notification is an onNext signal
        See Also:
        getValue()
      • getValue

        @Nullable
        public T getValue()
        Returns the contained value if this notification is an onNext signal, null otherwise.
        Returns:
        the value contained or null
        See Also:
        isOnNext()
      • getError

        @Nullable
        public @Nullable java.lang.Throwable getError()
        Returns the container Throwable error if this notification is an onError signal, null otherwise.
        Returns:
        the Throwable error contained or null
        See Also:
        isOnError()
      • equals

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

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

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

        @NonNull
        public static <@NonNull T> @NonNull Notification<T> createOnNext​(@NonNull T value)
        Constructs an onNext notification containing the given value.
        Type Parameters:
        T - the value type
        Parameters:
        value - the value to carry around in the notification, not null
        Returns:
        the new Notification instance
        Throws:
        java.lang.NullPointerException - if value is null
      • createOnError

        @NonNull
        public static <T> @NonNull Notification<T> createOnError​(@NonNull
                                                                 @NonNull java.lang.Throwable error)
        Constructs an onError notification containing the error.
        Type Parameters:
        T - the value type
        Parameters:
        error - the error Throwable to carry around in the notification, not null
        Returns:
        the new Notification instance
        Throws:
        java.lang.NullPointerException - if error is null
      • createOnComplete

        @NonNull
        public static <T> @NonNull Notification<T> createOnComplete()
        Returns the empty and stateless shared instance of a notification representing an onComplete signal.
        Type Parameters:
        T - the target value type
        Returns:
        the shared Notification instance representing an onComplete signal