io.reactivex.Observable.concatArray()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(14.1k)|赞(0)|评价(0)|浏览(207)

本文整理了Java中io.reactivex.Observable.concatArray()方法的一些代码示例,展示了Observable.concatArray()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Observable.concatArray()方法的具体详情如下:
包路径:io.reactivex.Observable
类名称:Observable
方法名:concatArray

Observable.concatArray介绍

[英]Concatenates a variable number of ObservableSource sources.

Note: named this way because of overload conflict with concat(ObservableSource<ObservableSource>)

Scheduler: concatArray does not operate by default on a particular Scheduler.
[中]连接可变数量的可观测源。
注意:之所以这样命名是因为与concat(observedsource<observedsource>)的重载冲突
调度程序:默认情况下,concatArray不会在特定调度程序上运行。

代码示例

代码示例来源:origin: ReactiveX/RxJava

  1. @Test(expected = NullPointerException.class)
  2. public void concatArrayNull() {
  3. Observable.concatArray((Observable<Object>[])null);
  4. }

代码示例来源:origin: ReactiveX/RxJava

  1. /**
  2. * Returns an Observable that emits a specified item before it begins to emit items emitted by the source
  3. * ObservableSource.
  4. * <p>
  5. * <img width="640" height="315" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/startWith.item.png" alt="">
  6. * <dl>
  7. * <dt><b>Scheduler:</b></dt>
  8. * <dd>{@code startWith} does not operate by default on a particular {@link Scheduler}.</dd>
  9. * </dl>
  10. *
  11. * @param item
  12. * the item to emit first
  13. * @return an Observable that emits the specified item before it begins to emit items emitted by the source
  14. * ObservableSource
  15. * @see <a href="http://reactivex.io/documentation/operators/startwith.html">ReactiveX operators documentation: StartWith</a>
  16. */
  17. @SuppressWarnings("unchecked")
  18. @CheckReturnValue
  19. @SchedulerSupport(SchedulerSupport.NONE)
  20. public final Observable<T> startWith(T item) {
  21. ObjectHelper.requireNonNull(item, "item is null");
  22. return concatArray(just(item), this);
  23. }

代码示例来源:origin: ReactiveX/RxJava

  1. /**
  2. * Returns an Observable that emits the items in a specified {@link Iterable} before it begins to emit items
  3. * emitted by the source ObservableSource.
  4. * <p>
  5. * <img width="640" height="315" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/startWith.png" alt="">
  6. * <dl>
  7. * <dt><b>Scheduler:</b></dt>
  8. * <dd>{@code startWith} does not operate by default on a particular {@link Scheduler}.</dd>
  9. * </dl>
  10. *
  11. * @param items
  12. * an Iterable that contains the items you want the modified ObservableSource to emit first
  13. * @return an Observable that emits the items in the specified {@link Iterable} and then emits the items
  14. * emitted by the source ObservableSource
  15. * @see <a href="http://reactivex.io/documentation/operators/startwith.html">ReactiveX operators documentation: StartWith</a>
  16. */
  17. @SuppressWarnings("unchecked")
  18. @CheckReturnValue
  19. @SchedulerSupport(SchedulerSupport.NONE)
  20. public final Observable<T> startWith(Iterable<? extends T> items) {
  21. return concatArray(fromIterable(items), this);
  22. }

代码示例来源:origin: ReactiveX/RxJava

  1. /**
  2. * Returns an Observable that emits the items in a specified {@link ObservableSource} before it begins to emit
  3. * items emitted by the source ObservableSource.
  4. * <p>
  5. * <img width="640" height="315" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/startWith.o.png" alt="">
  6. * <dl>
  7. * <dt><b>Scheduler:</b></dt>
  8. * <dd>{@code startWith} does not operate by default on a particular {@link Scheduler}.</dd>
  9. * </dl>
  10. *
  11. * @param other
  12. * an ObservableSource that contains the items you want the modified ObservableSource to emit first
  13. * @return an Observable that emits the items in the specified {@link ObservableSource} and then emits the items
  14. * emitted by the source ObservableSource
  15. * @see <a href="http://reactivex.io/documentation/operators/startwith.html">ReactiveX operators documentation: StartWith</a>
  16. */
  17. @SuppressWarnings("unchecked")
  18. @CheckReturnValue
  19. @SchedulerSupport(SchedulerSupport.NONE)
  20. public final Observable<T> startWith(ObservableSource<? extends T> other) {
  21. ObjectHelper.requireNonNull(other, "other is null");
  22. return concatArray(other, this);
  23. }

