本文整理了Java中io.reactivex.Flowable.toSortedList()
方法的一些代码示例,展示了Flowable.toSortedList()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Flowable.toSortedList()
方法的具体详情如下:
包路径:io.reactivex.Flowable
类名称:Flowable
方法名:toSortedList
[英]Returns a Single that emits a list that contains the items emitted by the finite 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 this operator requires the upstream to signal onComplete for the accumulated list to be emitted. Sources that are infinite and never complete will never emit anything through this operator and an infinite source may lead to a fatal 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: toSortedList does not operate by default on a particular Scheduler.
[中]返回以排序顺序发出包含有限源发布服务器发出的项的列表的单个项。发布者发出的每个项目必须实现与序列中所有其他项目的可比性。
如果此可流动项发出的任何项未实现与此可流动项发出的所有其他项的可比性,则不会发出任何项,并且序列将以ClassCastException终止。
请注意,此运算符要求上游发出“完成”信号,以发出累积列表。无限且永远不完整的源永远不会通过此运算符发出任何信息,无限源可能导致致命的OutOfMemoryError。背压:操作员接受来自下游的背压,并以无限制的方式消耗源发布服务器(即,不向其施加背压)。Scheduler:toSortedList默认情况下不在特定计划程序上运行。
代码示例来源:origin: ReactiveX/RxJava
@Test(expected = NullPointerException.class)
public void toSortedListNull() {
just1.toSortedList(null);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testSortedList() {
Flowable<Integer> w = Flowable.just(1, 3, 2, 5, 4);
Single<List<Integer>> single = w.toSortedList();
SingleObserver<List<Integer>> observer = TestHelper.mockSingleObserver();
single.subscribe(observer);
verify(observer, times(1)).onSuccess(Arrays.asList(1, 2, 3, 4, 5));
verify(observer, Mockito.never()).onError(any(Throwable.class));
}
代码示例来源:origin: ReactiveX/RxJava
@Override
public Publisher<List<Integer>> createPublisher(final long elements) {
return
Flowable.range(1, 1000).toSortedList().toFlowable()
;
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testSortedListWithCustomFunction() {
Flowable<Integer> w = Flowable.just(1, 3, 2, 5, 4);
Single<List<Integer>> single = w.toSortedList(new Comparator<Integer>() {
@Override
public int compare(Integer t1, Integer t2) {
return t2 - t1;
}
});
SingleObserver<List<Integer>> observer = TestHelper.mockSingleObserver();
single.subscribe(observer);
verify(observer, times(1)).onSuccess(Arrays.asList(5, 4, 3, 2, 1));
verify(observer, Mockito.never()).onError(any(Throwable.class));
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testSortedListFlowable() {
Flowable<Integer> w = Flowable.just(1, 3, 2, 5, 4);
Flowable<List<Integer>> flowable = w.toSortedList().toFlowable();
Subscriber<List<Integer>> subscriber = TestHelper.mockSubscriber();
flowable.subscribe(subscriber);
verify(subscriber, times(1)).onNext(Arrays.asList(1, 2, 3, 4, 5));
verify(subscriber, Mockito.never()).onError(any(Throwable.class));
verify(subscriber, times(1)).onComplete();
}
代码示例来源:origin: ReactiveX/RxJava
@SchedulerSupport(SchedulerSupport.NONE)
public final Single<List<T>> toSortedList() {
return toSortedList(Functions.naturalComparator());
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testSortedListWithCustomFunctionFlowable() {
Flowable<Integer> w = Flowable.just(1, 3, 2, 5, 4);
Flowable<List<Integer>> flowable = w.toSortedList(new Comparator<Integer>() {
@Override
public int compare(Integer t1, Integer t2) {
return t2 - t1;
}
}).toFlowable();
Subscriber<List<Integer>> subscriber = TestHelper.mockSubscriber();
flowable.subscribe(subscriber);
verify(subscriber, times(1)).onNext(Arrays.asList(5, 4, 3, 2, 1));
verify(subscriber, Mockito.never()).onError(any(Throwable.class));
verify(subscriber, times(1)).onComplete();
}
代码示例来源:origin: ReactiveX/RxJava
@SchedulerSupport(SchedulerSupport.NONE)
public final Single<List<T>> toSortedList(int capacityHint) {
return toSortedList(Functions.naturalComparator(), capacityHint);
代码示例来源:origin: ReactiveX/RxJava
@SuppressWarnings("unchecked")
@Test
public void toSortedListCapacity() {
Flowable.just(5, 1, 2, 4, 3).toSortedList(4)
.test()
.assertResult(Arrays.asList(1, 2, 3, 4, 5));
}
代码示例来源:origin: ReactiveX/RxJava
@SuppressWarnings("unchecked")
@Test
public void toSortedListComparatorCapacity() {
Flowable.just(5, 1, 2, 4, 3).toSortedList(new Comparator<Integer>() {
@Override
public int compare(Integer a, Integer b) {
return b - a;
}
}, 4)
.test()
.assertResult(Arrays.asList(5, 4, 3, 2, 1));
}
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testWithFollowingFirst() {
Flowable<Integer> f = Flowable.just(1, 3, 2, 5, 4);
assertEquals(Arrays.asList(1, 2, 3, 4, 5), f.toSortedList().blockingGet());
}
代码示例来源:origin: ReactiveX/RxJava
@SuppressWarnings("unchecked")
@Test
public void toSortedListComparatorCapacityFlowable() {
Flowable.just(5, 1, 2, 4, 3).toSortedList(new Comparator<Integer>() {
@Override
public int compare(Integer a, Integer b) {
return b - a;
}
}, 4).toFlowable()
.test()
.assertResult(Arrays.asList(5, 4, 3, 2, 1));
}
代码示例来源:origin: ReactiveX/RxJava
@SuppressWarnings("unchecked")
@Test
public void toSortedListCapacityFlowable() {
Flowable.just(5, 1, 2, 4, 3).toSortedList(4).toFlowable()
.test()
.assertResult(Arrays.asList(1, 2, 3, 4, 5));
}
代码示例来源:origin: redisson/redisson
@SchedulerSupport(SchedulerSupport.NONE)
public final Single<List<T>> toSortedList() {
return toSortedList(Functions.naturalComparator());
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testWithFollowingFirstFlowable() {
Flowable<Integer> f = Flowable.just(1, 3, 2, 5, 4);
assertEquals(Arrays.asList(1, 2, 3, 4, 5), f.toSortedList().toFlowable().blockingFirst());
}
代码示例来源:origin: redisson/redisson
@SchedulerSupport(SchedulerSupport.NONE)
public final Single<List<T>> toSortedList(int capacityHint) {
return toSortedList(Functions.naturalComparator(), capacityHint);
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testSortedList() {
Comparator<Media> sortFunction = new Comparator<Media>() {
@Override
public int compare(Media t1, Media t2) {
return 1;
}
};
// this one would work without the covariance generics
Flowable<Media> f = Flowable.just(new Movie(), new TVSeason(), new Album());
f.toSortedList(sortFunction);
// this one would NOT work without the covariance generics
Flowable<Movie> f2 = Flowable.just(new Movie(), new ActionMovie(), new HorrorMovie());
f2.toSortedList(sortFunction);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
@Ignore("Single doesn't do backpressure")
public void testBackpressureHonored() {
Single<List<Integer>> w = Flowable.just(1, 3, 2, 5, 4).toSortedList();
TestObserver<List<Integer>> to = new TestObserver<List<Integer>>();
w.subscribe(to);
to.assertNoValues();
to.assertNoErrors();
to.assertNotComplete();
// ts.request(1);
to.assertValue(Arrays.asList(1, 2, 3, 4, 5));
to.assertNoErrors();
to.assertComplete();
// ts.request(1);
to.assertValue(Arrays.asList(1, 2, 3, 4, 5));
to.assertNoErrors();
to.assertComplete();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testBackpressureHonoredFlowable() {
Flowable<List<Integer>> w = Flowable.just(1, 3, 2, 5, 4).toSortedList().toFlowable();
TestSubscriber<List<Integer>> ts = new TestSubscriber<List<Integer>>(0L);
w.subscribe(ts);
ts.assertNoValues();
ts.assertNoErrors();
ts.assertNotComplete();
ts.request(1);
ts.assertValue(Arrays.asList(1, 2, 3, 4, 5));
ts.assertNoErrors();
ts.assertComplete();
ts.request(1);
ts.assertValue(Arrays.asList(1, 2, 3, 4, 5));
ts.assertNoErrors();
ts.assertComplete();
}
代码示例来源:origin: com.github.rahulsom/grooves-api
return concatenatedEvents
.filter(it -> !isDeprecatesOrConverse(event, converse, it))
.toSortedList(Comparator.comparing(EventT::getTimestamp))
.toFlowable()
.doOnNext(it ->
内容来源于网络,如有侵权,请联系作者删除!