我第一次在我的应用程序中使用 rxJava 我试图实现以下实现:
从第 3 方服务器获取帐户
从本地数据库获取帐户
比较帐户并过滤掉那些不在本地数据库中的帐户
只保存那些不在本地数据库中的本地数据库中的帐户。
这是我的代码:-
private Observable<List<Result<Account, IError>>> filterAccounts(Context context, List<Account> accounts){
accountDAL.getByIds(context, accounts
.stream()
.map(a -> Long.valueOf(a.getAccountId()))
.collect(Collectors.toList()))//return Observable<List<T>> getByIds(Context context, List<Long> ids)
.map( a -> {
Map<Long, SearchConnectAccount> map = a.stream()
.collect(Collectors.toMap(a -> a.getId(), Function.identity())); // map ==> {id = Account}
return map;
}).subscribe( seMap -> { // subscribe observable
List<Account> filteredList = accounts.stream()
.filter(a -> seMap.get(Long.valueOf(a.getAccountId())) == null)
.collect(Collectors.toList());
Observable<List<Result<Account, IError>>> o = accountDAL.save(context, filteredList).first();
return o;//accountDAL.save(context, filteredList).first();
});
// how to return Observable<List<Result<Account, IError>>> from here
}
任何帮助表示赞赏。
慕标5832272
相关分类