代码示例来源:origin: ReactiveX/RxJava

  1. @SuppressWarnings("unchecked")
  2. @Test(expected = NullPointerException.class)
  3. public void concatArrayOneIsNull() {
  4. Observable.concatArray(just1, null).blockingLast();
  5. }

代码示例来源:origin: redisson/redisson

  1. /**
  2. * Returns an Observable that emits a specified item before it begins to emit items emitted by the source
  3. * ObservableSource.
  4. * <p>
  5. * <img width="640" height="315" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/startWith.item.png" alt="">
  6. * <dl>
  7. * <dt><b>Scheduler:</b></dt>
  8. * <dd>{@code startWith} does not operate by default on a particular {@link Scheduler}.</dd>
  9. * </dl>
  10. *
  11. * @param item
  12. * the item to emit first
  13. * @return an Observable that emits the specified item before it begins to emit items emitted by the source
  14. * ObservableSource
  15. * @see <a href="http://reactivex.io/documentation/operators/startwith.html">ReactiveX operators documentation: StartWith</a>
  16. */
  17. @SuppressWarnings("unchecked")
  18. @CheckReturnValue
  19. @SchedulerSupport(SchedulerSupport.NONE)
  20. public final Observable<T> startWith(T item) {
  21. ObjectHelper.requireNonNull(item, "item is null");
  22. return concatArray(just(item), this);
  23. }

代码示例来源:origin: redisson/redisson

  1. /**
  2. * Returns an Observable that emits the items in a specified {@link Iterable} before it begins to emit items
  3. * emitted by the source ObservableSource.
  4. * <p>
  5. * <img width="640" height="315" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/startWith.png" alt="">
  6. * <dl>
  7. * <dt><b>Scheduler:</b></dt>
  8. * <dd>{@code startWith} does not operate by default on a particular {@link Scheduler}.</dd>
  9. * </dl>
  10. *
  11. * @param items
  12. * an Iterable that contains the items you want the modified ObservableSource to emit first
  13. * @return an Observable that emits the items in the specified {@link Iterable} and then emits the items
  14. * emitted by the source ObservableSource
  15. * @see <a href="http://reactivex.io/documentation/operators/startwith.html">ReactiveX operators documentation: StartWith</a>
  16. */
  17. @SuppressWarnings("unchecked")
  18. @CheckReturnValue
  19. @SchedulerSupport(SchedulerSupport.NONE)
  20. public final Observable<T> startWith(Iterable<? extends T> items) {
  21. return concatArray(fromIterable(items), this);
  22. }

代码示例来源:origin: redisson/redisson

  1. /**
  2. * Returns an Observable that emits the items in a specified {@link ObservableSource} before it begins to emit
  3. * items emitted by the source ObservableSource.
  4. * <p>
  5. * <img width="640" height="315" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/startWith.o.png" alt="">
  6. * <dl>
  7. * <dt><b>Scheduler:</b></dt>
  8. * <dd>{@code startWith} does not operate by default on a particular {@link Scheduler}.</dd>
  9. * </dl>
  10. *
  11. * @param other
  12. * an ObservableSource that contains the items you want the modified ObservableSource to emit first
  13. * @return an Observable that emits the items in the specified {@link ObservableSource} and then emits the items
  14. * emitted by the source ObservableSource
  15. * @see <a href="http://reactivex.io/documentation/operators/startwith.html">ReactiveX operators documentation: StartWith</a>
  16. */
  17. @SuppressWarnings("unchecked")
  18. @CheckReturnValue
  19. @SchedulerSupport(SchedulerSupport.NONE)
  20. public final Observable<T> startWith(ObservableSource<? extends T> other) {
  21. ObjectHelper.requireNonNull(other, "other is null");
  22. return concatArray(other, this);
  23. }

