Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/387.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
基于RxJava中的内部列表筛选列表_Java_Rx Java - Fatal编程技术网

基于RxJava中的内部列表筛选列表

基于RxJava中的内部列表筛选列表,java,rx-java,Java,Rx Java,我想使用rxJava过滤列表,并得出以下解决方案。但我在几个地方使用了Observable.toBlocking()。我能做得更优雅些吗 为了回答这个问题,我创建了一个列表,其中内部包含整数范围,比如(1-10,10-20),外部包含所有这些列表。我想根据内部列表中的术语过滤列表,这样我就可以传递一个集合searchList,如果内部列表包含searchList中的任何元素,我就想保留它 我的解决方案: public static List<List<Integer>>

我想使用rxJava过滤列表,并得出以下解决方案。但我在几个地方使用了Observable.toBlocking()。我能做得更优雅些吗

为了回答这个问题,我创建了一个列表,其中内部包含整数范围,比如(1-10,10-20),外部包含所有这些列表。我想根据内部列表中的术语过滤列表,这样我就可以传递一个集合searchList,如果内部列表包含searchList中的任何元素,我就想保留它

我的解决方案:

public static List<List<Integer>> longFuncReturnList(Iterable<List<Integer>> masterIterable, List<Integer> searchList) {

    return Observable.from(masterIterable)
    .filter(new Func1<List<Integer>, Boolean>() {
        @Override
        public Boolean call(List<Integer> t1) {


            Observable<Boolean> result = Observable.from(new IteratorIterable<Integer>(t1.iterator()))
                    .exists(new Func1<Integer, Boolean>() {
                @Override
                public Boolean call(Integer t1) {

                    return searchList.contains(t1); 
                }
            });
            return result.toBlocking().first();
        }
    }).toList().toBlocking().single();

}
public静态列表longFuncReturnList(Iterable masterIterable,List searchList){
返回可观察。从(可掌握)
.filter(新函数1(){
@凌驾
公共布尔调用(列表t1){
Observable result=Observable.from(新的IteratorIterable(t1.iterator()))
.exists(新函数1(){
@凌驾
公共布尔调用(整数t1){
返回searchList.contains(t1);
}
});
返回结果.toBlocking().first();
}
}).toList().toBlocking().single();
}
为此,我使用以下方法传递列表列表:

Iterable<List<Integer>> masterIterable = new IteratorIterable<List<Integer>>(masterList.iterator());
    longFuncReturnList(masterIterable);
Iterable masterIterable=新的iteratoretable(masterList.iterator());
longFuncReturnList(masterIterable);
主列表是我的列表列表

对于过滤,我使用Observable.exists()但由于它返回另一个Observable,我使用toblock().first()获得布尔结果

我的解决方案正确吗?
如何改进它?

考虑到函数的签名,我认为它应该是同步的。那你为什么还需要RxJava呢?我在试着用RxJava从excel表格中读取数据。因为我有很多数据的大张表,所以我认为RxJava会很有帮助。我有多个场景需要根据单元格数据筛选出行。此实现用于测试。