我是eclipse插件开发的新手.
如何获取所有eclipse插件开发库的源代码?没有源代码,很难调试调用或查看实现.
我试图将嵌套的for循环转换为java 8流.
循环实现
private Set<String> getAllowRolesFromInheritedPolicy(String userId, List<Policy> allowedPoliciesThisCustomer) {
Set<String> allowedRolesThisUser = Sets.newHashSet();
for (Policy policy : allowedPoliciesThisCustomer) {
Map<String, Role> roles = policy.getRoles();
for (Role role : roles.values()) {
if (role.getUsers().contains(userId)) {
allowedRolesThisUser.add(role.getRoleName());
}
}
}
Run Code Online (Sandbox Code Playgroud)
在代码中role.getUsers()返回List<String>.
流实施
我试图将for循环更改为java 8流:
Set<String> allowedRolesThisUser = Sets.newHashSet(allowedPoliciesThisCustomer.stream()
.map(policy -> policy.getRoles().values())
.filter(role -> role.getUsers().contains(userId))
.collect(Collectors.toList()));
Run Code Online (Sandbox Code Playgroud)
但编译说:
error: cannot find symbol : .filter(role -> role.getUsers().contains(userId))
symbol: method getUsers(), location: variable role of type Collection<Role>
Run Code Online (Sandbox Code Playgroud)
Role有功能getUsers,Collection<Role> …