Package rx.internal.operators
Class NotificationLite<T>
- java.lang.Object
-
- rx.internal.operators.NotificationLite<T>
-
- Type Parameters:
T- the element type
public final class NotificationLite<T> extends java.lang.ObjectFor 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 creatingNotificationobjects for everyonNextandonCompleted.An object is allocated inside
error(Throwable)to wrap theThrowablebut 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 Classes Modifier and Type Class Description (package private) static classNotificationLite.OnErrorSentinel
-
Field Summary
Fields Modifier and Type Field Description private static NotificationLiteINSTANCEprivate static java.lang.ObjectON_COMPLETED_SENTINELprivate static java.lang.ObjectON_NEXT_NULL_SENTINEL
-
Constructor Summary
Constructors Modifier Constructor Description privateNotificationLite()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanaccept(Observer<? super T> o, java.lang.Object n)Unwraps the lite notification and calls the appropriate method on theObserver.java.lang.Objectcompleted()Creates a liteonCompletednotification without doing any allocation.java.lang.Objecterror(java.lang.Throwable e)Create a liteonErrornotification.java.lang.ThrowablegetError(java.lang.Object n)Returns theThrowablecorresponding to thisOnErrorlite notification.TgetValue(java.lang.Object n)Returns the item corresponding to thisOnNextlite notification.static <T> NotificationLite<T>instance()Gets theNotificationLitesingleton.booleanisCompleted(java.lang.Object n)Indicates whether or not the lite notification represents anonCompletedevent.booleanisError(java.lang.Object n)Indicates whether or not the lite notification represents anonErrorevent.booleanisNext(java.lang.Object n)Indicates whether or not the lite notification represents anonNextevent.booleanisNull(java.lang.Object n)Indicates whether or not the lite notification represents a wrappednullonNextevent.Notification.Kindkind(java.lang.Object n)Indicates which variety a particular lite notification is.java.lang.Objectnext(T t)Creates a liteonNextnotification for the value passed in without doing any allocation.
-
-
-
Field Detail
-
INSTANCE
private static final NotificationLite INSTANCE
-
ON_COMPLETED_SENTINEL
private static final java.lang.Object ON_COMPLETED_SENTINEL
-
ON_NEXT_NULL_SENTINEL
private static final java.lang.Object ON_NEXT_NULL_SENTINEL
-
-
Method Detail
-
instance
public static <T> NotificationLite<T> instance()
Gets theNotificationLitesingleton.- Type Parameters:
T- the value type- Returns:
- the sole
NotificationLiteobject
-
next
public java.lang.Object next(T t)
Creates a liteonNextnotification 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
public java.lang.Object completed()
Creates a liteonCompletednotification without doing any allocation. Can be unwrapped and sent with theaccept(rx.Observer<? super T>, java.lang.Object)method.- Returns:
- a completion token
-
error
public java.lang.Object error(java.lang.Throwable e)
Create a liteonErrornotification. 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- theThrowablein theonErrornotification- Returns:
- an object encapsulating the exception
-
accept
public boolean accept(Observer<? super T> o, java.lang.Object n)
Unwraps the lite notification and calls the appropriate method on theObserver.
-
isCompleted
public boolean isCompleted(java.lang.Object n)
Indicates whether or not the lite notification represents anonCompletedevent.- Parameters:
n- the lite notification- Returns:
trueifnrepresents anonCompletedevent;falseotherwise
-
isError
public boolean isError(java.lang.Object n)
Indicates whether or not the lite notification represents anonErrorevent.- Parameters:
n- the lite notification- Returns:
trueifnrepresents anonErrorevent;falseotherwise
-
isNull
public boolean isNull(java.lang.Object n)
Indicates whether or not the lite notification represents a wrappednullonNextevent.- Parameters:
n- the lite notification- Returns:
trueifnrepresents a wrappednullonNextevent,falseotherwise
-
isNext
public boolean isNext(java.lang.Object n)
Indicates whether or not the lite notification represents anonNextevent.- Parameters:
n- the lite notification- Returns:
trueifnrepresents anonNextevent,falseotherwise
-
kind
public Notification.Kind kind(java.lang.Object n)
Indicates which variety a particular lite notification is. If you need something more complex than simply calling the right method on anObserverthen you can use this method to get theNotification.Kind.- Parameters:
n- the lite notification- Returns:
- the
Notification.Kindof lite notificationnis: eitherKind.OnCompleted,Kind.OnError, orKind.OnNext - Throws:
java.lang.IllegalArgumentException- if the notification is null.
-
getValue
public T getValue(java.lang.Object n)
Returns the item corresponding to thisOnNextlite notification. Bad things happen if you pass this anOnCompleteorOnErrornotification 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
public java.lang.Throwable getError(java.lang.Object n)
Returns theThrowablecorresponding to thisOnErrorlite notification. Bad things happen if you pass this anOnCompleteorOnNextnotification 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
Throwablewrapped insiden
-
-