io.reactivex.Flowable.cast()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(6.7k)|赞(0)|评价(0)|浏览(134)

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

Flowable.cast介绍

[英]Returns a Flowable that emits the items emitted by the source Publisher, converted to the specified type.

Backpressure: The operator doesn't interfere with backpressure which is determined by the source Publisher's backpressure behavior. Scheduler: cast does not operate by default on a particular Scheduler.
[中]返回一个FlowTable,该FlowTable发出源发布服务器发出的项,并转换为指定类型。
背压:操作员不会干扰由源发布者的背压行为确定的背压。调度程序:默认情况下,cast不会在特定调度程序上运行。

代码示例

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

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

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

@Override
  public Flowable<Object> apply(Flowable<? extends Throwable> t1) {
    return t1.map(new Function<Throwable, Integer>() {
      @Override
      public Integer apply(Throwable t1) {
        return 0;
      }
    }).startWith(0).cast(Object.class);
  }
}).subscribe(subscriber);

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

@Test
public void testCast() {
  Flowable<?> source = Flowable.just(1, 2);
  Flowable<Integer> flowable = source.cast(Integer.class);
  Subscriber<Integer> subscriber = TestHelper.mockSubscriber();
  flowable.subscribe(subscriber);
  verify(subscriber, times(1)).onNext(1);
  verify(subscriber, times(1)).onNext(1);
  verify(subscriber, never()).onError(any(Throwable.class));
  verify(subscriber, times(1)).onComplete();
}

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

@Test
public void testCastWithWrongType() {
  Flowable<?> source = Flowable.just(1, 2);
  Flowable<Boolean> flowable = source.cast(Boolean.class);
  Subscriber<Boolean> subscriber = TestHelper.mockSubscriber();
  flowable.subscribe(subscriber);
  verify(subscriber, times(1)).onError(any(ClassCastException.class));
}

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

/**
 * Filters the items emitted by a Publisher, only emitting those of the specified type.
 * <p>
 * <img width="640" height="310" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/ofClass.png" alt="">
 * <dl>
 *  <dt><b>Backpressure:</b></dt>
 *  <dd>The operator doesn't interfere with backpressure which is determined by the source {@code Publisher}'s backpressure
 *  behavior.</dd>
 *  <dt><b>Scheduler:</b></dt>
 *  <dd>{@code ofType} does not operate by default on a particular {@link Scheduler}.</dd>
 * </dl>
 *
 * @param <U> the output type
 * @param clazz
 *            the class type to filter the items emitted by the source Publisher
 * @return a Flowable that emits items from the source Publisher of type {@code clazz}
 * @see <a href="http://reactivex.io/documentation/operators/filter.html">ReactiveX operators documentation: Filter</a>
 */
@CheckReturnValue
@NonNull
@BackpressureSupport(BackpressureKind.PASS_THROUGH)
@SchedulerSupport(SchedulerSupport.NONE)
public final <U> Flowable<U> ofType(final Class<U> clazz) {
  ObjectHelper.requireNonNull(clazz, "clazz is null");
  return filter(Functions.isInstanceOf(clazz)).cast(clazz);
}

代码示例来源:origin: redisson/redisson

/**
 * Filters the items emitted by a Publisher, only emitting those of the specified type.
 * <p>
 * <img width="640" height="310" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/ofClass.png" alt="">
 * <dl>
 *  <dt><b>Backpressure:</b></dt>
 *  <dd>The operator doesn't interfere with backpressure which is determined by the source {@code Publisher}'s backpressure
 *  behavior.</dd>
 *  <dt><b>Scheduler:</b></dt>
 *  <dd>{@code ofType} does not operate by default on a particular {@link Scheduler}.</dd>
 * </dl>
 *
 * @param <U> the output type
 * @param clazz
 *            the class type to filter the items emitted by the source Publisher
 * @return a Flowable that emits items from the source Publisher of type {@code clazz}
 * @see <a href="http://reactivex.io/documentation/operators/filter.html">ReactiveX operators documentation: Filter</a>
 */
@CheckReturnValue
@BackpressureSupport(BackpressureKind.PASS_THROUGH)
@SchedulerSupport(SchedulerSupport.NONE)
public final <U> Flowable<U> ofType(final Class<U> clazz) {
  ObjectHelper.requireNonNull(clazz, "clazz is null");
  return filter(Functions.isInstanceOf(clazz)).cast(clazz);
}

代码示例来源:origin: Blankj/RxBus

private <T> Flowable<T> toFlowable(final Class<T> eventType,
                  final String tag,
                  final Scheduler scheduler) {
  Flowable<T> flowable = mBus.ofType(TagMessage.class)
      .filter(new Predicate<TagMessage>() {
        @Override
        public boolean test(TagMessage tagMessage) {
          return tagMessage.isSameType(eventType, tag);
        }
      })
      .map(new Function<TagMessage, Object>() {
        @Override
        public Object apply(TagMessage tagMessage) {
          return tagMessage.mEvent;
        }
      })
      .cast(eventType);
  if (scheduler != null) {
    return flowable.observeOn(scheduler);
  }
  return flowable;
}

代码示例来源:origin: cr330326/DemoComponent

/**
 * 根据传递的code和 eventType 类型返回特定类型(eventType)的 被观察者
 *
 * @param code      事件code
 * @param eventType 事件类型
 */
private <T> Flowable<T> toObservable(final int code, final Class<T> eventType) {
  return bus.toFlowable(BackpressureStrategy.BUFFER).ofType(Message.class)
      .filter(new Predicate<Message>() {
        @Override
        public boolean test(Message o) throws Exception {
          return o.getCode() == code && eventType.isInstance(o.getObject());
        }
      }).map(new Function<Message, Object>() {
        @Override
        public Object apply(Message o) throws Exception {
          return o.getObject();
        }
      }).cast(eventType);
}

代码示例来源:origin: LuckSiege/PictureSelectorLight

/**
 * 根据传递的code和 eventType 类型返回特定类型(eventType)的 被观察者
 *
 * @param code      事件code
 * @param eventType 事件类型
 */
private <T> Flowable<T> toObservable(final int code, final Class<T> eventType) {
  return bus.toFlowable(BackpressureStrategy.BUFFER).ofType(Message.class)
      .filter(new Predicate<Message>() {
        @Override
        public boolean test(Message o) throws Exception {
          return o.getCode() == code && eventType.isInstance(o.getObject());
        }
      }).map(new Function<Message, Object>() {
        @Override
        public Object apply(Message o) throws Exception {
          return o.getObject();
        }
      }).cast(eventType);
}

代码示例来源:origin: gravitee-io/graviteeio-access-management

.onErrorResumeNext(Single.error(new InvalidClientMetadataException("Unable to parse sector_identifier_uri : "+ uri.toString())))
.flatMapPublisher(Flowable::fromIterable)
.cast(String.class)
.collect(HashSet::new,(set, value)->set.add(value))
.flatMap(allowedRedirectUris -> Observable.fromIterable(request.getRedirectUris().get())

代码示例来源:origin: io.gravitee.am.gateway.handlers/gravitee-am-gateway-handler

.onErrorResumeNext(Single.error(new InvalidClientMetadataException("Unable to parse sector_identifier_uri : "+ uri.toString())))
.flatMapPublisher(Flowable::fromIterable)
.cast(String.class)
.collect(HashSet::new,(set, value)->set.add(value))
.flatMap(allowedRedirectUris -> Observable.fromIterable(request.getRedirectUris().get())

相关文章

Flowable类方法