本文整理了Java中io.reactivex.Flowable.sorted()
方法的一些代码示例,展示了Flowable.sorted()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Flowable.sorted()
方法的具体详情如下:
包路径:io.reactivex.Flowable
类名称:Flowable
方法名:sorted
[英]Returns a Flowable that emits the events emitted by source Publisher, in a sorted order. Each item emitted by the Publisher must implement Comparable with respect to all other items in the sequence.
If any item emitted by this Flowable does not implement Comparable with respect to all other items emitted by this Flowable, no items will be emitted and the sequence is terminated with a ClassCastException.
Note that calling sorted with long, non-terminating or infinite sources might cause OutOfMemoryError Backpressure: The operator honors backpressure from downstream and consumes the source Publisher in an unbounded manner (i.e., without applying backpressure to it). Scheduler: sorted does not operate by default on a particular Scheduler.
[中]返回按排序顺序发出源发布服务器发出的事件的可流动文件。发布者发出的每个项目必须实现与序列中所有其他项目的可比性。
如果此可流动项发出的任何项未实现与此可流动项发出的所有其他项的可比性,则不会发出任何项,并且序列将以ClassCastException终止。
请注意,使用长源、非终止源或无限源排序的调用可能会导致OutOfMemoryError背压:操作员接受来自下游的背压,并以无限制的方式使用源发布服务器(即,不向其应用背压)。调度程序:默认情况下,排序不会在特定调度程序上运行。
代码示例来源:origin: ReactiveX/RxJava
@Override
public Publisher<Integer> createPublisher(long elements) {
return
Flowable.range(0, (int)elements).sorted()
;
}
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void sorted() {
Flowable.just(5, 1, 2, 4, 3).sorted()
.test()
.assertResult(1, 2, 3, 4, 5);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void sortedComparator() {
Flowable.just(5, 1, 2, 4, 3).sorted(new Comparator<Integer>() {
@Override
public int compare(Integer a, Integer b) {
return b - a;
}
})
.test()
.assertResult(5, 4, 3, 2, 1);
}
代码示例来源:origin: akarnokd/akarnokd-misc
@Test
public void testRx() {
for (int i = 1; i < 1000; i++) {
final int j = i;
Flowable.range(1, i).map(v -> j - v)
.sorted()
.zipWith(Flowable.range(1, Integer.MAX_VALUE), (a, b) -> Tuples.of(a, b))
.toList()
.map(list -> list.size())
.test()
.assertResult(i);
}
}
内容来源于网络,如有侵权,请联系作者删除!