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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

@Test
public void testSkipLast2() {
  Observable<String> o = Observable.fromIterable(Arrays.asList("one", "two")).skipLast(2);
  Observer<String> observer = TestHelper.mockObserver();
  o.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 testSkipLast1() {
  Observable<String> o = Observable.fromIterable(Arrays.asList("one", "two", "three")).skipLast(2);
  Observer<String> observer = TestHelper.mockObserver();
  InOrder inOrder = inOrder(observer);
  o.subscribe(observer);
  inOrder.verify(observer, never()).onNext("two");
  inOrder.verify(observer, never()).onNext("three");
  verify(observer, times(1)).onNext("one");
  verify(observer, never()).onError(any(Throwable.class));
  verify(observer, times(1)).onComplete();
}

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

@Test
public void testSkipLastEmpty() {
  Observable<String> o = Observable.<String> empty().skipLast(2);
  Observer<String> observer = TestHelper.mockObserver();
  o.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
@Ignore("Null values not allowed")
public void testSkipLastWithNull() {
  Observable<String> o = Observable.fromIterable(Arrays.asList("one", null, "two")).skipLast(1);
  Observer<String> observer = TestHelper.mockObserver();
  o.subscribe(observer);
  verify(observer, times(1)).onNext("one");
  verify(observer, times(1)).onNext(null);
  verify(observer, never()).onNext("two");
  verify(observer, never()).onError(any(Throwable.class));
  verify(observer, times(1)).onComplete();
}

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

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

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

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

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

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

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

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

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

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

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

@Test
  public void take() {
    Observable.just(1)
    .skipLast(0, TimeUnit.SECONDS)
    .take(1)
    .test()
    .awaitDone(5, TimeUnit.SECONDS)
    .assertResult(1);
  }
}

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

@Test
public void error() {
  Observable.error(new TestException())
  .skipLast(1)
  .test()
  .assertFailure(TestException.class);
}

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

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

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

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

相关文章

Observable类方法