public final class

MaybeSubject

extends Maybe<T>
implements MaybeObserver<T>
java.lang.Object
   ↳ io.reactivex.Maybe<T>
     ↳ io.reactivex.subjects.MaybeSubject<T>

Class Overview

Represents a hot Maybe-like source and consumer of events similar to Subjects.

All methods are thread safe. Calling onSuccess or onComplete multiple times has no effect. Calling onError multiple times relays the Throwable to the RxJavaPlugins' error handler.

The MaybeSubject doesn't store the Disposables coming through onSubscribe but disposes them once the other onXXX methods were called (terminal state reached).

History: 2.0.5 - experimental

Summary

Public Methods
static <T> MaybeSubject<T> create()
Creates a fresh MaybeSubject.
Throwable getThrowable()
Returns the terminal error if this MaybeSubject has been terminated with an error, null otherwise.
T getValue()
Returns the success value if this MaybeSubject was terminated with a success value.
boolean hasComplete()
Returns true if this MaybeSubject has been completed.
boolean hasObservers()
Returns true if this MaybeSubject has observers.
boolean hasThrowable()
Returns true if this MaybeSubject has been terminated with an error.
boolean hasValue()
Returns true if this MaybeSubject was terminated with a success value.
void onComplete()
Called once the deferred computation completes normally.
void onError(Throwable e)
Notifies the MaybeObserver that the Maybe has experienced an error condition.
void onSubscribe(Disposable d)
Provides the MaybeObserver with the means of cancelling (disposing) the connection (channel) with the Maybe in both synchronous (from within onSubscribe(Disposable) itself) and asynchronous manner.
void onSuccess(T value)
Notifies the MaybeObserver with one item and that the Maybe has finished sending push-based notifications.
Protected Methods
void subscribeActual(MaybeObserver<? super T> observer)
Override this method in subclasses to handle the incoming MaybeObservers.
[Expand]
Inherited Methods
From class io.reactivex.Maybe
From class java.lang.Object
From interface io.reactivex.MaybeObserver
From interface io.reactivex.MaybeSource

Public Methods

public static MaybeSubject<T> create ()

Creates a fresh MaybeSubject.

Returns
  • the new MaybeSubject instance

public Throwable getThrowable ()

Returns the terminal error if this MaybeSubject has been terminated with an error, null otherwise.

Returns
  • the terminal error or null if not terminated or not with an error

public T getValue ()

Returns the success value if this MaybeSubject was terminated with a success value.

Returns
  • the success value or null

public boolean hasComplete ()

Returns true if this MaybeSubject has been completed.

Returns
  • true if this MaybeSubject has been completed

public boolean hasObservers ()

Returns true if this MaybeSubject has observers.

Returns
  • true if this MaybeSubject has observers

public boolean hasThrowable ()

Returns true if this MaybeSubject has been terminated with an error.

Returns
  • true if this MaybeSubject has been terminated with an error

public boolean hasValue ()

Returns true if this MaybeSubject was terminated with a success value.

Returns
  • true if this MaybeSubject was terminated with a success value

public void onComplete ()

Called once the deferred computation completes normally.

public void onError (Throwable e)

Notifies the MaybeObserver that the Maybe has experienced an error condition.

If the Maybe calls this method, it will not thereafter call onSuccess(T).

Parameters
e the exception encountered by the Maybe

public void onSubscribe (Disposable d)

Provides the MaybeObserver with the means of cancelling (disposing) the connection (channel) with the Maybe in both synchronous (from within onSubscribe(Disposable) itself) and asynchronous manner.

Parameters
d the Disposable instance whose dispose() can be called anytime to cancel the connection

public void onSuccess (T value)

Notifies the MaybeObserver with one item and that the Maybe has finished sending push-based notifications.

The Maybe will not call this method if it calls onError(Throwable).

Parameters
value the item emitted by the Maybe

Protected Methods

protected void subscribeActual (MaybeObserver<? super T> observer)

Override this method in subclasses to handle the incoming MaybeObservers.

Parameters
observer the MaybeObserver to handle, not null