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

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

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

Observable.last介绍

[英]Returns a Single that emits only the last item emitted by this Observable, or a default item if this Observable completes without emitting any items.

Scheduler: last does not operate by default on a particular Scheduler.
[中]

代码示例

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

@Override
  public SingleSource<Object> apply(Observable<Object> o) throws Exception {
    return o.last(2);
  }
});

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

@Test
public void dispose() {
  TestHelper.checkDisposed(Observable.never().lastElement().toObservable());
  TestHelper.checkDisposed(Observable.never().lastElement());
  TestHelper.checkDisposed(Observable.just(1).lastOrError().toObservable());
  TestHelper.checkDisposed(Observable.just(1).lastOrError());
  TestHelper.checkDisposed(Observable.just(1).last(2).toObservable());
  TestHelper.checkDisposed(Observable.just(1).last(2));
}

代码示例来源:origin: nanchen2251/RxJava2Examples

@Override
  protected void doSomething() {
    Observable.just(1, 2, 3)
        .last(4)
        .subscribe(new Consumer<Integer>() {
          @Override
          public void accept(@NonNull Integer integer) throws Exception {
            mRxOperatorsText.append("last : " + integer + "\n");
            Log.e(TAG, "last : " + integer + "\n");
          }
        });
  }
}

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

@Override
  public ObservableSource<Object> apply(Observable<Object> o) throws Exception {
    return o.last(2).toObservable();
  }
});

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

@Test(expected = NullPointerException.class)
public void lastNull() {
  just1.last(null);
}

代码示例来源:origin: amitshekhariitbhu/RxJava2-Android-Samples

private void doSomeWork() {
  getObservable().last("A1") // the default item ("A1") to emit if the source ObservableSource is empty
      .subscribe(getObserver());
}

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

@Test
  public void testLastOrDefault() {
    Single<Integer> o = Observable.just(1, 2, 3)
        .last(4);

    SingleObserver<Integer> observer = TestHelper.mockSingleObserver();
    o.subscribe(observer);

    InOrder inOrder = inOrder(observer);
    inOrder.verify(observer, times(1)).onSuccess(3);
//        inOrder.verify(observer, times(1)).onComplete();
    inOrder.verifyNoMoreInteractions();
  }

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

@Test
  public void testLastOrDefaultWithOneElement() {
    Single<Integer> o = Observable.just(1).last(2);

    SingleObserver<Integer> observer = TestHelper.mockSingleObserver();
    o.subscribe(observer);

    InOrder inOrder = inOrder(observer);
    inOrder.verify(observer, times(1)).onSuccess(1);
//        inOrder.verify(observer, times(1)).onComplete();
    inOrder.verifyNoMoreInteractions();
  }

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

@Test
  public void testLastOrDefaultWithEmpty() {
    Single<Integer> o = Observable.<Integer> empty()
        .last(1);

    SingleObserver<Integer> observer = TestHelper.mockSingleObserver();
    o.subscribe(observer);

    InOrder inOrder = inOrder(observer);
    inOrder.verify(observer, times(1)).onSuccess(1);
//        inOrder.verify(observer, times(1)).onComplete();
    inOrder.verifyNoMoreInteractions();
  }

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

@Test
  public void testLastOrDefaultWithPredicateAndOneElement() {
    Single<Integer> o = Observable.just(1, 2)
        .filter(new Predicate<Integer>() {

          @Override
          public boolean test(Integer t1) {
            return t1 % 2 == 0;
          }
        })
        .last(4);

    SingleObserver<Integer> observer = TestHelper.mockSingleObserver();
    o.subscribe(observer);

    InOrder inOrder = inOrder(observer);
    inOrder.verify(observer, times(1)).onSuccess(2);
//        inOrder.verify(observer, times(1)).onComplete();
    inOrder.verifyNoMoreInteractions();
  }

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

@Test
  public void testLastOrDefaultWithPredicate() {
    Single<Integer> o = Observable.just(1, 2, 3, 4, 5, 6)
        .filter(new Predicate<Integer>() {

          @Override
          public boolean test(Integer t1) {
            return t1 % 2 == 0;
          }
        })
        .last(8);

    SingleObserver<Integer> observer = TestHelper.mockSingleObserver();
    o.subscribe(observer);

    InOrder inOrder = inOrder(observer);
    inOrder.verify(observer, times(1)).onSuccess(6);
//        inOrder.verify(observer, times(1)).onComplete();
    inOrder.verifyNoMoreInteractions();
  }

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

@Test
  public void testLastOrDefaultWithPredicateAndEmpty() {
    Single<Integer> o = Observable.just(1)
        .filter(
        new Predicate<Integer>() {

          @Override
          public boolean test(Integer t1) {
            return t1 % 2 == 0;
          }
        })
        .last(2);

    SingleObserver<Integer> observer = TestHelper.mockSingleObserver();
    o.subscribe(observer);

    InOrder inOrder = inOrder(observer);
    inOrder.verify(observer, times(1)).onSuccess(2);
//        inOrder.verify(observer, times(1)).onComplete();
    inOrder.verifyNoMoreInteractions();
  }

代码示例来源:origin: zhiwei1990/android-jetpack-demo

public static void doSome() {
    Observable.just("A1", "A2", "A3", "A4", "A5", "A6")
        .last("A0")
        .subscribeOn(Schedulers.io())
        .observeOn(AndroidSchedulers.mainThread())
        .subscribe(new SingleObserver<String>() {
          @Override
          public void onSubscribe(Disposable d) {
            Log.d(TAG, "onSubscribe: " + d.isDisposed());
          }

          @Override
          public void onSuccess(String s) {
            Log.i(TAG, "onSuccess: " + s);
          }

          @Override
          public void onError(Throwable e) {
            Log.e(TAG, "onError: " + e.getMessage());
          }
        });
  }
}

相关文章

Observable类方法