@Override public List<AccountGroupSelection> getAccountGroupsForSelection(ID accountId) { // Account groups or none Set<Integer> accountGroupIds = accountId.ifSet(accountGroupRepository::findByAccount) .orElse(Collections.emptyList()) .stream() .map(Entity::id) .collect(Collectors.toSet()); // Collection of groups with the selection return getAccountGroups().stream() .map(group -> AccountGroupSelection.of(group, accountGroupIds.contains(group.id()))) .collect(Collectors.toList()); }
public static AccountGroupSelection of(AccountGroup group, boolean selected) { return new AccountGroupSelection(group.id(), group.getName(), selected); }