RxJava2 Flowable buffer(转换操作符)

本文详细介绍了RxJava2中的Flowable buffer操作符,包括接口文档、测试用例分析和实用场景。buffer能将多个元素打包成一个列表进行发送,适用于数据聚合的场景。此外,还提及了其他相关辅助和条件操作符。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

buffer

目录

buffer接口文档

buffer测试用例

buffer测试用例分析

buffer实用场景


 

buffer接口文档

<B> Flowable<List<T>>buffer(Callable<? extends Publisher<B>> boundaryIndicatorSupplier)

Returns a Flowable that emits buffers of items it collects from the source Publisher.

返回一个Flowable,它发出从源Publisher收集的项目的缓冲区。

<B,U extends Collection<? super T>>
Flowable<U>
buffer(Callable<? extends Publisher<B>> boundaryIndicatorSupplier,Callable<U> bufferSupplier)

Returns a Flowable that emits buffers of items it collects from the source Publisher.

返回一个Flowable,它发出从源Publisher收集的项目的缓冲区。

<TOpening,TClosing>
Flowable<List<T>>
buffer(Flowable<? extends TOpening> openingIndicator, Function<? super TOpening,? extendsPublisher<? extends TClosing>> closingIndicator)

Returns a Flowable that emits buffers of items it collects from the source Publisher.

返回一个Flowable,它发出从源Publisher收集的项目的缓冲区。

<TOpening,TClosing,U extends Collection<? super T>>
Flowable<U>
buffer(Flowable<? extends TOpening> openingIndicator, Function<? super TOpening,? extendsPublisher<? extends TClosing>> closingIndicator, Callable<U> bufferSupplier)

Returns a Flowable that emits buffers of items it collects from the source Publisher.

返回一个Flowable,它发出从源Publisher收集的项目的缓冲区。

Flowable<List<T>>buffer(int count)

Returns a Flowable that emits buffers of items it collects from the source Publisher.

返回一个Flowable,它发出从源Publisher收集的项目的缓冲区。

<U extends Collection<? super T>>
Flowable<U>
buffer(int count, Callable<U> bufferSupplier)

Returns a Flowable that emits buffers of items it collects from the source Publisher.

返回一个Flowable,它发出从源Publisher收集的项目的缓冲区。

Flowable<List<T>>buffer(int count, int skip)

Returns a Flowable that emits buffers of items it collects from the source Publisher.

返回一个Flowable,它发出从源Publisher收集的项目的缓冲区。

<U extends Collection<? super T>>
Flowable<U>
buffer(int count, int skip, Callable<U> bufferSupplier)

Returns a Flowable that emits buffers of items it collects from the source Publisher.

返回一个Flowable,它发出从源Publisher收集的项目的缓冲区。

Flowable<List<T>>buffer(long timespan, long timeskip, TimeUnit unit)

Returns a Flowable that emits buffers of items it collects from the source Publisher.

返回一个Flowable,它发出从源Publisher收集的项目的缓冲区。

Flowable<List<T>>buffer(long timespan, long timeskip, TimeUnit unit, Scheduler scheduler)

Returns a Flowable that emits buffers of items it collects from the source Publisher.

返回一个Flowable,它发出从源Publisher收集的项目的缓冲区。

<U extends Collection<? super T>>
Flowable<U>
buffer(long timespan, long timeskip, TimeUnit unit, Scheduler scheduler,Callable<U> bufferSupplier)

Returns a Flowable that emits buffers of items it collects from the source Publisher.

返回一个Flowable,它发出从源Publisher收集的项目的缓冲区。

Flowable<List<T>>buffer(long timespan, TimeUnit unit)

Returns a Flowable that emits buffers of items it collects from the source Publisher.

返回一个Flowable,它发出从源Publisher收集的项目的缓冲区。

Flowable<List<T>>buffer(long timespan, TimeUnit unit, int count)

Returns a Flowable that emits buffers of items it collects from the source Publisher.

返回一个Flowable,它发出从源Publisher收集的项目的缓冲区。

Flowable<List<T>>buffer(long timespan, TimeUnit unit, Scheduler scheduler)

Returns a Flowable that emits buffers of items it collects from the source Publisher.

返回一个Flowable,它发出从源Publisher收集的项目的缓冲区。

Flowable<List<T>>buffer(long timespan, TimeUnit unit, Scheduler scheduler, int count)

Returns a Flowable that emits buffers of items it collects from the source Publisher.

返回一个Flowable,它发出从源Publisher收集的项目的缓冲区。

<U extends Collection<? super T>>
Flowable<U>
buffer(long timespan, TimeUnit unit, Scheduler scheduler, int count,Callable<U> bufferSupplier, boolean restartTimerOnMaxSize)

Returns a Flowable that emits buffers of items it collects from the source Publisher.

返回一个Flowable,它发出从源Publisher收集的项目的缓冲区。

<B> Flowable<List<T>>buffer(Publisher<B> boundaryIndicator)

Returns a Flowable that emits non-overlapping buffered items from the source Publisher each time the specified boundary Publisher emits an item.

返回一个Flowable,每次指定的边界Publisher发出项目时,它都会从源Publisher发出非重叠的缓冲项。

<B,U extends Collection<? super T>>
Flowable<U>
buffer(Publisher<B> boundaryIndicator, Callable<U> bufferSupplier)

Returns a Flowable that emits non-overlapping buffered items from the source Publisher each time the specified boundary Publisher emits an item.

返回一个Flowable,每次指定的边界Publisher发出项目时,它都会从源Publisher发出非重叠的缓冲项。

<B> Flowable<List<T>>buffer(Publisher<B> boundaryIndicator, int initialCapacity)

Returns a Flowable that emits non-overlapping buffered items from the source Publisher each time the specified boundary Publisher emits an item.

返回一个Flowable,每次指定的边界Publisher发出项目时,它都会从源Publisher发出非重叠的缓冲项。

buffer测试用例

buffer的重载方法太多,这里不一一举例

测试代码
  @Test
    public void buffer3() {
        System.out.println("######buffer3#####");
        Flowable.just(10, 22, 13, 74, 52)
                .buffer(2)//三个元素打包成一个元素
                .subscribe(new Consumer<List<Integer>>() {
                    @Override
                    public void accept(List<Integer> integers) throws Exception {
                        System.out.println(integers.toString());
                    }
                });
    }
测试结果:
######buffer3#####
[10, 22]
[13, 74]
[52]

 

buffer测试用例分析

buffer操作符是把多个元素按照指定数量打包成一个元素一次过发送数据,上面测试用例实际上每次把2个元素组合成一个List发送。

至于其他重载方法,都是类似的作用,只是相应的配置不同。

buffer实用场景

后续完善

 

其他操作符

delay delaySubscription(辅助操作符)

delaySubscription(辅助操作符)

switchIfEmpty(条件操作符)

debounce(过滤操作符)去重复操作

count(统计操作符)

contains(条件操作符)

concatWith(连接操作符)

concatMap(变换操作符)

collect & collectInto

cast

cache

buffer

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值