本文整理汇总了Java中io.reactivex.observables.GroupedObservable类的典型用法代码示例。如果您正苦于以下问题:Java GroupedObservable类的具体用法?Java GroupedObservable怎么用?Java GroupedObservable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GroupedObservable类属于io.reactivex.observables包,在下文中一共展示了GroupedObservable类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: shouldBeNecessaryToSubscribetoStreamAfterSplitting
import io.reactivex.observables.GroupedObservable; //导入依赖的package包/类
@Test
public void shouldBeNecessaryToSubscribetoStreamAfterSplitting() {
final double[] averages = {0, 0};
Observable<Integer> numbers = Observable.just(22, 22, 99, 22, 101, 22);
Function<Integer, Integer> keySelector = integer -> integer % 2;
Observable<GroupedObservable<Integer, Integer>> split = numbers.groupBy(keySelector);
split.subscribe(
group -> {
Observable<Double> convertToDouble = group.map(integer -> (double) integer);
Function<Double, Double> insertIntoAveragesArray = aDouble -> averages[group.getKey()] = aDouble;
convertToDouble.reduce((t1, t2) -> t1+t2).map(insertIntoAveragesArray).subscribe();
}
);
assertThat(averages[0]).isEqualTo(0);
assertThat(averages[1]).isEqualTo(0);
}
开发者ID:vogellacompany,项目名称:code-examples-android-expert,代码行数:19,代码来源:lessonD_AdvancedStreams.java
示例2: doSomeWork
import io.reactivex.observables.GroupedObservable; //导入依赖的package包/类
private void doSomeWork() {
Observable.range(0, 8).groupBy(new Function<Integer, String>() {
@Override
public String apply(@NonNull Integer integer) throws Exception {
return integer % 2 == 0 ? "偶数" : "奇数";
}
}).subscribe(new Consumer<GroupedObservable<String, Integer>>() {
@Override
public void accept(@NonNull GroupedObservable<String, Integer> stringIntegerGroupedObservable) throws Exception {
String key = stringIntegerGroupedObservable.getKey();
Log.i(TAG, "accept: key=" + key);
if (key.equals("偶数")) {
stringIntegerGroupedObservable.subscribe(getObserver(key));
} else {
stringIntegerGroupedObservable.subscribe(getObserver(key));
}
}
});
}
开发者ID:changjiashuai,项目名称:RxJava2-Android-Sample,代码行数:21,代码来源:GroupByExampleActivity.java
示例3: completeCompletesInner
import io.reactivex.observables.GroupedObservable; //导入依赖的package包/类
@Test public void completeCompletesInner() {
Observable<Message> messages = Observable.just(new Message("Bob", "Hello"));
final AtomicInteger seen = new AtomicInteger();
WindowIfChanged.create(messages, userSelector)
.switchMap(
new Function<GroupedObservable<String, Message>, Observable<Notification<String>>>() {
@Override public Observable<Notification<String>> apply(
GroupedObservable<String, Message> group) {
final int count = seen.incrementAndGet();
return group.map(new Function<Message, String>() {
@Override public String apply(Message message) throws Exception {
return count + " " + message;
}
}).materialize();
}
})
.test()
.assertValues( //
Notification.createOnNext("1 Bob Hello"), //
Notification.<String>createOnComplete()) //
.assertComplete();
}
开发者ID:JakeWharton,项目名称:RxWindowIfChanged,代码行数:23,代码来源:WindowIfChangedTest.java
示例4: errorCompletesInner
import io.reactivex.observables.GroupedObservable; //导入依赖的package包/类
@Test public void errorCompletesInner() {
RuntimeException error = new RuntimeException("boom!");
Observable<Message> messages = Observable.just( //
Notification.createOnNext(new Message("Bob", "Hello")),
Notification.createOnError(error)
).dematerialize();
final AtomicInteger seen = new AtomicInteger();
WindowIfChanged.create(messages, userSelector)
.switchMap(
new Function<GroupedObservable<String, Message>, Observable<Notification<String>>>() {
@Override public Observable<Notification<String>> apply(
GroupedObservable<String, Message> group) {
final int count = seen.incrementAndGet();
return group.map(new Function<Message, String>() {
@Override public String apply(Message message) throws Exception {
return count + " " + message;
}
}).materialize();
}
})
.test()
.assertValues( //
Notification.createOnNext("1 Bob Hello"), //
Notification.<String>createOnComplete()) //
.assertError(error);
}
开发者ID:JakeWharton,项目名称:RxWindowIfChanged,代码行数:27,代码来源:WindowIfChangedTest.java
示例5: main
import io.reactivex.observables.GroupedObservable; //导入依赖的package包/类
public static void main(String[] args) {
Observable<String> source =
Observable.just("Alpha", "Beta", "Gamma", "Delta",
"Epsilon");
Observable<GroupedObservable<Integer, String>> byLengths =
source.groupBy(s -> s.length());
byLengths.flatMapSingle(grp ->
grp.reduce("", (x, y) -> x.equals("") ? y : x + ", " + y)
.map(s -> grp.getKey() + ": " + s)
).subscribe(System.out::println);
}
开发者ID:PacktPublishing,项目名称:Learning-RxJava,代码行数:12,代码来源:Ch4_19.java
示例6: main
import io.reactivex.observables.GroupedObservable; //导入依赖的package包/类
public static void main(String[] args) {
Observable<String> source =
Observable.just("Alpha", "Beta", "Gamma", "Delta", "Epsilon");
Observable<GroupedObservable<Integer, String>> byLengths =
source.groupBy(s -> s.length());
}
开发者ID:PacktPublishing,项目名称:Learning-RxJava,代码行数:7,代码来源:Ch4_17.java
示例7: main
import io.reactivex.observables.GroupedObservable; //导入依赖的package包/类
public static void main(String[] args) {
Observable<String> source =
Observable.just("Alpha", "Beta", "Gamma", "Delta",
"Epsilon");
Observable<GroupedObservable<Integer, String>> byLengths =
source.groupBy(s -> s.length());
byLengths.flatMapSingle(grp -> grp.toList())
.subscribe(System.out::println);
}
开发者ID:PacktPublishing,项目名称:Learning-RxJava,代码行数:10,代码来源:Ch4_18.java
示例8: testBasicGroupByObservable
import io.reactivex.observables.GroupedObservable; //导入依赖的package包/类
@Test
public void testBasicGroupByObservable() throws InterruptedException {
Observable<GroupedObservable<String, Integer>> grouped =
Observable.range(1, 100)
.groupBy(integer -> {
if (integer % 2 == 0) return "Even";
else return "Odd";
});
grouped.subscribe(g -> g.subscribe(x ->
System.out.println
("g:" + g.getKey() + ", value:" + x)));
Thread.sleep(4000);
}
开发者ID:dhinojosa,项目名称:javarx-study,代码行数:16,代码来源:ObservableFunctionalTest.java
示例9: splits
import io.reactivex.observables.GroupedObservable; //导入依赖的package包/类
@Test public void splits() {
Observable<Message> messages = Observable.just( //
new Message("Bob", "Hello"), //
new Message("Bob", "World"), //
new Message("Alice", "Hey"), //
new Message("Bob", "What's"), //
new Message("Bob", "Up?"), //
new Message("Eve", "Hey") //
);
final AtomicInteger seen = new AtomicInteger();
WindowIfChanged.create(messages, userSelector)
.switchMap(
new Function<GroupedObservable<String, Message>, Observable<Notification<String>>>() {
@Override public Observable<Notification<String>> apply(
GroupedObservable<String, Message> group) {
final int count = seen.incrementAndGet();
return group.map(new Function<Message, String>() {
@Override public String apply(Message message) throws Exception {
return count + " " + message;
}
}).materialize();
}
})
.test()
.assertValues( //
Notification.createOnNext("1 Bob Hello"), //
Notification.createOnNext("1 Bob World"), //
Notification.<String>createOnComplete(), //
Notification.createOnNext("2 Alice Hey"), //
Notification.<String>createOnComplete(), //
Notification.createOnNext("3 Bob What's"), //
Notification.createOnNext("3 Bob Up?"), //
Notification.<String>createOnComplete(), //
Notification.createOnNext("4 Eve Hey"), //
Notification.<String>createOnComplete()); //
}
开发者ID:JakeWharton,项目名称:RxWindowIfChanged,代码行数:37,代码来源:WindowIfChangedTest.java
示例10: subscribeActual
import io.reactivex.observables.GroupedObservable; //导入依赖的package包/类
@Override protected void subscribeActual(Observer<? super GroupedObservable<K, T>> observer) {
upstream.subscribe(new WindowIfChangedObserver<>(keySelector, observer));
}
开发者ID:JakeWharton,项目名称:RxWindowIfChanged,代码行数:4,代码来源:WindowIfChangedObservable.java
示例11: WindowIfChangedObserver
import io.reactivex.observables.GroupedObservable; //导入依赖的package包/类
WindowIfChangedObserver(Function<? super T, ? extends K> keySelector,
Observer<? super GroupedObservable<K, T>> observer) {
this.keySelector = keySelector;
this.observer = observer;
}
开发者ID:JakeWharton,项目名称:RxWindowIfChanged,代码行数:6,代码来源:WindowIfChangedObserver.java
示例12: create
import io.reactivex.observables.GroupedObservable; //导入依赖的package包/类
public static <T, K> Observable<GroupedObservable<K, T>> create(Observable<T> upstream,
Function<? super T, ? extends K> keySelector) {
return new WindowIfChangedObservable<>(upstream, keySelector);
}
开发者ID:JakeWharton,项目名称:RxWindowIfChanged,代码行数:5,代码来源:WindowIfChanged.java
示例13: groupBy
import io.reactivex.observables.GroupedObservable; //导入依赖的package包/类
@CheckReturnValue
@SchedulerSupport("none")
public <K> Observable<GroupedObservable<K, T>> groupBy(Function<? super T, ? extends K> keySelector) {
return boxed.groupBy(keySelector);
}
开发者ID:aol,项目名称:cyclops,代码行数:6,代码来源:ObservableKind.java
注:本文中的io.reactivex.observables.GroupedObservable类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论