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

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

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

Observable.ofType介绍

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

Scheduler: ofType does not operate by default on a particular Scheduler.
[中]过滤由ObservableSource发出的项,仅发出指定类型的项。
调度器:默认情况下,ofType不会在特定的调度器上运行。

代码示例

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

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

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

@Test
public void testOfType() {
  Observable<String> o = Observable.just(1, "abc", false, 2L).ofType(String.class);
  Observer<Object> observer = TestHelper.mockObserver();
  o.subscribe(observer);
  verify(observer, never()).onNext(1);
  verify(observer, times(1)).onNext("abc");
  verify(observer, never()).onNext(false);
  verify(observer, never()).onNext(2L);
  verify(observer, never()).onError(
      any(Throwable.class));
  verify(observer, 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")
  Observable<List> o = Observable.<Object> just(l1, l2, "123").ofType(List.class);
  Observer<Object> observer = TestHelper.mockObserver();
  o.subscribe(observer);
  verify(observer, times(1)).onNext(l1);
  verify(observer, times(1)).onNext(l2);
  verify(observer, never()).onNext("123");
  verify(observer, never()).onError(
      any(Throwable.class));
  verify(observer, times(1)).onComplete();
}

代码示例来源:origin: adgvcxz/Dribbble-MVVM

@BindingAdapter({"android:layout_marginRight"})
public static void setMarginRight(View view, int right) {
  Observable.just(view.getLayoutParams()).ofType(ViewGroup.MarginLayoutParams.class)
      .filter(marginLayoutParams -> marginLayoutParams.rightMargin != right).subscribe(marginLayoutParams -> {
    marginLayoutParams.rightMargin = right;
    view.setLayoutParams(marginLayoutParams);
  });
}

代码示例来源:origin: adgvcxz/Dribbble-MVVM

@BindingAdapter({"android:layout_marginLeft"})
public static void setMarginLeft(View view, int left) {
  Observable.just(view.getLayoutParams()).ofType(ViewGroup.MarginLayoutParams.class)
      .filter(marginLayoutParams -> marginLayoutParams.leftMargin != left).subscribe(marginLayoutParams -> {
    marginLayoutParams.leftMargin = left;
    view.setLayoutParams(marginLayoutParams);
  });
}

代码示例来源:origin: adgvcxz/Dribbble-MVVM

@BindingAdapter({"android:layout_marginBottom"})
public static void setMarginBottom(View view, int bottom) {
  Observable.just(view.getLayoutParams()).ofType(ViewGroup.MarginLayoutParams.class)
      .filter(marginLayoutParams -> marginLayoutParams.bottomMargin != bottom).subscribe(marginLayoutParams -> {
    marginLayoutParams.bottomMargin = bottom;
    view.setLayoutParams(marginLayoutParams);
  });
}

代码示例来源:origin: adgvcxz/Dribbble-MVVM

@BindingAdapter({"fragment"})
public static void addFragment(ViewGroup viewGroup, BaseFragmentViewModel model) {
  Observable.just(viewGroup.getContext()).ofType(FragmentActivity.class).subscribe(fragmentActivity -> {
    BaseViewModelFragment fragment = BaseViewModelFragment.newInstance(model);
    fragmentActivity.getSupportFragmentManager().beginTransaction().replace(viewGroup.getId(), fragment).commit();
  });
}

代码示例来源:origin: adgvcxz/Dribbble-MVVM

@BindingAdapter(value = {"osVersionMarginTop"}, requireAll = false)
public static void setStatusBarMarginTop(View view, int osVersion) {
  Observable.just(osVersion).filter(integer -> osVersion > Build.VERSION_CODES.KITKAT)
      .map(integer -> view.getLayoutParams())
      .ofType(ViewGroup.MarginLayoutParams.class)
      .subscribe(marginLayoutParams -> {
        marginLayoutParams.topMargin = Util.getStatusBarHeight(view.getContext());
        view.setLayoutParams(marginLayoutParams);
      });
}

代码示例来源:origin: com.b2international.snowowl/com.b2international.snowowl.datastore.server

public ReviewManagerImpl(final InternalRepository repository, final ReviewConfiguration config) {
  this.store = repository.getIndex();
  this.revisionIndex = repository.getRevisionIndex();
  this.keepCurrentMillis = TimeUnit.MINUTES.toMillis(config.getKeepCurrentMins());
  this.keepOtherMillis = TimeUnit.MINUTES.toMillis(config.getKeepOtherMins());
  // Check every minute if there's something to remove
  Holder.CLEANUP_TIMER.schedule(cleanupTask, CLEANUP_INTERVAL, CLEANUP_INTERVAL);
  notificationSubscription = repository.notifications()
    .ofType(BranchChangedEvent.class)
    .subscribe(this::onBranchChange);
}

代码示例来源:origin: spotify/mobius

@Override
 public Observable<E> apply(Observable<F> effects) {
  return effects
    .ofType(effectClass)
    .compose(effectHandler)
    .doOnError(onErrorFunction.apply(effectHandler));
 }
});

