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

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

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

Observable.skipLast介绍

[英]Returns an Observable that drops a specified number of items from the end of the sequence emitted by the source ObservableSource.

This Observer accumulates a queue long enough to store the first count items. As more items are received, items are taken from the front of the queue and emitted by the returned ObservableSource. This causes such items to be delayed. Scheduler: This version of skipLast does not operate by default on a particular Scheduler.
[中]

代码示例

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

  1. @Override
  2. public ObservableSource<Object> apply(Observable<Object> o) throws Exception {
  3. return o.skipLast(1, TimeUnit.DAYS);
  4. }
  5. });

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

  1. @Override
  2. public Observable<Object> apply(Observable<Object> o)
  3. throws Exception {
  4. return o.skipLast(1);
  5. }
  6. });

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

  1. @Test(expected = IndexOutOfBoundsException.class)
  2. public void testSkipLastWithNegativeCount() {
  3. Observable.just("one").skipLast(-1);
  4. }

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

  1. @Test(expected = NullPointerException.class)
  2. public void skipLastTimedSchedulerNull() {
  3. just1.skipLast(1, TimeUnit.SECONDS, null);
  4. }

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

  1. @Test
  2. public void testSkipLastWithZeroCount() {
  3. Observable<String> w = Observable.just("one", "two");
  4. Observable<String> observable = w.skipLast(0);
  5. Observer<String> observer = TestHelper.mockObserver();
  6. observable.subscribe(observer);
  7. verify(observer, times(1)).onNext("one");
  8. verify(observer, times(1)).onNext("two");
  9. verify(observer, never()).onError(any(Throwable.class));
  10. verify(observer, times(1)).onComplete();
  11. }

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

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

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

  1. /**
  2. * Returns an Observable that drops items emitted by the source ObservableSource during a specified time window
  3. * (defined on a specified scheduler) before the source completes.
  4. * <p>
  5. * <img width="640" height="340" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/skipLast.ts.png" alt="">
  6. * <p>
  7. * Note: this action will cache the latest items arriving in the specified time window.
  8. * <dl>
  9. * <dt><b>Scheduler:</b></dt>
  10. * <dd>You specify which {@link Scheduler} this operator will use for tracking the current time</dd>
  11. * </dl>
  12. *
  13. * @param time
  14. * the length of the time window
  15. * @param unit
  16. * the time unit of {@code time}
  17. * @param scheduler
  18. * the scheduler used as the time source
  19. * @return an Observable that drops those items emitted by the source ObservableSource in a time window before the
  20. * source completes defined by {@code time} and {@code scheduler}
  21. * @see <a href="http://reactivex.io/documentation/operators/skiplast.html">ReactiveX operators documentation: SkipLast</a>
  22. */
  23. @CheckReturnValue
  24. @SchedulerSupport(SchedulerSupport.CUSTOM)
  25. public final Observable<T> skipLast(long time, TimeUnit unit, Scheduler scheduler) {
  26. return skipLast(time, unit, scheduler, false, bufferSize());
  27. }

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

  1. @Test
  2. public void testSkipLast2() {
  3. Observable<String> o = Observable.fromIterable(Arrays.asList("one", "two")).skipLast(2);
  4. Observer<String> observer = TestHelper.mockObserver();
  5. o.subscribe(observer);
  6. verify(observer, never()).onNext(any(String.class));
  7. verify(observer, never()).onError(any(Throwable.class));
  8. verify(observer, times(1)).onComplete();
  9. }

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

  1. @Test
  2. public void testSkipLast1() {
  3. Observable<String> o = Observable.fromIterable(Arrays.asList("one", "two", "three")).skipLast(2);
  4. Observer<String> observer = TestHelper.mockObserver();
  5. InOrder inOrder = inOrder(observer);
  6. o.subscribe(observer);
  7. inOrder.verify(observer, never()).onNext("two");
  8. inOrder.verify(observer, never()).onNext("three");
  9. verify(observer, times(1)).onNext("one");
  10. verify(observer, never()).onError(any(Throwable.class));
  11. verify(observer, times(1)).onComplete();
  12. }

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

  1. @Test
  2. public void testSkipLastEmpty() {
  3. Observable<String> o = Observable.<String> empty().skipLast(2);
  4. Observer<String> observer = TestHelper.mockObserver();
  5. o.subscribe(observer);
  6. verify(observer, never()).onNext(any(String.class));
  7. verify(observer, never()).onError(any(Throwable.class));
  8. verify(observer, times(1)).onComplete();
  9. }

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

  1. @Test
  2. @Ignore("Null values not allowed")
  3. public void testSkipLastWithNull() {
  4. Observable<String> o = Observable.fromIterable(Arrays.asList("one", null, "two")).skipLast(1);
  5. Observer<String> observer = TestHelper.mockObserver();
  6. o.subscribe(observer);
  7. verify(observer, times(1)).onNext("one");
  8. verify(observer, times(1)).onNext(null);
  9. verify(observer, never()).onNext("two");
  10. verify(observer, never()).onError(any(Throwable.class));
  11. verify(observer, times(1)).onComplete();
  12. }

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

  1. @Test(expected = NullPointerException.class)
  2. public void skipLastTimedUnitNull() {
  3. just1.skipLast(1, null, Schedulers.single());
  4. }

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

  1. /**
  2. * Returns an Observable that drops items emitted by the source ObservableSource during a specified time window
  3. * before the source completes.
  4. * <p>
  5. * <img width="640" height="305" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/skipLast.t.png" alt="">
  6. * <p>
  7. * Note: this action will cache the latest items arriving in the specified time window.
  8. * <dl>
  9. * <dt><b>Scheduler:</b></dt>
  10. * <dd>{@code skipLast} does not operate on any particular scheduler but uses the current time
  11. * from the {@code computation} {@link Scheduler}.</dd>
  12. * </dl>
  13. *
  14. * @param time
  15. * the length of the time window
  16. * @param unit
  17. * the time unit of {@code time}
  18. * @return an Observable that drops those items emitted by the source ObservableSource in a time window before the
  19. * source completes defined by {@code time}
  20. * @see <a href="http://reactivex.io/documentation/operators/skiplast.html">ReactiveX operators documentation: SkipLast</a>
  21. */
  22. @CheckReturnValue
  23. @SchedulerSupport(SchedulerSupport.TRAMPOLINE)
  24. public final Observable<T> skipLast(long time, TimeUnit unit) {
  25. return skipLast(time, unit, Schedulers.trampoline(), false, bufferSize());
  26. }

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

  1. @Test
  2. public void skipLastTimedCustomSchedulerDelayError() {
  3. Observable.just(1).concatWith(Observable.just(2).delay(500, TimeUnit.MILLISECONDS))
  4. .skipLast(300, TimeUnit.MILLISECONDS, Schedulers.io(), true)
  5. .test()
  6. .awaitDone(5, TimeUnit.SECONDS)
  7. .assertResult(1);
  8. }

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

  1. @Test
  2. public void skipLastTimedDefaultScheduler() {
  3. Observable.just(1).concatWith(Observable.just(2).delay(500, TimeUnit.MILLISECONDS))
  4. .skipLast(300, TimeUnit.MILLISECONDS)
  5. .test()
  6. .awaitDone(5, TimeUnit.SECONDS)
  7. .assertResult(1);
  8. }

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

  1. @Test
  2. public void skipLastTimedDefaultSchedulerDelayError() {
  3. Observable.just(1).concatWith(Observable.just(2).delay(500, TimeUnit.MILLISECONDS))
  4. .skipLast(300, TimeUnit.MILLISECONDS, true)
  5. .test()
  6. .awaitDone(5, TimeUnit.SECONDS)
  7. .assertResult(1);
  8. }

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

  1. @Test
  2. public void take() {
  3. Observable.just(1)
  4. .skipLast(0, TimeUnit.SECONDS)
  5. .take(1)
  6. .test()
  7. .awaitDone(5, TimeUnit.SECONDS)
  8. .assertResult(1);
  9. }
  10. }

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

  1. @Test
  2. public void error() {
  3. Observable.error(new TestException())
  4. .skipLast(1)
  5. .test()
  6. .assertFailure(TestException.class);
  7. }

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

  1. @Test
  2. public void errorDelayed() {
  3. Observable.error(new TestException())
  4. .skipLast(1, TimeUnit.DAYS, new TestScheduler(), true)
  5. .test()
  6. .assertFailure(TestException.class);
  7. }

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

  1. @Test
  2. public void testSkipLastWithBackpressure() {
  3. Observable<Integer> o = Observable.range(0, Flowable.bufferSize() * 2).skipLast(Flowable.bufferSize() + 10);
  4. TestObserver<Integer> to = new TestObserver<Integer>();
  5. o.observeOn(Schedulers.computation()).subscribe(to);
  6. to.awaitTerminalEvent();
  7. to.assertNoErrors();
  8. assertEquals((Flowable.bufferSize()) - 10, to.valueCount());
  9. }

相关文章

Observable类方法