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

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

本文整理了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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

/**
 * Returns an Observable that emits the specified items before it begins to emit items emitted by the source
 * ObservableSource.
 * <p>
 * <img width="640" height="315" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/startWithArray.png" alt="">
 * <dl>
 *  <dt><b>Scheduler:</b></dt>
 *  <dd>{@code startWithArray} does not operate by default on a particular {@link Scheduler}.</dd>
 * </dl>
 *
 * @param items
 *            the array of values to emit first
 * @return an Observable that emits the specified items before it begins to emit items emitted by the source
 *         ObservableSource
 * @see <a href="http://reactivex.io/documentation/operators/startwith.html">ReactiveX operators documentation: StartWith</a>
 */
@SuppressWarnings("unchecked")
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public final Observable<T> startWithArray(T... items) {
  Observable<T> fromArray = fromArray(items);
  if (fromArray == empty()) {
    return RxJavaPlugins.onAssembly(this);
  }
  return concatArray(fromArray, this);
}

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

@SuppressWarnings("unchecked")
@Test
public void concatArrayEmpty() {
  assertSame(Observable.empty(), Observable.concatArray());
}

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

@SuppressWarnings("unchecked")
@Test
public void noCancelPreviousArray() {
  final AtomicInteger counter = new AtomicInteger();
  Observable<Integer> source = Observable.just(1).doOnDispose(new Action() {
    @Override
    public void run() throws Exception {
      counter.getAndIncrement();
    }
  });
  Observable.concatArray(source, source, source, source, source)
  .test()
  .assertResult(1, 1, 1, 1, 1);
  assertEquals(0, counter.get());
}

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

/**
 * Returns an Observable that emits the items emitted by two ObservableSources, one after the other, without
 * interleaving them.
 * <p>
 * <img width="640" height="380" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/concat.png" alt="">
 * <dl>
 *  <dt><b>Scheduler:</b></dt>
 *  <dd>{@code concat} does not operate by default on a particular {@link Scheduler}.</dd>
 * </dl>
 *
 * @param <T> the common element base type
 * @param source1
 *            an ObservableSource to be concatenated
 * @param source2
 *            an ObservableSource to be concatenated
 * @return an Observable that emits items emitted by the two source ObservableSources, one after the other,
 *         without interleaving them
 * @see <a href="http://reactivex.io/documentation/operators/concat.html">ReactiveX operators documentation: Concat</a>
 */
@SuppressWarnings("unchecked")
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public static <T> Observable<T> concat(ObservableSource<? extends T> source1, ObservableSource<? extends T> source2) {
  ObjectHelper.requireNonNull(source1, "source1 is null");
  ObjectHelper.requireNonNull(source2, "source2 is null");
  return concatArray(source1, source2);
}

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

/**
 * Returns an Observable that emits the items emitted by two ObservableSources, one after the other, without
 * interleaving them.
 * <p>
 * <img width="640" height="380" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/concat.png" alt="">
 * <dl>
 *  <dt><b>Scheduler:</b></dt>
 *  <dd>{@code concat} does not operate by default on a particular {@link Scheduler}.</dd>
 * </dl>
 *
 * @param <T> the common element base type
 * @param source1
 *            an ObservableSource to be concatenated
 * @param source2
 *            an ObservableSource to be concatenated
 * @return an Observable that emits items emitted by the two source ObservableSources, one after the other,
 *         without interleaving them
 * @see <a href="http://reactivex.io/documentation/operators/concat.html">ReactiveX operators documentation: Concat</a>
 */
@SuppressWarnings("unchecked")
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public static <T> Observable<T> concat(ObservableSource<? extends T> source1, ObservableSource<? extends T> source2) {
  ObjectHelper.requireNonNull(source1, "source1 is null");
  ObjectHelper.requireNonNull(source2, "source2 is null");
  return concatArray(source1, source2);
}

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

@SuppressWarnings("unchecked")
@Test
public void concatArraySingleElement() {
  assertSame(Observable.never(), Observable.concatArray(Observable.never()));
}

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

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

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

/**
 * Returns an Observable that emits the specified items before it begins to emit items emitted by the source
 * ObservableSource.
 * <p>
 * <img width="640" height="315" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/startWithArray.png" alt="">
 * <dl>
 *  <dt><b>Scheduler:</b></dt>
 *  <dd>{@code startWithArray} does not operate by default on a particular {@link Scheduler}.</dd>
 * </dl>
 *
 * @param items
 *            the array of values to emit first
 * @return an Observable that emits the specified items before it begins to emit items emitted by the source
 *         ObservableSource
 * @see <a href="http://reactivex.io/documentation/operators/startwith.html">ReactiveX operators documentation: StartWith</a>
 */
@SuppressWarnings("unchecked")
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public final Observable<T> startWithArray(T... items) {
  Observable<T> fromArray = fromArray(items);
  if (fromArray == empty()) {
    return RxJavaPlugins.onAssembly(this);
  }
  return concatArray(fromArray, this);
}

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

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

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

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

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

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

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

@SuppressWarnings("unchecked")
@Test
public void noSubsequentSubscription() {
  final int[] calls = { 0 };
  Observable<Integer> source = Observable.create(new ObservableOnSubscribe<Integer>() {
    @Override
    public void subscribe(ObservableEmitter<Integer> s) throws Exception {
      calls[0]++;
      s.onNext(1);
      s.onComplete();
    }
  });
  Observable.concatArray(source, source).firstElement()
  .test()
  .assertResult(1);
  assertEquals(1, calls[0]);
}

相关文章

Observable类方法