代码示例来源:origin: HIFILEO/ReactiveArchitecture

/**
 * Process Filtering for {@link ScrollResult}, {@link RestoreResult}, {@link FilterAction}.
 * @param object - object to apply filtering on.
 * @return {@link Observable} of {@link Result}
 */
private Observable<Result> processFiltering(Object object) {
  return Observable.just(object)
      .publish(objectObservable -> Observable.merge(
          objectObservable.ofType(FilterAction.class)
              .compose(filterTransformer.getTransformFilterActionToFilterResult()),
          objectObservable.ofType(ScrollResult.class)
              .compose(filterTransformer.getTransformFilterScrollResult()),
          objectObservable.ofType(RestoreResult.class)
              .compose(filterTransformer.getTransformFilterRestoreResult())
      ));
}

代码示例来源:origin: adgvcxz/Dribbble-MVVM

@BindingAdapter(value = {"loadMore", "isLoadAll"}, requireAll = false)
public static void setLoadMore(RecyclerView recyclerView, boolean loadMore, boolean isLoadAll) {
  Observable.just(recyclerView.getAdapter()).ofType(BaseRecyclerViewAdapter.class)
      .filter(adapter -> adapter.isLoadMore() != loadMore || adapter.isLoadAll() != isLoadAll)
      .subscribe(adapter -> {
        adapter.setLoadMore(loadMore);
        adapter.setLoadAll(isLoadAll);
      });
}

代码示例来源:origin: HIFILEO/ReactiveArchitecture

/**
 * Setup the transformers used by this {@link NowPlayingViewModel}.
 */
@MainThread
private void setupTransformers() {
  final ObservableTransformer<ScrollEvent, ScrollAction> scrollTransformer =
      upstream -> upstream.flatMap((Function<ScrollEvent, ObservableSource<ScrollAction>>) scrollEvent -> {
        return Observable.just(new ScrollAction(scrollEvent.getPageNumber()));
      });
  final ObservableTransformer<RestoreEvent, RestoreAction> restoreTransformer =
      upstream -> upstream.flatMap(restoreEvent -> Observable.just(new RestoreAction(restoreEvent.getPageNumber())));
  final ObservableTransformer<FilterEvent, FilterAction> filterTransformer =
      upstream -> upstream.flatMap(filterEvent -> Observable.just(new FilterAction(filterEvent.isFilterOn())));
  transformEventsIntoActions = upstream -> upstream.publish(uiEventObservable -> Observable.merge(
      uiEventObservable.ofType(ScrollEvent.class).compose(scrollTransformer),
      uiEventObservable.ofType(RestoreEvent.class).compose(restoreTransformer),
      uiEventObservable.ofType(FilterEvent.class).compose(filterTransformer)
  ));
}

代码示例来源:origin: akarnokd/akarnokd-misc

@Test
public void test1() {
  Observable<Object> mixedSource = Observable.<Object>just("a", 1, "b", 2, "c", 3)
      .doOnSubscribe(s -> System.out.println("Subscribed!"));
   
   mixedSource.compose(f ->
     Observable.merge(
      f.ofType(Integer.class).compose(g -> g.map(v -> v + 1)),
      f.ofType(String.class).compose(g -> g.map(v -> v.toUpperCase()))
     )
   )
   .subscribe(System.out::println);
}

代码示例来源:origin: adgvcxz/Dribbble-MVVM

}).delay(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? 120 : 200, TimeUnit.MILLISECONDS).ofType(ViewGroup.class).flatMap(viewGroup -> Observable.range(0, viewGroup.getChildCount())
    .map(viewGroup::getChildAt)
).scan(new Pair<Integer, View>(0, null), (integerViewPair, view2) -> new Pair<>(integerViewPair.first + 50, view2))

代码示例来源:origin: akarnokd/akarnokd-misc

@Test
  public void test2() {
    Observable<Object> mixedSource = Observable.<Object>just("a", 1, "b", 2, "c", 3)
        .doOnSubscribe(s -> System.out.println("Subscribed!"));

     
     mixedSource.publish(f ->
       Observable.merge(
        f.ofType(Integer.class).compose(g -> g.map(v -> v + 1)),
        f.ofType(String.class).compose(g -> g.map(v -> v.toUpperCase()))
       )
     )
     .subscribe(System.out::println);
  }
}

相关文章

Observable类方法