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

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

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

Observable.singleOrError介绍

[英]Returns a Single that emits the single item emitted by this Observable if this Observable emits only a single item, otherwise if this Observable completes without emitting any items or emits more than one item a NoSuchElementException or IllegalArgumentException will be signalled respectively.

Scheduler: singleOrError does not operate by default on a particular Scheduler.
[中]如果此可观测对象仅发射单个项,则返回发射此可观测对象发射的单个项的单个项;否则,如果此可观测对象在未发射任何项的情况下完成,或发射多个项,则将分别发出NosTouchElementException或IllegalArgumentException信号。
调度程序:默认情况下,singleOrError不会在特定调度程序上运行。

代码示例

代码示例来源:origin: lettuce-io/lettuce-core

@Override
  public io.reactivex.Single<?> apply(io.reactivex.Observable<?> source) {
    return source.singleOrError();
  }
}

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

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

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

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

代码示例来源:origin: amitshekhariitbhu/Fast-Android-Networking

public <T> Single<T> getObjectSingle(Class<T> objectClass) {
  return getObjectObservable(objectClass).singleOrError();
}

代码示例来源:origin: amitshekhariitbhu/Fast-Android-Networking

public Single<String> getStringSingle() {
  return getStringObservable().singleOrError();
}

代码示例来源:origin: amitshekhariitbhu/Fast-Android-Networking

public Single<JSONArray> getJSONArraySingle() {
  return getJSONArrayObservable().singleOrError();
}

代码示例来源:origin: amitshekhariitbhu/Fast-Android-Networking

public Single<Bitmap> getBitmapSingle() {
  return getBitmapObservable().singleOrError();
}

代码示例来源:origin: amitshekhariitbhu/Fast-Android-Networking

public Single<String> getDownloadSingle() {
  return getDownloadObservable().singleOrError();
}

代码示例来源:origin: amitshekhariitbhu/Fast-Android-Networking

public <T> Single<T> getParseSingle(TypeToken<T> typeToken) {
  return getParseObservable(typeToken).singleOrError();
}

代码示例来源:origin: amitshekhariitbhu/Fast-Android-Networking

public <T> Single<List<T>> getObjectListSingle(Class<T> objectClass) {
  return getObjectListObservable(objectClass).singleOrError();
}

代码示例来源:origin: jeasonlzy/okhttp-OkGo

@Override
  public Single<Response<T>> adapt(Call<T> call, AdapterParam param) {
    ObservableResponse<T> observable = new ObservableResponse<>();
    return observable.adapt(call, param).singleOrError();
  }
}

代码示例来源:origin: jeasonlzy/okhttp-OkGo

@Override
  public Single<Result<T>> adapt(Call<T> call, AdapterParam param) {
    ObservableResult<T> observable = new ObservableResult<>();
    return observable.adapt(call, param).singleOrError();
  }
}

代码示例来源:origin: jeasonlzy/okhttp-OkGo

@Override
  public Single<T> adapt(Call<T> call, AdapterParam param) {
    ObservableBody<T> observable = new ObservableBody<>();
    return observable.adapt(call, param).singleOrError();
  }
}

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

@Test
public void singleOrErrorOneElement() {
  Observable.just(1)
    .singleOrError()
    .test()
    .assertNoErrors()
    .assertValue(1);
}

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

@Test
public void singleOrErrorMultipleElements() {
  Observable.just(1, 2, 3)
    .singleOrError()
    .test()
    .assertNoValues()
    .assertError(IllegalArgumentException.class);
}

代码示例来源:origin: square/retrofit

return observable.singleOrError();

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

@Test
public void singleOrErrorError() {
  Observable.error(new RuntimeException("error"))
    .singleOrError()
    .test()
    .assertNoValues()
    .assertErrorMessage("error")
    .assertError(RuntimeException.class);
}

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

@Test
public void singleOrErrorNoElement() {
  Observable.empty()
    .singleOrError()
    .test()
    .assertNoValues()
    .assertError(NoSuchElementException.class);
}

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

@Test
  public void singleOrError() {
    Observable.empty()
    .singleOrError()
    .toObservable()
    .test()
    .assertFailure(NoSuchElementException.class);
  }
}

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

@Test
  public void toObservableAndBack() {
    Single.fromCallable(new Callable<Integer>() {
      @Override
      public Integer call() throws Exception {
        return 1;
      }
    })
        .toObservable()
        .singleOrError()
        .test()
        .assertResult(1);
  }
}

相关文章

Observable类方法