Package rx.internal.operators
Class NotificationLite<T>
java.lang.Object
rx.internal.operators.NotificationLite<T>
- Type Parameters:
T
- the element type
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
Notification
objects for every onNext
and
onCompleted
.
An object is allocated inside error(Throwable)
to wrap the Throwable
but this shouldn't
affect performance because exceptions should be exceptionally rare.
It's implemented as a singleton to maintain some semblance of type safety that is completely non-existent.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static final class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final NotificationLite
private static final Object
private static final Object
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
Unwraps the lite notification and calls the appropriate method on theObserver
.Creates a liteonCompleted
notification without doing any allocation.Create a liteonError
notification.Returns theThrowable
corresponding to thisOnError
lite notification.Returns the item corresponding to thisOnNext
lite notification.static <T> NotificationLite
<T> instance()
Gets theNotificationLite
singleton.boolean
Indicates whether or not the lite notification represents anonCompleted
event.boolean
Indicates whether or not the lite notification represents anonError
event.boolean
Indicates whether or not the lite notification represents anonNext
event.boolean
Indicates whether or not the lite notification represents a wrappednull
onNext
event.Indicates which variety a particular lite notification is.Creates a liteonNext
notification for the value passed in without doing any allocation.
-
Field Details
-
INSTANCE
-
ON_COMPLETED_SENTINEL
-
ON_NEXT_NULL_SENTINEL
-
-
Constructor Details
-
NotificationLite
private NotificationLite()
-
-
Method Details
-
instance
Gets theNotificationLite
singleton.- Type Parameters:
T
- the value type- Returns:
- the sole
NotificationLite
object
-
next
Creates a liteonNext
notification for the value passed in without doing any allocation. Can be unwrapped and sent with theaccept(rx.Observer<? super T>, java.lang.Object)
method.- Parameters:
t
- the item emitted toonNext
- Returns:
- the item, or a null token representing the item if the item is
null
-
completed
Creates a liteonCompleted
notification without doing any allocation. Can be unwrapped and sent with theaccept(rx.Observer<? super T>, java.lang.Object)
method.- Returns:
- a completion token
-
error
Create a liteonError
notification. This call creates an object to wrap theThrowable
, but since there should only be one of these, the performance impact should be small. Can be unwrapped and sent with theaccept(rx.Observer<? super T>, java.lang.Object)
method.- Parameters:
e
- theThrowable
in theonError
notification- Returns:
- an object encapsulating the exception
-
accept
Unwraps the lite notification and calls the appropriate method on theObserver
.- Parameters:
o
- theObserver
to callonNext
,onCompleted
, oronError
.n
- the lite notification- Returns:
true
ifn
represents a termination event;false
otherwise- Throws:
IllegalArgumentException
- if the notification is null.NullPointerException
- if theObserver
is null.
-
isCompleted
Indicates whether or not the lite notification represents anonCompleted
event.- Parameters:
n
- the lite notification- Returns:
true
ifn
represents anonCompleted
event;false
otherwise
-
isError
Indicates whether or not the lite notification represents anonError
event.- Parameters:
n
- the lite notification- Returns:
true
ifn
represents anonError
event;false
otherwise
-
isNull
Indicates whether or not the lite notification represents a wrappednull
onNext
event.- Parameters:
n
- the lite notification- Returns:
true
ifn
represents a wrappednull
onNext
event,false
otherwise
-
isNext
Indicates whether or not the lite notification represents anonNext
event.- Parameters:
n
- the lite notification- Returns:
true
ifn
represents anonNext
event,false
otherwise
-
kind
Indicates which variety a particular lite notification is. If you need something more complex than simply calling the right method on anObserver
then you can use this method to get theNotification.Kind
.- Parameters:
n
- the lite notification- Returns:
- the
Notification.Kind
of lite notificationn
is: eitherKind.OnCompleted
,Kind.OnError
, orKind.OnNext
- Throws:
IllegalArgumentException
- if the notification is null.
-
getValue
Returns the item corresponding to thisOnNext
lite notification. Bad things happen if you pass this anOnComplete
orOnError
notification type. For performance reasons, this method does not check for this, so you are expected to prevent such a mishap.- Parameters:
n
- the lite notification (of typeKind.OnNext
)- Returns:
- the unwrapped value, which can be null
-
getError
Returns theThrowable
corresponding to thisOnError
lite notification. Bad things happen if you pass this anOnComplete
orOnNext
notification type. For performance reasons, this method does not check for this, so you are expected to prevent such a mishap.- Parameters:
n
- the lite notification (of typeKind.OnError
)- Returns:
- the
Throwable
wrapped insiden
-