I have the following classes:
@Setter
@NoArgsConstructor
public classAccount {
List<AccountRole> accountRoles = new ArrayList<>();
List<AccountRole> getAccountRoles() { return accountRoles };
}
@Setter
@NoArgsConstructor
public class AccountRole {
List<Operation> operations = new ArrayList<>();
List<Operation> getAllowedOperations( return operations);
String accountRole;
String getAuthority() { return accountRole; }
}
@Setter
@NoArgsConstructor
public class Operation {
String operation;
String getAuthority( return operation; )
}
I managed it to collect all authorities of the operations like:
account.getAccountRoles().stream()
.flatMap(accountRole -> accountRole.getAllowedOperations().stream().map(operation -> operation.getAuthority()))
.collect(Collectors.toList())
I didn't manage it to collect the authorities of account roles and the operations in one stream and merge them to the result list. Is there a possibility?
flatMap(accountRole -> Stream.concat(Stream.of(getAuthority()), accountRole.getAllowedOperations().stream().map(operation -> operation.getAuthority())))