【发布时间】:2016-07-12 15:59:45
【问题描述】:
如何简化基于先前过滤结果的流搜索?
HashMap<Boolean, List<Path>> result = (HashMap<Boolean, List<Path>>) Files.walk(Paths.get(folder)).map(Path
::toAbsolutePath).collect(Collectors.groupingBy(Files::isSymbolicLink));
result.get(true).stream().filter(path -> {
try {
return !result.get(false).contains(Files.readSymbolicLink(path));
} catch (IOException e) {
throw Throwables.propagate(e);
}
}).forEach(symbolicLink -> {
try {
result.get(false).addAll(Files.walk(symbolicLink, FileVisitOption.FOLLOW_LINKS).collect(Collectors
.toList()));
} catch (IOException e) {
throw Throwables.propagate(e);
}
});
return result.get(false).stream().filter(Files::isRegularFile).distinct().collect(Collectors.toList());
【问题讨论】:
标签: java search recursion collections java-stream