18
18
import java .util .Map ;
19
19
20
20
import rx .functions .Func0 ;
21
- import rx .operators .OperationConditionals ;
21
+ import rx .operators .OperatorIfThen ;
22
+ import rx .operators .OperatorSwitchCase ;
23
+ import rx .operators .OperatorWhileDoWhile ;
22
24
23
25
/**
24
26
* Imperative statements expressed as Observable operators.
25
27
*/
26
- public class Statement {
27
-
28
+ public final class Statement {
29
+ private Statement () { throw new IllegalStateException ( "No instances!" ); }
28
30
/**
29
31
* Return a particular one of several possible Observables based on a case
30
32
* selector.
@@ -99,7 +101,7 @@ public static <K, R> Observable<R> switchCase(Func0<? extends K> caseSelector,
99
101
public static <K , R > Observable <R > switchCase (Func0 <? extends K > caseSelector ,
100
102
Map <? super K , ? extends Observable <? extends R >> mapOfCases ,
101
103
Observable <? extends R > defaultCase ) {
102
- return Observable .create (OperationConditionals . switchCase (caseSelector , mapOfCases , defaultCase ));
104
+ return Observable .create (new OperatorSwitchCase < K , R > (caseSelector , mapOfCases , defaultCase ));
103
105
}
104
106
105
107
/**
@@ -116,8 +118,8 @@ public static <K, R> Observable<R> switchCase(Func0<? extends K> caseSelector,
116
118
* Observable, and then continues to replay them so long as the post
117
119
* condition is true
118
120
*/
119
- public static <T > Observable <T > doWhile (Observable <T > source , Func0 <Boolean > postCondition ) {
120
- return Observable .create (OperationConditionals . doWhile (source , postCondition ));
121
+ public static <T > Observable <T > doWhile (Observable <? extends T > source , Func0 <Boolean > postCondition ) {
122
+ return Observable .create (new OperatorWhileDoWhile < T > (source , TRUE , postCondition ));
121
123
}
122
124
123
125
/**
@@ -132,8 +134,8 @@ public static <T> Observable<T> doWhile(Observable<T> source, Func0<Boolean> pos
132
134
* @return an Observable that replays the emissions from the source
133
135
* Observable so long as <code>preCondition</code> is true
134
136
*/
135
- public static <T > Observable <T > whileDo (Observable <T > source , Func0 <Boolean > preCondition ) {
136
- return Observable .create (OperationConditionals . whileDo (source , preCondition ));
137
+ public static <T > Observable <T > whileDo (Observable <? extends T > source , Func0 <Boolean > preCondition ) {
138
+ return Observable .create (new OperatorWhileDoWhile < T > (source , preCondition , preCondition ));
137
139
}
138
140
139
141
/**
@@ -200,7 +202,16 @@ public static <R> Observable<R> ifThen(Func0<Boolean> condition, Observable<? ex
200
202
*/
201
203
public static <R > Observable <R > ifThen (Func0 <Boolean > condition , Observable <? extends R > then ,
202
204
Observable <? extends R > orElse ) {
203
- return Observable .create (OperationConditionals .ifThen (condition , then , orElse ));
205
+ return Observable .create (new OperatorIfThen <R >(condition , then , orElse ));
206
+ }
207
+ /** Returns always true. */
208
+ private static final class Func0True implements Func0 <Boolean > {
209
+ @ Override
210
+ public Boolean call () {
211
+ return true ;
212
+ }
204
213
}
205
214
215
+ /** Returns always true function. */
216
+ private static final Func0True TRUE = new Func0True ();
206
217
}
0 commit comments