Skip to content

Commit 129e531

Browse files
committed
Use NotificationLite
1 parent 49075d6 commit 129e531

File tree

1 file changed

+26
-39
lines changed

1 file changed

+26
-39
lines changed

rxjava-core/src/main/java/rx/operators/OperatorTakeUntil.java

Lines changed: 26 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -43,84 +43,71 @@ public final class OperatorTakeUntil {
4343
* @return An observable sequence containing the elements of the source sequence up to the point the other sequence interrupted further propagation.
4444
*/
4545
public static <T, E> Observable<T> takeUntil(final Observable<? extends T> source, final Observable<? extends E> other) {
46-
Observable<Notification<T>> s = source.lift(new SourceObservable<T>());
47-
Observable<Notification<T>> o = other.lift(new OtherObservable<T, E>());
46+
Observable<Object> s = source.lift(new SourceObservable<T>());
47+
Observable<Object> o = other.lift(new OtherObservable<E>());
4848

49-
Observable<Notification<T>> result = Observable.merge(s, o);
49+
Observable<Object> result = Observable.merge(s, o);
5050

51-
return result.takeWhile(new Func1<Notification<T>, Boolean>() {
51+
final NotificationLite<T> notification = NotificationLite.instance();
52+
53+
return result.takeWhile(new Func1<Object, Boolean>() {
5254
@Override
53-
public Boolean call(Notification<T> notification) {
54-
return !notification.halt;
55+
public Boolean call(Object args) {
56+
return !notification.isCompleted(args);
5557
}
56-
}).map(new Func1<Notification<T>, T>() {
58+
}).map(new Func1<Object, T>() {
5759
@Override
58-
public T call(Notification<T> notification) {
59-
return notification.value;
60+
public T call(Object args) {
61+
return notification.getValue(args);
6062
}
6163
});
6264
}
6365

64-
private static class Notification<T> {
65-
private final boolean halt;
66-
private final T value;
67-
68-
public static <T> Notification<T> value(T value) {
69-
return new Notification<T>(false, value);
70-
}
71-
72-
public static <T> Notification<T> halt() {
73-
return new Notification<T>(true, null);
74-
}
75-
76-
private Notification(boolean halt, T value) {
77-
this.halt = halt;
78-
this.value = value;
79-
}
66+
private final static class SourceObservable<T> implements Operator<Object, T> {
8067

81-
}
82-
83-
private static class SourceObservable<T> implements Operator<Notification<T>, T> {
68+
private final NotificationLite<T> notification = NotificationLite.instance();
8469

8570
@Override
86-
public Subscriber<? super T> call(final Subscriber<? super Notification<T>> notificationObserver) {
87-
return new Subscriber<T>(notificationObserver) {
71+
public Subscriber<? super T> call(final Subscriber<? super Object> subscriber) {
72+
return new Subscriber<T>(subscriber) {
8873
@Override
8974
public void onCompleted() {
90-
notificationObserver.onNext(Notification.<T>halt());
75+
subscriber.onNext(notification.completed());
9176
}
9277

9378
@Override
9479
public void onError(Throwable e) {
95-
notificationObserver.onError(e);
80+
subscriber.onError(e);
9681
}
9782

9883
@Override
9984
public void onNext(T args) {
100-
notificationObserver.onNext(Notification.value(args));
85+
subscriber.onNext(notification.next(args));
10186
}
10287
};
10388
}
10489
}
10590

106-
private static class OtherObservable<T, E> implements Operator<Notification<T>, E> {
91+
private final static class OtherObservable<E> implements Operator<Object, E> {
92+
93+
private final NotificationLite<E> notification = NotificationLite.instance();
10794

10895
@Override
109-
public Subscriber<? super E> call(final Subscriber<? super Notification<T>> notificationObserver) {
110-
return new Subscriber<E>(notificationObserver) {
96+
public Subscriber<? super E> call(final Subscriber<? super Object> subscriber) {
97+
return new Subscriber<E>(subscriber) {
11198
@Override
11299
public void onCompleted() {
113-
notificationObserver.onNext(Notification.<T>halt());
100+
subscriber.onNext(notification.completed());
114101
}
115102

116103
@Override
117104
public void onError(Throwable e) {
118-
notificationObserver.onError(e);
105+
subscriber.onError(e);
119106
}
120107

121108
@Override
122109
public void onNext(E args) {
123-
notificationObserver.onNext(Notification.<T>halt());
110+
subscriber.onNext(notification.completed());
124111
}
125112
};
126113
}

0 commit comments

Comments
 (0)