代码示例来源:origin: ReactiveX/RxJava

  1. /**
  2. * Returns an Observable that emits the specified items before it begins to emit items emitted by the source
  3. * ObservableSource.
  4. * <p>
  5. * <img width="640" height="315" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/startWithArray.png" alt="">
  6. * <dl>
  7. * <dt><b>Scheduler:</b></dt>
  8. * <dd>{@code startWithArray} does not operate by default on a particular {@link Scheduler}.</dd>
  9. * </dl>
  10. *
  11. * @param items
  12. * the array of values to emit first
  13. * @return an Observable that emits the specified items before it begins to emit items emitted by the source
  14. * ObservableSource
  15. * @see <a href="http://reactivex.io/documentation/operators/startwith.html">ReactiveX operators documentation: StartWith</a>
  16. */
  17. @SuppressWarnings("unchecked")
  18. @CheckReturnValue
  19. @SchedulerSupport(SchedulerSupport.NONE)
  20. public final Observable<T> startWithArray(T... items) {
  21. Observable<T> fromArray = fromArray(items);
  22. if (fromArray == empty()) {
  23. return RxJavaPlugins.onAssembly(this);
  24. }
  25. return concatArray(fromArray, this);
  26. }

代码示例来源:origin: ReactiveX/RxJava

  1. @SuppressWarnings("unchecked")
  2. @Test
  3. public void concatArrayEmpty() {
  4. assertSame(Observable.empty(), Observable.concatArray());
  5. }

代码示例来源:origin: ReactiveX/RxJava

  1. @SuppressWarnings("unchecked")
  2. @Test
  3. public void noCancelPreviousArray() {
  4. final AtomicInteger counter = new AtomicInteger();
  5. Observable<Integer> source = Observable.just(1).doOnDispose(new Action() {
  6. @Override
  7. public void run() throws Exception {
  8. counter.getAndIncrement();
  9. }
  10. });
  11. Observable.concatArray(source, source, source, source, source)
  12. .test()
  13. .assertResult(1, 1, 1, 1, 1);
  14. assertEquals(0, counter.get());
  15. }

代码示例来源:origin: ReactiveX/RxJava

  1. /**
  2. * Returns an Observable that emits the items emitted by two ObservableSources, one after the other, without
  3. * interleaving them.
  4. * <p>
  5. * <img width="640" height="380" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/concat.png" alt="">
  6. * <dl>
  7. * <dt><b>Scheduler:</b></dt>
  8. * <dd>{@code concat} does not operate by default on a particular {@link Scheduler}.</dd>
  9. * </dl>
  10. *
  11. * @param <T> the common element base type
  12. * @param source1
  13. * an ObservableSource to be concatenated
  14. * @param source2
  15. * an ObservableSource to be concatenated
  16. * @return an Observable that emits items emitted by the two source ObservableSources, one after the other,
  17. * without interleaving them
  18. * @see <a href="http://reactivex.io/documentation/operators/concat.html">ReactiveX operators documentation: Concat</a>
  19. */
  20. @SuppressWarnings("unchecked")
  21. @CheckReturnValue
  22. @NonNull
  23. @SchedulerSupport(SchedulerSupport.NONE)
  24. public static <T> Observable<T> concat(ObservableSource<? extends T> source1, ObservableSource<? extends T> source2) {
  25. ObjectHelper.requireNonNull(source1, "source1 is null");
  26. ObjectHelper.requireNonNull(source2, "source2 is null");
  27. return concatArray(source1, source2);
  28. }

