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

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

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

Observable.skip介绍

[英]Returns an Observable that skips the first count items emitted by the source ObservableSource and emits the remainder.

Scheduler: This version of skip does not operate by default on a particular Scheduler.
[中]返回一个Observable,它跳过源ObservableSource发出的第一个计数项,并发出剩余的计数项。
调度程序:默认情况下,此版本的skip不会在特定调度程序上运行。

代码示例

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

@Override
  public Observable<Object> apply(Observable<Object> o)
      throws Exception {
    return o.skip(1);
  }
});

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

@Test(expected = NullPointerException.class)
public void skipTimedSchedulerNull() {
  just1.skip(1, TimeUnit.SECONDS, null);
}

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

@Test
public void testSkipNegativeElements() {
  Observable<String> skip = Observable.just("one", "two", "three").skip(-99);
  Observer<String> observer = TestHelper.mockObserver();
  skip.subscribe(observer);
  verify(observer, times(1)).onNext("one");
  verify(observer, times(1)).onNext("two");
  verify(observer, times(1)).onNext("three");
  verify(observer, never()).onError(any(Throwable.class));
  verify(observer, times(1)).onComplete();
}

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

@Test
public void testSkipTwoElements() {
  Observable<String> skip = Observable.just("one", "two", "three").skip(2);
  Observer<String> observer = TestHelper.mockObserver();
  skip.subscribe(observer);
  verify(observer, never()).onNext("one");
  verify(observer, never()).onNext("two");
  verify(observer, times(1)).onNext("three");
  verify(observer, never()).onError(any(Throwable.class));
  verify(observer, times(1)).onComplete();
}

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

@Test
public void dispose() {
  TestHelper.checkDisposed(Observable.just(1).skip(2));
}

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

@Test
public void testSkipEmptyStream() {
  Observable<String> w = Observable.empty();
  Observable<String> skip = w.skip(1);
  Observer<String> observer = TestHelper.mockObserver();
  skip.subscribe(observer);
  verify(observer, never()).onNext(any(String.class));
  verify(observer, never()).onError(any(Throwable.class));
  verify(observer, times(1)).onComplete();
}

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

@Test
public void testSkipZeroElements() {
  Observable<String> skip = Observable.just("one", "two", "three").skip(0);
  Observer<String> observer = TestHelper.mockObserver();
  skip.subscribe(observer);
  verify(observer, times(1)).onNext("one");
  verify(observer, times(1)).onNext("two");
  verify(observer, times(1)).onNext("three");
  verify(observer, never()).onError(any(Throwable.class));
  verify(observer, times(1)).onComplete();
}

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

@Test
public void testSkipOneElement() {
  Observable<String> skip = Observable.just("one", "two", "three").skip(1);
  Observer<String> observer = TestHelper.mockObserver();
  skip.subscribe(observer);
  verify(observer, never()).onNext("one");
  verify(observer, times(1)).onNext("two");
  verify(observer, times(1)).onNext("three");
  verify(observer, never()).onError(any(Throwable.class));
  verify(observer, times(1)).onComplete();
}

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

@Test
public void testSkipError() {
  Exception e = new Exception();
  Observable<String> ok = Observable.just("one");
  Observable<String> error = Observable.error(e);
  Observable<String> skip = Observable.concat(ok, error).skip(100);
  Observer<String> observer = TestHelper.mockObserver();
  skip.subscribe(observer);
  verify(observer, never()).onNext(any(String.class));
  verify(observer, times(1)).onError(e);
  verify(observer, never()).onComplete();
}

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

@Test(expected = NullPointerException.class)
public void skipTimedUnitNull() {
  just1.skip(1, null, Schedulers.single());
}

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

@Test
public void testSkipMultipleObservers() {
  Observable<String> skip = Observable.just("one", "two", "three")
      .skip(2);
  Observer<String> observer1 = TestHelper.mockObserver();
  skip.subscribe(observer1);
  Observer<String> observer2 = TestHelper.mockObserver();
  skip.subscribe(observer2);
  verify(observer1, times(1)).onNext(any(String.class));
  verify(observer1, never()).onError(any(Throwable.class));
  verify(observer1, times(1)).onComplete();
  verify(observer2, times(1)).onNext(any(String.class));
  verify(observer2, never()).onError(any(Throwable.class));
  verify(observer2, times(1)).onComplete();
}

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

@Override
  public Observable<Movie> apply(Observable<List<Movie>> movieList) {
    return movieList
      .startWith(new ArrayList<Movie>())
      .buffer(2, 1)
      .skip(1)
      .flatMap(calculateDelta);
  }
};

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

