16
16
package rx .operators ;
17
17
18
18
import rx .Observable ;
19
- import rx .Observable .OnSubscribeFunc ;
20
- import rx .Observer ;
21
19
import rx .Subscriber ;
22
- import rx .Subscription ;
23
20
import rx .functions .Func1 ;
24
21
22
+ import static rx .Observable .Operator ;
23
+
25
24
/**
26
25
* Returns an Observable that emits the items from the source Observable until another Observable
27
26
* emits an item.
28
27
* <p>
29
28
* <img width="640" src="https://github.com/Netflix/RxJava/wiki/images/rx-operators/takeUntil.png">
30
29
*/
31
- public class OperationTakeUntil {
30
+ public final class OperatorTakeUntil {
32
31
33
32
/**
34
33
* Returns the values from the source observable sequence until the other observable sequence produces a value.
@@ -44,8 +43,8 @@ public class OperationTakeUntil {
44
43
* @return An observable sequence containing the elements of the source sequence up to the point the other sequence interrupted further propagation.
45
44
*/
46
45
public static <T , E > Observable <T > takeUntil (final Observable <? extends T > source , final Observable <? extends E > other ) {
47
- Observable <Notification <T >> s = Observable . create (new SourceObservable <T >(source ));
48
- Observable <Notification <T >> o = Observable . create (new OtherObservable <T , E >(other ));
46
+ Observable <Notification <T >> s = source . lift (new SourceObservable <T >());
47
+ Observable <Notification <T >> o = other . lift (new OtherObservable <T , E >());
49
48
50
49
Observable <Notification <T >> result = Observable .merge (s , o );
51
50
@@ -81,19 +80,14 @@ private Notification(boolean halt, T value) {
81
80
82
81
}
83
82
84
- private static class SourceObservable <T > implements OnSubscribeFunc <Notification <T >> {
85
- private final Observable <? extends T > sequence ;
86
-
87
- private SourceObservable (Observable <? extends T > sequence ) {
88
- this .sequence = sequence ;
89
- }
83
+ private static class SourceObservable <T > implements Operator <Notification <T >, T > {
90
84
91
85
@ Override
92
- public Subscription onSubscribe (final Observer <? super Notification <T >> notificationObserver ) {
93
- return sequence . unsafeSubscribe ( new Subscriber <T >() {
86
+ public Subscriber <? super T > call (final Subscriber <? super Notification <T >> notificationObserver ) {
87
+ return new Subscriber <T >(notificationObserver ) {
94
88
@ Override
95
89
public void onCompleted () {
96
- notificationObserver .onNext (Notification .<T > halt ());
90
+ notificationObserver .onNext (Notification .<T >halt ());
97
91
}
98
92
99
93
@ Override
@@ -105,23 +99,18 @@ public void onError(Throwable e) {
105
99
public void onNext (T args ) {
106
100
notificationObserver .onNext (Notification .value (args ));
107
101
}
108
- }) ;
102
+ };
109
103
}
110
104
}
111
105
112
- private static class OtherObservable <T , E > implements OnSubscribeFunc <Notification <T >> {
113
- private final Observable <? extends E > sequence ;
114
-
115
- private OtherObservable (Observable <? extends E > sequence ) {
116
- this .sequence = sequence ;
117
- }
106
+ private static class OtherObservable <T , E > implements Operator <Notification <T >, E > {
118
107
119
108
@ Override
120
- public Subscription onSubscribe (final Observer <? super Notification <T >> notificationObserver ) {
121
- return sequence . unsafeSubscribe ( new Subscriber <E >() {
109
+ public Subscriber <? super E > call (final Subscriber <? super Notification <T >> notificationObserver ) {
110
+ return new Subscriber <E >(notificationObserver ) {
122
111
@ Override
123
112
public void onCompleted () {
124
- notificationObserver .onNext (Notification .<T > halt ());
113
+ notificationObserver .onNext (Notification .<T >halt ());
125
114
}
126
115
127
116
@ Override
@@ -131,9 +120,9 @@ public void onError(Throwable e) {
131
120
132
121
@ Override
133
122
public void onNext (E args ) {
134
- notificationObserver .onNext (Notification .<T > halt ());
123
+ notificationObserver .onNext (Notification .<T >halt ());
135
124
}
136
- }) ;
125
+ };
137
126
}
138
127
}
139
128
}
0 commit comments