Repository navigation
Expand file tree
/
Copy pathJoinObservable.java
More file actions
322 lines (303 loc) · 15.6 KB
/
Copy pathJoinObservable.java
File metadata and controls
322 lines (303 loc) · 15.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
package rx.observables;
import rx.Observable;
import rx.functions.Func1;
import rx.joins.Pattern2;
import rx.joins.Plan0;
import rx.joins.operators.OperatorJoinPatterns;
/**
* Represents an observable that supports join operations.
*
* @param <T> the value type joined
*/
public final class JoinObservable<T> {
private final Observable<T> o;
private JoinObservable(Observable<T> o) {
this.o = o;
}
/**
* Creates a JoinObservable from a regular Observable.
* @param o the observable to wrap
* @return the created JoinObservable instance
*/
public static <T> JoinObservable<T> from(Observable<T> o) {
return new JoinObservable<T>(o);
}
/**
* Returns a Pattern that matches when both Observables emit an item.
* <p>
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/and_then_when.png">
*
* @param right
* an Observable to match with the source Observable
* @return a Pattern object that matches when both Observables emit an item
* @throws NullPointerException
* if {@code right} is null
* @see <a href="https://github.com/Netflix/RxJava/wiki/Combining-Observables#wiki-and-then-and-when">RxJava Wiki: and()</a>
* @see <a href="http://msdn.microsoft.com/en-us/library/hh229153.aspx">MSDN: Observable.And</a>
*/
public final <T2> Pattern2<T, T2> and(Observable<T2> right) {
return OperatorJoinPatterns.and(o, right);
}
/**
* Joins together the results from several patterns via their plans.
* <p>
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/and_then_when.png">
*
* @param plans
* a series of plans created by use of the {@link #then} Observer on patterns
* @return an Observable that emits the results from matching several patterns
* @throws NullPointerException
* if {@code plans} is null
* @see <a href="https://github.com/Netflix/RxJava/wiki/Combining-Observables#wiki-and-then-and-when">RxJava Wiki: when()</a>
* @see <a href="http://msdn.microsoft.com/en-us/library/hh229558.aspx">MSDN: Observable.When</a>
*/
public final static <R> JoinObservable<R> when(Iterable<? extends Plan0<R>> plans) {
if (plans == null) {
throw new NullPointerException("plans");
}
return from(Observable.create(OperatorJoinPatterns.when(plans)));
}
/**
* Joins together the results from several patterns via their plans.
* <p>
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/and_then_when.png">
*
* @param plans
* a series of plans created by use of the {@link #then} Observer on patterns
* @return an Observable that emits the results from matching several patterns
* @throws NullPointerException
* if {@code plans} is null
* @see <a href="https://github.com/Netflix/RxJava/wiki/Combining-Observables#wiki-and-then-and-when">RxJava Wiki: when()</a>
* @see <a href="http://msdn.microsoft.com/en-us/library/hh229889.aspx">MSDN: Observable.When</a>
*/
public final static <R> JoinObservable<R> when(Plan0<R>... plans) {
return from(Observable.create(OperatorJoinPatterns.when(plans)));
}
/**
* Joins the results from a pattern via its plan.
* <p>
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/and_then_when.png">
*
* @param p1
* the plan to join, created by use of the {@link #then} Observer on a pattern
* @return an Observable that emits the results from matching a pattern
* @see <a href="https://github.com/Netflix/RxJava/wiki/Combining-Observables#wiki-and-then-and-when">RxJava Wiki: when()</a>
* @see <a href="http://msdn.microsoft.com/en-us/library/hh229889.aspx">MSDN: Observable.When</a>
*/
@SuppressWarnings("unchecked")
public final static <R> JoinObservable<R> when(Plan0<R> p1) {
return from(Observable.create(OperatorJoinPatterns.when(p1)));
}
/**
* Joins together the results from two patterns via their plans.
* <p>
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/and_then_when.png">
*
* @param p1
* a plan, created by use of the {@link #then} Observer on a pattern
* @param p2
* a plan, created by use of the {@link #then} Observer on a pattern
* @return an Observable that emits the results from matching two patterns
* @see <a href="https://github.com/Netflix/RxJava/wiki/Combining-Observables#wiki-and-then-and-when">RxJava Wiki: when()</a>
* @see <a href="http://msdn.microsoft.com/en-us/library/hh229889.aspx">MSDN: Observable.When</a>
*/
@SuppressWarnings("unchecked")
public final static <R> JoinObservable<R> when(Plan0<R> p1, Plan0<R> p2) {
return from(Observable.create(OperatorJoinPatterns.when(p1, p2)));
}
/**
* Joins together the results from three patterns via their plans.
* <p>
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/and_then_when.png">
*
* @param p1
* a plan, created by use of the {@link #then} Observer on a pattern
* @param p2
* a plan, created by use of the {@link #then} Observer on a pattern
* @param p3
* a plan, created by use of the {@link #then} Observer on a pattern
* @return an Observable that emits the results from matching three patterns
* @see <a href="https://github.com/Netflix/RxJava/wiki/Combining-Observables#wiki-and-then-and-when">RxJava Wiki: when()</a>
* @see <a href="http://msdn.microsoft.com/en-us/library/hh229889.aspx">MSDN: Observable.When</a>
*/
@SuppressWarnings("unchecked")
public final static <R> JoinObservable<R> when(Plan0<R> p1, Plan0<R> p2, Plan0<R> p3) {
return from(Observable.create(OperatorJoinPatterns.when(p1, p2, p3)));
}
/**
* Joins together the results from four patterns via their plans.
* <p>
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/and_then_when.png">
*
* @param p1
* a plan, created by use of the {@link #then} Observer on a pattern
* @param p2
* a plan, created by use of the {@link #then} Observer on a pattern
* @param p3
* a plan, created by use of the {@link #then} Observer on a pattern
* @param p4
* a plan, created by use of the {@link #then} Observer on a pattern
* @return an Observable that emits the results from matching four patterns
* @see <a href="https://github.com/Netflix/RxJava/wiki/Combining-Observables#wiki-and-then-and-when">RxJava Wiki: when()</a>
* @see <a href="http://msdn.microsoft.com/en-us/library/hh229889.aspx">MSDN: Observable.When</a>
*/
@SuppressWarnings("unchecked")
public final static <R> JoinObservable<R> when(Plan0<R> p1, Plan0<R> p2, Plan0<R> p3, Plan0<R> p4) {
return from(Observable.create(OperatorJoinPatterns.when(p1, p2, p3, p4)));
}
/**
* Joins together the results from five patterns via their plans.
* <p>
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/and_then_when.png">
*
* @param p1
* a plan, created by use of the {@link #then} Observer on a pattern
* @param p2
* a plan, created by use of the {@link #then} Observer on a pattern
* @param p3
* a plan, created by use of the {@link #then} Observer on a pattern
* @param p4
* a plan, created by use of the {@link #then} Observer on a pattern
* @param p5
* a plan, created by use of the {@link #then} Observer on a pattern
* @return an Observable that emits the results from matching five patterns
* @see <a href="https://github.com/Netflix/RxJava/wiki/Combining-Observables#wiki-and-then-and-when">RxJava Wiki: when()</a>
* @see <a href="http://msdn.microsoft.com/en-us/library/hh229889.aspx">MSDN: Observable.When</a>
*/
@SuppressWarnings("unchecked")
public final static <R> JoinObservable<R> when(Plan0<R> p1, Plan0<R> p2, Plan0<R> p3, Plan0<R> p4, Plan0<R> p5) {
return from(Observable.create(OperatorJoinPatterns.when(p1, p2, p3, p4, p5)));
}
/**
* Joins together the results from six patterns via their plans.
* <p>
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/and_then_when.png">
*
* @param p1
* a plan, created by use of the {@link #then} Observer on a pattern
* @param p2
* a plan, created by use of the {@link #then} Observer on a pattern
* @param p3
* a plan, created by use of the {@link #then} Observer on a pattern
* @param p4
* a plan, created by use of the {@link #then} Observer on a pattern
* @param p5
* a plan, created by use of the {@link #then} Observer on a pattern
* @param p6
* a plan, created by use of the {@link #then} Observer on a pattern
* @return an Observable that emits the results from matching six patterns
* @see <a href="https://github.com/Netflix/RxJava/wiki/Combining-Observables#wiki-and-then-and-when">RxJava Wiki: when()</a>
* @see <a href="http://msdn.microsoft.com/en-us/library/hh229889.aspx">MSDN: Observable.When</a>
*/
@SuppressWarnings("unchecked")
public final static <R> JoinObservable<R> when(Plan0<R> p1, Plan0<R> p2, Plan0<R> p3, Plan0<R> p4, Plan0<R> p5, Plan0<R> p6) {
return from(Observable.create(OperatorJoinPatterns.when(p1, p2, p3, p4, p5, p6)));
}
/**
* Joins together the results from seven patterns via their plans.
* <p>
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/and_then_when.png">
*
* @param p1
* a plan, created by use of the {@link #then} Observer on a pattern
* @param p2
* a plan, created by use of the {@link #then} Observer on a pattern
* @param p3
* a plan, created by use of the {@link #then} Observer on a pattern
* @param p4
* a plan, created by use of the {@link #then} Observer on a pattern
* @param p5
* a plan, created by use of the {@link #then} Observer on a pattern
* @param p6
* a plan, created by use of the {@link #then} Observer on a pattern
* @param p7
* a plan, created by use of the {@link #then} Observer on a pattern
* @return an Observable that emits the results from matching seven patterns
* @see <a href="https://github.com/Netflix/RxJava/wiki/Combining-Observables#wiki-and-then-and-when">RxJava Wiki: when()</a>
* @see <a href="http://msdn.microsoft.com/en-us/library/hh229889.aspx">MSDN: Observable.When</a>
*/
@SuppressWarnings("unchecked")
public final static <R> JoinObservable<R> when(Plan0<R> p1, Plan0<R> p2, Plan0<R> p3, Plan0<R> p4, Plan0<R> p5, Plan0<R> p6, Plan0<R> p7) {
return from(Observable.create(OperatorJoinPatterns.when(p1, p2, p3, p4, p5, p6, p7)));
}
/**
* Joins together the results from eight patterns via their plans.
* <p>
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/and_then_when.png">
*
* @param p1
* a plan, created by use of the {@link #then} Observer on a pattern
* @param p2
* a plan, created by use of the {@link #then} Observer on a pattern
* @param p3
* a plan, created by use of the {@link #then} Observer on a pattern
* @param p4
* a plan, created by use of the {@link #then} Observer on a pattern
* @param p5
* a plan, created by use of the {@link #then} Observer on a pattern
* @param p6
* a plan, created by use of the {@link #then} Observer on a pattern
* @param p7
* a plan, created by use of the {@link #then} Observer on a pattern
* @param p8
* a plan, created by use of the {@link #then} Observer on a pattern
* @return an Observable that emits the results from matching eight patterns
* @see <a href="https://github.com/Netflix/RxJava/wiki/Combining-Observables#wiki-and-then-and-when">RxJava Wiki: when()</a>
* @see <a href="http://msdn.microsoft.com/en-us/library/hh229889.aspx">MSDN: Observable.When</a>
*/
@SuppressWarnings("unchecked")
public final static <R> JoinObservable<R> when(Plan0<R> p1, Plan0<R> p2, Plan0<R> p3, Plan0<R> p4, Plan0<R> p5, Plan0<R> p6, Plan0<R> p7, Plan0<R> p8) {
return from(Observable.create(OperatorJoinPatterns.when(p1, p2, p3, p4, p5, p6, p7, p8)));
}
/**
* Joins together the results from nine patterns via their plans.
* <p>
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/and_then_when.png">
*
* @param p1
* a plan, created by use of the {@link #then} Observer on a pattern
* @param p2
* a plan, created by use of the {@link #then} Observer on a pattern
* @param p3
* a plan, created by use of the {@link #then} Observer on a pattern
* @param p4
* a plan, created by use of the {@link #then} Observer on a pattern
* @param p5
* a plan, created by use of the {@link #then} Observer on a pattern
* @param p6
* a plan, created by use of the {@link #then} Observer on a pattern
* @param p7
* a plan, created by use of the {@link #then} Observer on a pattern
* @param p8
* a plan, created by use of the {@link #then} Observer on a pattern
* @param p9
* a plan, created by use of the {@link #then} Observer on a pattern
* @return an Observable that emits the results from matching nine patterns
* @see <a href="https://github.com/Netflix/RxJava/wiki/Combining-Observables#wiki-and-then-and-when">RxJava Wiki: when()</a>
* @see <a href="http://msdn.microsoft.com/en-us/library/hh229889.aspx">MSDN: Observable.When</a>
*/
@SuppressWarnings("unchecked")
public final static <R> JoinObservable<R> when(Plan0<R> p1, Plan0<R> p2, Plan0<R> p3, Plan0<R> p4, Plan0<R> p5, Plan0<R> p6, Plan0<R> p7, Plan0<R> p8, Plan0<R> p9) {
return from(Observable.create(OperatorJoinPatterns.when(p1, p2, p3, p4, p5, p6, p7, p8, p9)));
}
/**
* Matches when the Observable has an available item and projects the item by invoking the selector
* function.
* <p>
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/and_then_when.png">
*
* @param selector
* selector that will be invoked for items emitted by the source Observable
* @return a {@link Plan0} that produces the projected results, to be fed (with other Plans) to the {@link #when} Observer
* @throws NullPointerException
* if {@code selector} is null
* @see <a href="https://github.com/Netflix/RxJava/wiki/Combining-Observables#wiki-and-then-and-when">RxJava Wiki: then()</a>
* @see <a href="http://msdn.microsoft.com/en-us/library/hh211662.aspx">MSDN: Observable.Then</a>
*/
public final <R> Plan0<R> then(Func1<T, R> selector) {
return OperatorJoinPatterns.then(o, selector);
}
public Observable<T> toObservable() {
return o;
}
}