I have the following Java method:
public List<GrantedAuthority> toAuthorities(Set<Role> roles) {
List<GrantedAuthority> authorities = new ArrayList<>();
if (null != roles) {
for (Role role : roles) {
for (Permission permission : role.getPermissions()) {
authorities.add(new SimpleGrantedAuthority("ROLE_" + permission.getLabel()));
}
}
}
return authorities;
}
I'm trying to rewrite it using Java 8 streams. My best attempt thus far:
public List<GrantedAuthority> toAuthorities(Set<Role> roles) {
List<GrantedAuthority> authorities = new ArrayList<>();
if (null != roles) {
roles.stream().filter(role -> ???).collect(Collectors.toList());
}
return authorities;
}
But I'm at a loss as to what I put in the stream filter (substituting ???)...any ideas?