代码示例来源:origin: redisson/redisson

  1. /**
  2. * Returns an Observable that emits the items emitted by two ObservableSources, one after the other, without
  3. * interleaving them.
  4. * <p>
  5. * <img width="640" height="380" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/concat.png" alt="">
  6. * <dl>
  7. * <dt><b>Scheduler:</b></dt>
  8. * <dd>{@code concat} does not operate by default on a particular {@link Scheduler}.</dd>
  9. * </dl>
  10. *
  11. * @param <T> the common element base type
  12. * @param source1
  13. * an ObservableSource to be concatenated
  14. * @param source2
  15. * an ObservableSource to be concatenated
  16. * @return an Observable that emits items emitted by the two source ObservableSources, one after the other,
  17. * without interleaving them
  18. * @see <a href="http://reactivex.io/documentation/operators/concat.html">ReactiveX operators documentation: Concat</a>
  19. */
  20. @SuppressWarnings("unchecked")
  21. @CheckReturnValue
  22. @SchedulerSupport(SchedulerSupport.NONE)
  23. public static <T> Observable<T> concat(ObservableSource<? extends T> source1, ObservableSource<? extends T> source2) {
  24. ObjectHelper.requireNonNull(source1, "source1 is null");
  25. ObjectHelper.requireNonNull(source2, "source2 is null");
  26. return concatArray(source1, source2);
  27. }

代码示例来源:origin: ReactiveX/RxJava

  1. @SuppressWarnings("unchecked")
  2. @Test
  3. public void concatArraySingleElement() {
  4. assertSame(Observable.never(), Observable.concatArray(Observable.never()));
  5. }

代码示例来源:origin: ReactiveX/RxJava

  1. ObjectHelper.requireNonNull(source2, "source2 is null");
  2. ObjectHelper.requireNonNull(source3, "source3 is null");
  3. return concatArray(source1, source2, source3);

代码示例来源:origin: redisson/redisson

  1. /**
  2. * Returns an Observable that emits the specified items before it begins to emit items emitted by the source
  3. * ObservableSource.
  4. * <p>
  5. * <img width="640" height="315" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/startWithArray.png" alt="">
  6. * <dl>
  7. * <dt><b>Scheduler:</b></dt>
  8. * <dd>{@code startWithArray} does not operate by default on a particular {@link Scheduler}.</dd>
  9. * </dl>
  10. *
  11. * @param items
  12. * the array of values to emit first
  13. * @return an Observable that emits the specified items before it begins to emit items emitted by the source
  14. * ObservableSource
  15. * @see <a href="http://reactivex.io/documentation/operators/startwith.html">ReactiveX operators documentation: StartWith</a>
  16. */
  17. @SuppressWarnings("unchecked")
  18. @CheckReturnValue
  19. @SchedulerSupport(SchedulerSupport.NONE)
  20. public final Observable<T> startWithArray(T... items) {
  21. Observable<T> fromArray = fromArray(items);
  22. if (fromArray == empty()) {
  23. return RxJavaPlugins.onAssembly(this);
  24. }
  25. return concatArray(fromArray, this);
  26. }

代码示例来源:origin: redisson/redisson

  1. ObjectHelper.requireNonNull(source2, "source2 is null");
  2. ObjectHelper.requireNonNull(source3, "source3 is null");
  3. return concatArray(source1, source2, source3);

代码示例来源:origin: ReactiveX/RxJava

  1. ObjectHelper.requireNonNull(source3, "source3 is null");
  2. ObjectHelper.requireNonNull(source4, "source4 is null");
  3. return concatArray(source1, source2, source3, source4);

代码示例来源:origin: redisson/redisson

  1. ObjectHelper.requireNonNull(source3, "source3 is null");
  2. ObjectHelper.requireNonNull(source4, "source4 is null");
  3. return concatArray(source1, source2, source3, source4);

代码示例来源:origin: ReactiveX/RxJava

  1. @SuppressWarnings("unchecked")
  2. @Test
  3. public void noSubsequentSubscription() {
  4. final int[] calls = { 0 };
  5. Observable<Integer> source = Observable.create(new ObservableOnSubscribe<Integer>() {
  6. @Override
  7. public void subscribe(ObservableEmitter<Integer> s) throws Exception {
  8. calls[0]++;
  9. s.onNext(1);
  10. s.onComplete();
  11. }
  12. });
  13. Observable.concatArray(source, source).firstElement()
  14. .test()
  15. .assertResult(1);
  16. assertEquals(1, calls[0]);
  17. }

相关文章

Observable类方法