@Test
  public void skipTimedDefaultScheduler() {
    Observable.just(1).skip(1, TimeUnit.MINUTES)
    .test()
    .awaitDone(5, TimeUnit.SECONDS)
    .assertResult();
  }
}

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

@Test
public void testRequestOverflowDoesNotOccur() {
  TestObserver<Integer> to = new TestObserver<Integer>();
  Observable.range(1, 10).skip(5).subscribe(to);
  to.assertTerminated();
  to.assertComplete();
  to.assertNoErrors();
  assertEquals(Arrays.asList(6, 7, 8, 9, 10), to.values());
}

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

@Test
public void testAsyncComeAndGo() {
  Observable<Long> source = Observable.interval(1, 1, TimeUnit.MILLISECONDS)
      .take(1000)
      .subscribeOn(Schedulers.io());
  Observable<Long> cached = source.replay().autoConnect();
  Observable<Long> output = cached.observeOn(Schedulers.computation());
  List<TestObserver<Long>> list = new ArrayList<TestObserver<Long>>(100);
  for (int i = 0; i < 100; i++) {
    TestObserver<Long> to = new TestObserver<Long>();
    list.add(to);
    output.skip(i * 10).take(10).subscribe(to);
  }
  List<Long> expected = new ArrayList<Long>();
  for (int i = 0; i < 10; i++) {
    expected.add((long)(i - 10));
  }
  int j = 0;
  for (TestObserver<Long> to : list) {
    to.awaitTerminalEvent(3, TimeUnit.SECONDS);
    to.assertNoErrors();
    to.assertTerminated();
    for (int i = j * 10; i < j * 10 + 10; i++) {
      expected.set(i - j * 10, (long)i);
    }
    to.assertValueSequence(expected);
    j++;
  }
}

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

@Test
public void testAsyncComeAndGo() {
  Observable<Long> source = Observable.interval(1, 1, TimeUnit.MILLISECONDS)
      .take(1000)
      .subscribeOn(Schedulers.io());
  ObservableCache<Long> cached = new ObservableCache<Long>(source, 16);
  Observable<Long> output = cached.observeOn(Schedulers.computation());
  List<TestObserver<Long>> list = new ArrayList<TestObserver<Long>>(100);
  for (int i = 0; i < 100; i++) {
    TestObserver<Long> to = new TestObserver<Long>();
    list.add(to);
    output.skip(i * 10).take(10).subscribe(to);
  }
  List<Long> expected = new ArrayList<Long>();
  for (int i = 0; i < 10; i++) {
    expected.add((long)(i - 10));
  }
  int j = 0;
  for (TestObserver<Long> to : list) {
    to.awaitTerminalEvent(3, TimeUnit.SECONDS);
    to.assertNoErrors();
    to.assertComplete();
    for (int i = j * 10; i < j * 10 + 10; i++) {
      expected.set(i - j * 10, (long)i);
    }
    to.assertValueSequence(expected);
    j++;
  }
}

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

@Test
public void fromIterable() {
  ArrayList<String> items = new ArrayList<String>();
  items.add("one");
  items.add("two");
  items.add("three");
  assertEquals((Long)3L, Observable.fromIterable(items).count().blockingGet());
  assertEquals("two", Observable.fromIterable(items).skip(1).take(1).blockingSingle());
  assertEquals("three", Observable.fromIterable(items).takeLast(1).blockingSingle());
}

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

@Test
public void fromArityArgs3() {
  Observable<String> items = Observable.just("one", "two", "three");
  assertEquals((Long)3L, items.count().blockingGet());
  assertEquals("two", items.skip(1).take(1).blockingSingle());
  assertEquals("three", items.takeLast(1).blockingSingle());
}

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

@Test
public void zip2DelayErrorPrefetch() {
  Observable.zip(Observable.range(1, 9).concatWith(Observable.<Integer>error(new TestException())),
      Observable.range(21, 9),
    new BiFunction<Integer, Integer, Object>() {
      @Override
      public Object apply(Integer a, Integer b) throws Exception {
        return "" + a + b;
      }
    }, true, 2
  )
  .skip(8)
  .test()
  .assertFailure(TestException.class, "929");
}

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

@Test
public void fromArray() {
  String[] items = new String[] { "one", "two", "three" };
  assertEquals((Long)3L, Observable.fromArray(items).count().blockingGet());
  assertEquals("two", Observable.fromArray(items).skip(1).take(1).blockingSingle());
  assertEquals("three", Observable.fromArray(items).takeLast(1).blockingSingle());
}

相关文章

Observable类方法