本文整理了Java中rx.Observable.toSortedList()
方法的一些代码示例,展示了Observable.toSortedList()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Observable.toSortedList()
方法的具体详情如下:
包路径:rx.Observable
类名称: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
.toSortedList(new Func2<TopicsEntity, TopicsEntity, Integer>() {
@Override
public Integer call(TopicsEntity topicsEntity, TopicsEntity topicsEntity2) {
代码示例来源:origin: jaydenxiao2016/AndroidFire
@Override
public Observable<List<VideoData>> getVideosListData(final String type, int startPage) {
return Api.getDefault(HostType.NETEASE_NEWS_VIDEO).getVideoList(Api.getCacheControl(),type,startPage)
.flatMap(new Func1<Map<String, List<VideoData>>, Observable<VideoData>>() {
@Override
public Observable<VideoData> call(Map<String, List<VideoData>> map) {
return Observable.from(map.get(type));
}
})
//转化时间
.map(new Func1<VideoData, VideoData>() {
@Override
public VideoData call(VideoData videoData) {
String ptime = TimeUtil.formatDate(videoData.getPtime());
videoData.setPtime(ptime);
return videoData;
}
})
.distinct()//去重
.toSortedList(new Func2<VideoData, VideoData, Integer>() {
@Override
public Integer call(VideoData videoData, VideoData videoData2) {
return videoData2.getPtime().compareTo(videoData.getPtime());
}
})
//声明线程调度
.compose(RxSchedulers.<List<VideoData>>io_main());
}
}
代码示例来源:origin: jaydenxiao2016/AndroidFire
.toSortedList(new Func2<NewsSummary, NewsSummary, Integer>() {
@Override
public Integer call(NewsSummary newsSummary, NewsSummary newsSummary2) {
代码示例来源:origin: kaku2015/ColorfulNews
.toSortedList(new Func2<NewsSummary, NewsSummary, Integer>() {
@Override
public Integer call(NewsSummary newsSummary, NewsSummary newsSummary2) {
代码示例来源:origin: henrymorgen/android-advanced-light
private void toSortedList() {
Observable.just(3,1,2).toSortedList().subscribe(new Action1<List<Integer>>() {
@Override
public void call(List<Integer> integers) {
for(int integer :integers){
Log.i("wangshu", "toSortedList:" + integer);
}
}
});
}
代码示例来源:origin: ladingwu/ApplicationDemo
private void start() {
//
Observable.from(words)
.toSortedList()
.flatMap(new Func1<List<Integer>, Observable<Integer>>() {
@Override
public Observable<Integer> call(List<Integer> strings) {
return Observable.from(strings);
}
})
.subscribe(new Action1<Integer>() {
@Override
public void call(Integer strings) {
mText.append(strings+"\n");
}
});
}
}
代码示例来源:origin: marcoRS/rxjava-essentials
private void refreshTheList() {
getApps().toSortedList().subscribe(new Observer<List<AppInfo>>() {
@Override public void onCompleted() {
Toast.makeText(getActivity(), "Here is the list!", Toast.LENGTH_LONG).show();
}
@Override public void onError(Throwable e) {
Toast.makeText(getActivity(), "Something went wrong!", Toast.LENGTH_SHORT).show();
mSwipeRefreshLayout.setRefreshing(false);
}
@Override public void onNext(List<AppInfo> appInfos) {
mRecyclerView.setVisibility(View.VISIBLE);
mAdapter.addApplications(appInfos);
mSwipeRefreshLayout.setRefreshing(false);
storeList(appInfos);
}
});
}
代码示例来源:origin: com.netflix.spinnaker.orca/orca-core
public @Nonnull
List<Artifact> getArtifactsForPipelineId(
@Nonnull String pipelineId,
@Nonnull ExecutionCriteria criteria
) {
Execution execution = executionRepository
.retrievePipelinesForPipelineConfigId(pipelineId, criteria)
.subscribeOn(Schedulers.io())
.toSortedList(startTimeOrId)
.toBlocking()
.single()
.stream()
.findFirst()
.orElse(null);
return execution == null ? Collections.emptyList() : getAllArtifacts(execution);
}
代码示例来源:origin: hawkular/hawkular-metrics
private Observable<Date> findTimeSlices() {
return session.execute(findActiveTimeSlices.bind(), queryScheduler)
.flatMap(Observable::from)
.map(row -> row.getTimestamp(0))
.toSortedList()
.flatMap(Observable::from);
}
代码示例来源:origin: davidmoten/rxjava-extras
@Override
public Observable<T> call(Observable<T> o) {
return o.toSortedList().flatMapIterable(Functions.<List<T>> identity());
}
};
代码示例来源:origin: com.github.davidmoten/rxjava-extras
@Override
public Observable<T> call(Observable<T> o) {
return o.toSortedList().flatMapIterable(Functions.<List<T>> identity());
}
};
代码示例来源:origin: oubowu/YinyuetaiPlayer
public static Subscription getVideoList(String id, int startPage, RequestCallback<List<VideoSummary>> callback) {
return RetrofitManager.getInstance().getVideoListObservable("V9LG4B3A0", 0)//
.flatMap(new Func1<Map<String, List<VideoSummary>>, Observable<VideoSummary>>() {
@Override
public Observable<VideoSummary> call(Map<String, List<VideoSummary>> map) {
// 通过id取到list
return Observable.from(map.get("V9LG4B3A0"));
}
})//
.toSortedList(new Func2<VideoSummary, VideoSummary, Integer>() {
@Override
public Integer call(VideoSummary videoSummary, VideoSummary videoSummary2) {
// 时间排序
return videoSummary2.mPtime.compareTo(videoSummary.mPtime);
}
})//
.subscribeOn(Schedulers.io())//
.observeOn(AndroidSchedulers.mainThread())//
.subscribe(new BaseSubscriber<>(callback));
}
代码示例来源:origin: Piwigo/Piwigo-Android
public Observable<List<Category>> getCategories(Account account, @Nullable Integer categoryId) {
RestService restService = restServiceFactory.createForAccount(account);
/* TODO: make thumbnail Size configurable, also check for ImageRepository, whether it can reduce the amount of REST/JSON traffic */
return restService.getCategories(categoryId, "large")
.flatMap(response -> Observable.from(response.result.categories))
.filter(category -> categoryId == null || category.id != categoryId)
// TODO: #90 generalize sorting
.toSortedList((category1, category2) -> NaturalOrderComparator.compare(category1.globalRank, category2.globalRank))
.compose(applySchedulers());
}
}
代码示例来源:origin: cesarferreira/RxPeople
public Observable<List<FakeUser>> intoObservable() {
String nationality = mNationality != null ? mNationality.toString() : null;
Integer amount = mAmount > 0 ? mAmount : null;
String gender = mGender != null ? mGender.toString() : null;
return new RestClient()
.getAPI()
.getUsers(nationality, mSeed, amount, gender)
.flatMap(new Func1<FetchedData, Observable<FakeUser>>() {
@Override
public Observable<FakeUser> call(FetchedData fetchedData) {
return Observable.from(fetchedData.results);
}
}).flatMap(new Func1<FakeUser, Observable<FakeUser>>() {
@Override
public Observable<FakeUser> call(FakeUser user) {
user.getName().title = RxPeople.this.upperCaseFirstLetter(user.getName().title);
user.getName().first = RxPeople.this.upperCaseFirstLetter(user.getName().first);
user.getName().last = RxPeople.this.upperCaseFirstLetter(user.getName().last);
return Observable.just(user);
}
}).toSortedList();
}
代码示例来源:origin: hawkular/hawkular-metrics
public Observable<Date> findActiveTimeSlices(Date currentTime, rx.Scheduler scheduler) {
return session.executeAndFetch(findTimeSlices.bind(), scheduler)
.map(row -> row.getTimestamp(0))
.filter(timestamp -> timestamp.compareTo(currentTime) < 0)
.toSortedList()
.doOnNext(timeSlices -> logger.debugf("Active time slices %s", timeSlices))
.flatMap(Observable::from)
.concatWith(Observable.just(currentTime));
}
代码示例来源:origin: spencergibb/myfeed
public Observable<List<FeedItem>> feed(String username) {
return user.findId(username).toObservable()
.flatMap(userid -> {
if (StringUtils.hasText(userid)) {
return Observable.from(repo.findByUserid(userid));
} else {
return Observable.just(singletonFeed("Unknown user: " + username));
}
})
// sort by created desc since redis repo doesn't support order
.flatMapIterable(feedItems -> feedItems)
.toSortedList((feedItem1, feedItem2) -> feedItem2.getCreated().compareTo(feedItem1.getCreated()));
}
代码示例来源:origin: com.github.davidmoten/rxjava-extras
@Override
public Observable<T> call(Observable<T> o) {
return o.toSortedList(Functions.toFunc2(comparator))
.flatMapIterable(Functions.<List<T>> identity());
}
};
代码示例来源:origin: davidmoten/rxjava-extras
@Override
public Observable<T> call(Observable<T> o) {
return o.toSortedList(Functions.toFunc2(comparator))
.flatMapIterable(Functions.<List<T>> identity());
}
};
代码示例来源:origin: plusCubed/anticipate
/**
* Returns sorted list of AppInfos.
* <p/>
* AppInfo's drawable and id are null
*/
public static Single<List<AppInfo>> getInstalledApps(final Context context) {
return Single.create(new Single.OnSubscribe<List<ApplicationInfo>>() {
@Override
public void call(SingleSubscriber<? super List<ApplicationInfo>> singleSubscriber) {
singleSubscriber.onSuccess(context.getPackageManager().getInstalledApplications(0));
}
}).subscribeOn(Schedulers.io())
.flatMapObservable(new Func1<List<ApplicationInfo>, Observable<ApplicationInfo>>() {
@Override
public Observable<ApplicationInfo> call(List<ApplicationInfo> appInfos) {
return Observable.from(appInfos);
}
})
.map(new Func1<ApplicationInfo, AppInfo>() {
@Override
public AppInfo call(ApplicationInfo applicationInfo) {
AppInfo appInfo = new AppInfo();
appInfo.packageName = applicationInfo.packageName;
appInfo.name = applicationInfo.loadLabel(context.getPackageManager()).toString();
return appInfo;
}
})
.toSortedList().toSingle();
}
代码示例来源:origin: gitskarios/GithubAndroidSdk
private Observable<List<IssueStoryDetail>> getIssueDetailsObservable() {
Observable<IssueStoryDetail> commentsDetailsObs = getCommentsDetailsObs();
Observable<IssueStoryDetail> eventDetailsObs = getEventDetailsObs();
Observable<IssueStoryDetail> reviewCommentsObs = getReviewCommentsDetailsObs();
Observable<IssueStoryDetail> details =
Observable.mergeDelayError(eventDetailsObs, reviewCommentsObs);
return Observable.mergeDelayError(commentsDetailsObs, details)
.toSortedList((issueStoryDetail, issueStoryDetail2) -> {
return ((Long) issueStoryDetail.createdAt()).compareTo(issueStoryDetail2.createdAt());
});
}
内容来源于网络,如有侵权,请联系作者删除!