本文整理汇总了Java中io.reactivex.Flowable.fromArray方法的典型用法代码示例。如果您正苦于以下问题:Java Flowable.fromArray方法的具体用法?Java Flowable.fromArray怎么用?Java Flowable.fromArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.reactivex.Flowable
的用法示例。
在下文中一共展示了Flowable.fromArray方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testConservationWhenTransformingPayloadStream
import io.reactivex.Flowable; //导入方法依赖的package包/类
@Test
public void testConservationWhenTransformingPayloadStream() {
Flowable<Data<Double>> flowable = Flowable.fromArray(producer.get(), producer.get(), producer.get(), producer.get(), producer.get());
ListSink<String> sink = Sink.list();
Source.from(flowable)
.transformPayloadFlow(s -> s.map(x -> {
if (random.nextBoolean()) {
return "foo";
}
return "bar";
}).map(String::toUpperCase)
)
.to(sink);
assertThat(sink.values()).hasSize(5);
for (Data<String> d : sink.data()) {
assertThat((long) d.get("timestamp")).isNotNull().isNotZero().isNotNegative();
assertThat((int) d.get("index")).isNotNull().isNotZero().isNotNegative();
assertThat(d.payload()).isIn("FOO", "BAR");
}
}
示例2: testZip
import io.reactivex.Flowable; //导入方法依赖的package包/类
@Test
public void testZip() {
Flowable<String> f1 = Flowable.fromArray("a", "b", "c");
Flowable<String> f2 = Flowable.fromArray("1", "2", "3");
CacheSink<String> cache = new CacheSink<>();
Source.fromPayloads(f1).transformPayload(String::toUpperCase).zipWith(Source.fromPayloads(f2))
.transformPayload(pair -> pair.left() + ":" + pair.right() + "\n")
.to(cache);
await().until(() -> cache.cache().size() == 3);
assertThat(cache.cache()).containsExactly("A:1\n", "B:2\n", "C:3\n");
}
示例3: testConservationWhenTransformingPayloadStreamWithDoubleEmission
import io.reactivex.Flowable; //导入方法依赖的package包/类
@Test
public void testConservationWhenTransformingPayloadStreamWithDoubleEmission() {
Flowable<Data<Double>> flowable = Flowable.fromArray(producer.get(), producer.get(), producer.get(), producer.get(), producer.get());
ListSink<String> sink = Sink.list();
Source.from(flowable)
.transformPayloadFlow(s -> s
.map(x -> {
if (random.nextBoolean()) {
return "foo";
}
return "bar";
})
.flatMap(v -> Flowable.just(v.toUpperCase(), v.toUpperCase()))
)
.to(sink);
assertThat(sink.values()).hasSize(10);
int i = 1;
long lastTimestamp = 0;
int lastIndex = 0;
for (Data<String> d : sink.data()) {
assertThat((long) d.get("timestamp")).isNotNull().isNotZero().isNotNegative();
assertThat((int) d.get("index")).isNotNull().isNotZero().isNotNegative();
assertThat(d.payload()).isIn("FOO", "BAR");
if (i % 2 == 0) {
assertThat((long) d.get("timestamp")).isEqualTo(lastTimestamp);
assertThat((int) d.get("index")).isEqualTo(lastIndex);
} else {
lastTimestamp = d.get("timestamp");
lastIndex = d.get("index");
}
i++;
}
}
示例4: flowable
import io.reactivex.Flowable; //导入方法依赖的package包/类
@Override
public Flowable<T> flowable() {
return Flowable.fromArray(get());
}