本文整理汇总了Java中io.reactivex.Flowable.generate方法的典型用法代码示例。如果您正苦于以下问题:Java Flowable.generate方法的具体用法?Java Flowable.generate怎么用?Java Flowable.generate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.reactivex.Flowable
的用法示例。
在下文中一共展示了Flowable.generate方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: path
import io.reactivex.Flowable; //导入方法依赖的package包/类
/**
* @param downNode
* @param upNode
* @return from downNode to upNode's path
*/
private static <T> Flowable<Tree<T>> path(Tree<T> downNode, Tree<T> upNode) {
return Flowable.generate(() -> Wrapper.of(downNode), (w, e) -> {
Tree<T> node = w.get();
if (node == null) {
e.onComplete();
} else {
e.onNext(node);
if (node == upNode) {
w.set(null);
} else {
Tree<T> parent = node.getParent();
w.set(parent);
}
}
});
}
示例2: rangeReverse
import io.reactivex.Flowable; //导入方法依赖的package包/类
static Flowable<Integer> rangeReverse(int upperBound, int
lowerBound) {
return Flowable.generate(() -> new
AtomicInteger(upperBound + 1),
(state, emitter) -> {
int current = state.decrementAndGet();
emitter.onNext(current);
if (current == lowerBound)
emitter.onComplete();
}
);
}
示例3: parents
import io.reactivex.Flowable; //导入方法依赖的package包/类
/**
* Get all of the node's parent
*
* @return
*/
public Flowable<Tree<T>> parents() {
return Flowable.generate(() -> Wrapper.of(this), (n, e) -> {
Tree<T> parent = n.get().getParent();
if (parent != null) {
e.onNext(parent);
n.set(parent);
} else {
e.onComplete();
}
});
}
示例4: postOrderTraversal
import io.reactivex.Flowable; //导入方法依赖的package包/类
public static <T> Flowable<T> postOrderTraversal(T root, Function<T, Iterable<T>> getChildren) {
return Flowable.generate(() -> newDeque(Either.<Iterator<T>, T> left(Arrays.asList(root).iterator())), (d, e) -> {
Either<Iterator<T>, T> item;
while (true) {
if (d.isEmpty()) {
e.onComplete();
return;
}
item = d.peek();
item.exec(iterator -> {
if (iterator.hasNext()) {
T t = iterator.next();
Iterator<T> children = getChildren.apply(t).iterator();
d.push(Either.right(t));
if (children.hasNext()) {
d.push(Either.left(children));
}
} else {
d.pop();
}
}, value -> {
d.pop();
e.onNext(value);
});
if (item.isRight()) {
return;
}
}
});
}
示例5: randomGenerator
import io.reactivex.Flowable; //导入方法依赖的package包/类
static Flowable<Integer> randomGenerator(int min, int max) {
return Flowable.generate(emitter ->
emitter.onNext(ThreadLocalRandom.current().nextInt(min, max))
);
}
示例6: createObservableContinousLongPolling
import io.reactivex.Flowable; //导入方法依赖的package包/类
private static Flowable<SqsMessage> createObservableContinousLongPolling(AmazonSQS sqs, String queueName,
Optional<String> bucketName, Optional<AmazonS3> s3, final Service service) {
final ContinuousLongPollingSyncOnSubscribe c = new ContinuousLongPollingSyncOnSubscribe(sqs, queueName, s3,
bucketName, service);
return Flowable.generate(c, c);
}