-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathObservableAggregateOperators.java
67 lines (58 loc) · 1.4 KB
/
ObservableAggregateOperators.java
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
package java_rxjava134;
import static java_rxjava134.Commons.cutOffLine;
import java.util.Iterator;
import java.util.List;
import rx.Observable;
/**
* Observable aggregate operators
*
* @author ÌÆÁú
*
*/
public class ObservableAggregateOperators {
public static void main(String[] args) {
// count
testCount();
cutOffLine();
// toList
testToList();
cutOffLine();
// toSortedList
testToSortedList();
cutOffLine();
// blocking single
testToListBlocking();
}
/** test for 'count' */
private static void testCount() {
Observable
.just(63, 5, 17, 9, 212, 34)
.count() // emits the number of the items emitted by the source Observable instance
.subscribe(System.out::println);
}
/** test for 'toList' */
private static void testToList() {
Observable
.just(63, 5, 17, 9, 212, 34)
.toList()
.subscribe(System.out::println);
}
/** test for 'tooSortedList' */
private static void testToSortedList() {
Observable
.just(63, 5, 17, 9, 212, 34)
.toSortedList()
.subscribe(System.out::println);
}
/** test for 'toList' and 'toBlocking' */
private static void testToListBlocking() {
List<Integer> o = Observable
.just(63, 5, 17, 9, 212, 34)
.toList()
.toBlocking()
.single();
for(Iterator<Integer> i = o.iterator();i.hasNext();) {
System.out.println("Blocking Single: " + i.next());
}
}
}