Skip to content

Commit 4d2a960

Browse files
Merge pull request #1295 from benjchristensen/notification-lite
Change `void accept` to `boolean accept`
2 parents a977208 + 9467053 commit 4d2a960

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

rxjava-core/src/main/java/rx/internal/operators/NotificationLite.java

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131
* It's implemented as a singleton to maintain some semblance of type safety that is completely
3232
* non-existent.
3333
*
34-
* @author gscampbell
35-
*
3634
* @param <T>
3735
*/
3836
public final class NotificationLite<T> {
@@ -89,8 +87,7 @@ public Object completed() {
8987
}
9088

9189
/**
92-
* Create a lite onError notification. This call does new up an object to wrap the
93-
* {@link Throwable} but since there should only be one of these the performance impact should
90+
* Create a lite onError notification. This call does new up an object to wrap the {@link Throwable} but since there should only be one of these the performance impact should
9491
* be small. Can be unwrapped and sent with the {@link #accept} method.
9592
*
9693
* @param e
@@ -106,25 +103,27 @@ public Object error(Throwable e) {
106103
* @param o
107104
* the {@link Observer} to call onNext, onCompleted or onError.
108105
* @param n
106+
* @return true if the n was a termination event
109107
* @throws IllegalArgumentException
110108
* if the notification is null.
111109
* @throws NullPointerException
112110
* if the {@link Observer} is null.
113111
*/
114112
@SuppressWarnings("unchecked")
115-
public void accept(Observer<? super T> o, Object n) {
113+
public boolean accept(Observer<? super T> o, Object n) {
116114
if (n == ON_COMPLETED_SENTINEL) {
117115
o.onCompleted();
118-
} else
119-
if (n == ON_NEXT_NULL_SENTINEL) {
116+
return true;
117+
} else if (n == ON_NEXT_NULL_SENTINEL) {
120118
o.onNext(null);
121-
} else
122-
if (n != null) {
119+
return false;
120+
} else if (n != null) {
123121
if (n.getClass() == OnErrorSentinel.class) {
124-
o.onError(((OnErrorSentinel)n).e);
125-
} else {
126-
o.onNext((T)n);
122+
o.onError(((OnErrorSentinel) n).e);
123+
return true;
127124
}
125+
o.onNext((T) n);
126+
return false;
128127
} else {
129128
throw new IllegalArgumentException("The lite notification can not be null");
130129
}
@@ -139,8 +138,7 @@ public boolean isError(Object n) {
139138
}
140139

141140
/**
142-
* If there is custom logic that isn't as simple as call the right method on an {@link Observer}
143-
* then this method can be used to get the {@link rx.Notification.Kind}
141+
* If there is custom logic that isn't as simple as call the right method on an {@link Observer} then this method can be used to get the {@link rx.Notification.Kind}
144142
*
145143
* @param n
146144
* @return the kind of the raw object

0 commit comments

Comments
 (0)