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

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

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

Flowable.ofType介绍

[英]Filters the items emitted by a Publisher, only emitting those of the specified type.

Backpressure: The operator doesn't interfere with backpressure which is determined by the source Publisher's backpressure behavior. Scheduler: ofType does not operate by default on a particular Scheduler.
[中]过滤发布者发出的项目,仅发出指定类型的项目。
背压:操作员不会干扰由源发布者的背压行为确定的背压。调度器:默认情况下,ofType不会在特定的调度器上运行。

代码示例

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

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

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

@Test
public void testOfType() {
  Flowable<String> flowable = Flowable.just(1, "abc", false, 2L).ofType(String.class);
  Subscriber<Object> subscriber = TestHelper.mockSubscriber();
  flowable.subscribe(subscriber);
  verify(subscriber, never()).onNext(1);
  verify(subscriber, times(1)).onNext("abc");
  verify(subscriber, never()).onNext(false);
  verify(subscriber, never()).onNext(2L);
  verify(subscriber, never()).onError(any(Throwable.class));
  verify(subscriber, times(1)).onComplete();
}

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

@Test
public void testOfTypeWithPolymorphism() {
  ArrayList<Integer> l1 = new ArrayList<Integer>();
  l1.add(1);
  LinkedList<Integer> l2 = new LinkedList<Integer>();
  l2.add(2);
  @SuppressWarnings("rawtypes")
  Flowable<List> flowable = Flowable.<Object> just(l1, l2, "123").ofType(List.class);
  Subscriber<Object> subscriber = TestHelper.mockSubscriber();
  flowable.subscribe(subscriber);
  verify(subscriber, times(1)).onNext(l1);
  verify(subscriber, times(1)).onNext(l2);
  verify(subscriber, never()).onNext("123");
  verify(subscriber, never()).onError(any(Throwable.class));
  verify(subscriber, times(1)).onComplete();
}

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

/**
 * 根据传递的 eventType 类型返回特定类型(eventType)的 被观察者
 *
 * @param eventType 事件类型
 * @return return
 */
private <T> Flowable<T> toObservable(Class<T> eventType) {
  return bus.toFlowable(BackpressureStrategy.BUFFER).ofType(eventType);
}

代码示例来源:origin: simplezhli/RxPay

/**
 * 返回指定类型的带背压的Flowable实例
 *
 * @param <T>
 * @param type
 * @return
 */
public <T>Flowable<T> toObservable(Class<T> type){
  return mSubject.toFlowable(BackpressureStrategy.BUFFER)
      .ofType(type);
}
/**

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

/**
 * 根据传递的 eventType 类型返回特定类型(eventType)的 被观察者
 *
 * @param eventType 事件类型
 * @return return
 */
public  <T> Flowable<T> toObservable(Class<T> eventType) {
  return bus.toFlowable(BackpressureStrategy.BUFFER).ofType(eventType);
}

代码示例来源: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);
}

相关文章

Flowable类方法