rx.Observable.toSortedList()方法的使用及代码示例

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

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

Observable.toSortedList介绍

[英]Returns an Observable that emits a list that contains the items emitted by the source Observable, in a sorted order. Each item emitted by the Observable must implement Comparable with respect to all other items in the sequence.

Backpressure Support: This operator does not support backpressure as by intent it is requesting and buffering everything. Scheduler: toSortedList does not operate by default on a particular Scheduler.
[中]返回一个Observable,该Observable发出一个列表,其中包含源Observable按排序顺序发出的项。可观察物发出的每个项目必须与序列中的所有其他项目具有可比性。
背压支持:该操作员无意支持背压,因为它正在请求和缓冲所有内容。Scheduler:toSortedList默认情况下不会在特定的计划程序上运行。

代码示例

代码示例来源:origin: Rukey7/MvpApp

  1. .toSortedList(new Func2<TopicsEntity, TopicsEntity, Integer>() {
  2. @Override
  3. public Integer call(TopicsEntity topicsEntity, TopicsEntity topicsEntity2) {

代码示例来源:origin: jaydenxiao2016/AndroidFire

  1. @Override
  2. public Observable<List<VideoData>> getVideosListData(final String type, int startPage) {
  3. return Api.getDefault(HostType.NETEASE_NEWS_VIDEO).getVideoList(Api.getCacheControl(),type,startPage)
  4. .flatMap(new Func1<Map<String, List<VideoData>>, Observable<VideoData>>() {
  5. @Override
  6. public Observable<VideoData> call(Map<String, List<VideoData>> map) {
  7. return Observable.from(map.get(type));
  8. }
  9. })
  10. //转化时间
  11. .map(new Func1<VideoData, VideoData>() {
  12. @Override
  13. public VideoData call(VideoData videoData) {
  14. String ptime = TimeUtil.formatDate(videoData.getPtime());
  15. videoData.setPtime(ptime);
  16. return videoData;
  17. }
  18. })
  19. .distinct()//去重
  20. .toSortedList(new Func2<VideoData, VideoData, Integer>() {
  21. @Override
  22. public Integer call(VideoData videoData, VideoData videoData2) {
  23. return videoData2.getPtime().compareTo(videoData.getPtime());
  24. }
  25. })
  26. //声明线程调度
  27. .compose(RxSchedulers.<List<VideoData>>io_main());
  28. }
  29. }

代码示例来源:origin: jaydenxiao2016/AndroidFire

  1. .toSortedList(new Func2<NewsSummary, NewsSummary, Integer>() {
  2. @Override
  3. public Integer call(NewsSummary newsSummary, NewsSummary newsSummary2) {

代码示例来源:origin: kaku2015/ColorfulNews

  1. .toSortedList(new Func2<NewsSummary, NewsSummary, Integer>() {
  2. @Override
  3. public Integer call(NewsSummary newsSummary, NewsSummary newsSummary2) {

代码示例来源:origin: henrymorgen/android-advanced-light

  1. private void toSortedList() {
  2. Observable.just(3,1,2).toSortedList().subscribe(new Action1<List<Integer>>() {
  3. @Override
  4. public void call(List<Integer> integers) {
  5. for(int integer :integers){
  6. Log.i("wangshu", "toSortedList:" + integer);
  7. }
  8. }
  9. });
  10. }

代码示例来源:origin: ladingwu/ApplicationDemo

  1. private void start() {
  2. //
  3. Observable.from(words)
  4. .toSortedList()
  5. .flatMap(new Func1<List<Integer>, Observable<Integer>>() {
  6. @Override
  7. public Observable<Integer> call(List<Integer> strings) {
  8. return Observable.from(strings);
  9. }
  10. })
  11. .subscribe(new Action1<Integer>() {
  12. @Override
  13. public void call(Integer strings) {
  14. mText.append(strings+"\n");
  15. }
  16. });
  17. }
  18. }

代码示例来源:origin: marcoRS/rxjava-essentials

  1. private void refreshTheList() {
  2. getApps().toSortedList().subscribe(new Observer<List<AppInfo>>() {
  3. @Override public void onCompleted() {
  4. Toast.makeText(getActivity(), "Here is the list!", Toast.LENGTH_LONG).show();
  5. }
  6. @Override public void onError(Throwable e) {
  7. Toast.makeText(getActivity(), "Something went wrong!", Toast.LENGTH_SHORT).show();
  8. mSwipeRefreshLayout.setRefreshing(false);
  9. }
  10. @Override public void onNext(List<AppInfo> appInfos) {
  11. mRecyclerView.setVisibility(View.VISIBLE);
  12. mAdapter.addApplications(appInfos);
  13. mSwipeRefreshLayout.setRefreshing(false);
  14. storeList(appInfos);
  15. }
  16. });
  17. }

代码示例来源:origin: com.netflix.spinnaker.orca/orca-core

  1. public @Nonnull
  2. List<Artifact> getArtifactsForPipelineId(
  3. @Nonnull String pipelineId,
  4. @Nonnull ExecutionCriteria criteria
  5. ) {
  6. Execution execution = executionRepository
  7. .retrievePipelinesForPipelineConfigId(pipelineId, criteria)
  8. .subscribeOn(Schedulers.io())
  9. .toSortedList(startTimeOrId)
  10. .toBlocking()
  11. .single()
  12. .stream()
  13. .findFirst()
  14. .orElse(null);
  15. return execution == null ? Collections.emptyList() : getAllArtifacts(execution);
  16. }

代码示例来源:origin: hawkular/hawkular-metrics

  1. private Observable<Date> findTimeSlices() {
  2. return session.execute(findActiveTimeSlices.bind(), queryScheduler)
  3. .flatMap(Observable::from)
  4. .map(row -> row.getTimestamp(0))
  5. .toSortedList()
  6. .flatMap(Observable::from);
  7. }

代码示例来源:origin: davidmoten/rxjava-extras

  1. @Override
  2. public Observable<T> call(Observable<T> o) {
  3. return o.toSortedList().flatMapIterable(Functions.<List<T>> identity());
  4. }
  5. };

代码示例来源:origin: com.github.davidmoten/rxjava-extras

  1. @Override
  2. public Observable<T> call(Observable<T> o) {
  3. return o.toSortedList().flatMapIterable(Functions.<List<T>> identity());
  4. }
  5. };

代码示例来源:origin: oubowu/YinyuetaiPlayer

  1. public static Subscription getVideoList(String id, int startPage, RequestCallback<List<VideoSummary>> callback) {
  2. return RetrofitManager.getInstance().getVideoListObservable("V9LG4B3A0", 0)//
  3. .flatMap(new Func1<Map<String, List<VideoSummary>>, Observable<VideoSummary>>() {
  4. @Override
  5. public Observable<VideoSummary> call(Map<String, List<VideoSummary>> map) {
  6. // 通过id取到list
  7. return Observable.from(map.get("V9LG4B3A0"));
  8. }
  9. })//
  10. .toSortedList(new Func2<VideoSummary, VideoSummary, Integer>() {
  11. @Override
  12. public Integer call(VideoSummary videoSummary, VideoSummary videoSummary2) {
  13. // 时间排序
  14. return videoSummary2.mPtime.compareTo(videoSummary.mPtime);
  15. }
  16. })//
  17. .subscribeOn(Schedulers.io())//
  18. .observeOn(AndroidSchedulers.mainThread())//
  19. .subscribe(new BaseSubscriber<>(callback));
  20. }

代码示例来源:origin: Piwigo/Piwigo-Android

  1. public Observable<List<Category>> getCategories(Account account, @Nullable Integer categoryId) {
  2. RestService restService = restServiceFactory.createForAccount(account);
  3. /* TODO: make thumbnail Size configurable, also check for ImageRepository, whether it can reduce the amount of REST/JSON traffic */
  4. return restService.getCategories(categoryId, "large")
  5. .flatMap(response -> Observable.from(response.result.categories))
  6. .filter(category -> categoryId == null || category.id != categoryId)
  7. // TODO: #90 generalize sorting
  8. .toSortedList((category1, category2) -> NaturalOrderComparator.compare(category1.globalRank, category2.globalRank))
  9. .compose(applySchedulers());
  10. }
  11. }

代码示例来源:origin: cesarferreira/RxPeople

  1. public Observable<List<FakeUser>> intoObservable() {
  2. String nationality = mNationality != null ? mNationality.toString() : null;
  3. Integer amount = mAmount > 0 ? mAmount : null;
  4. String gender = mGender != null ? mGender.toString() : null;
  5. return new RestClient()
  6. .getAPI()
  7. .getUsers(nationality, mSeed, amount, gender)
  8. .flatMap(new Func1<FetchedData, Observable<FakeUser>>() {
  9. @Override
  10. public Observable<FakeUser> call(FetchedData fetchedData) {
  11. return Observable.from(fetchedData.results);
  12. }
  13. }).flatMap(new Func1<FakeUser, Observable<FakeUser>>() {
  14. @Override
  15. public Observable<FakeUser> call(FakeUser user) {
  16. user.getName().title = RxPeople.this.upperCaseFirstLetter(user.getName().title);
  17. user.getName().first = RxPeople.this.upperCaseFirstLetter(user.getName().first);
  18. user.getName().last = RxPeople.this.upperCaseFirstLetter(user.getName().last);
  19. return Observable.just(user);
  20. }
  21. }).toSortedList();
  22. }

代码示例来源:origin: hawkular/hawkular-metrics

  1. public Observable<Date> findActiveTimeSlices(Date currentTime, rx.Scheduler scheduler) {
  2. return session.executeAndFetch(findTimeSlices.bind(), scheduler)
  3. .map(row -> row.getTimestamp(0))
  4. .filter(timestamp -> timestamp.compareTo(currentTime) < 0)
  5. .toSortedList()
  6. .doOnNext(timeSlices -> logger.debugf("Active time slices %s", timeSlices))
  7. .flatMap(Observable::from)
  8. .concatWith(Observable.just(currentTime));
  9. }

代码示例来源:origin: spencergibb/myfeed

  1. public Observable<List<FeedItem>> feed(String username) {
  2. return user.findId(username).toObservable()
  3. .flatMap(userid -> {
  4. if (StringUtils.hasText(userid)) {
  5. return Observable.from(repo.findByUserid(userid));
  6. } else {
  7. return Observable.just(singletonFeed("Unknown user: " + username));
  8. }
  9. })
  10. // sort by created desc since redis repo doesn't support order
  11. .flatMapIterable(feedItems -> feedItems)
  12. .toSortedList((feedItem1, feedItem2) -> feedItem2.getCreated().compareTo(feedItem1.getCreated()));
  13. }

代码示例来源:origin: com.github.davidmoten/rxjava-extras

  1. @Override
  2. public Observable<T> call(Observable<T> o) {
  3. return o.toSortedList(Functions.toFunc2(comparator))
  4. .flatMapIterable(Functions.<List<T>> identity());
  5. }
  6. };

代码示例来源:origin: davidmoten/rxjava-extras

  1. @Override
  2. public Observable<T> call(Observable<T> o) {
  3. return o.toSortedList(Functions.toFunc2(comparator))
  4. .flatMapIterable(Functions.<List<T>> identity());
  5. }
  6. };

代码示例来源:origin: plusCubed/anticipate

  1. /**
  2. * Returns sorted list of AppInfos.
  3. * <p/>
  4. * AppInfo's drawable and id are null
  5. */
  6. public static Single<List<AppInfo>> getInstalledApps(final Context context) {
  7. return Single.create(new Single.OnSubscribe<List<ApplicationInfo>>() {
  8. @Override
  9. public void call(SingleSubscriber<? super List<ApplicationInfo>> singleSubscriber) {
  10. singleSubscriber.onSuccess(context.getPackageManager().getInstalledApplications(0));
  11. }
  12. }).subscribeOn(Schedulers.io())
  13. .flatMapObservable(new Func1<List<ApplicationInfo>, Observable<ApplicationInfo>>() {
  14. @Override
  15. public Observable<ApplicationInfo> call(List<ApplicationInfo> appInfos) {
  16. return Observable.from(appInfos);
  17. }
  18. })
  19. .map(new Func1<ApplicationInfo, AppInfo>() {
  20. @Override
  21. public AppInfo call(ApplicationInfo applicationInfo) {
  22. AppInfo appInfo = new AppInfo();
  23. appInfo.packageName = applicationInfo.packageName;
  24. appInfo.name = applicationInfo.loadLabel(context.getPackageManager()).toString();
  25. return appInfo;
  26. }
  27. })
  28. .toSortedList().toSingle();
  29. }

代码示例来源:origin: gitskarios/GithubAndroidSdk

  1. private Observable<List<IssueStoryDetail>> getIssueDetailsObservable() {
  2. Observable<IssueStoryDetail> commentsDetailsObs = getCommentsDetailsObs();
  3. Observable<IssueStoryDetail> eventDetailsObs = getEventDetailsObs();
  4. Observable<IssueStoryDetail> reviewCommentsObs = getReviewCommentsDetailsObs();
  5. Observable<IssueStoryDetail> details =
  6. Observable.mergeDelayError(eventDetailsObs, reviewCommentsObs);
  7. return Observable.mergeDelayError(commentsDetailsObs, details)
  8. .toSortedList((issueStoryDetail, issueStoryDetail2) -> {
  9. return ((Long) issueStoryDetail.createdAt()).compareTo(issueStoryDetail2.createdAt());
  10. });
  11. }

相关文章

Observable类方法