I'm feeling uneasy with this service method that I wrote:
@Override
public Optional<Set<TenantDTO>> getAllTenantsOfUsers(Set<Long> usersIds) {
return Optional.ofNullable(usersIds)
.map((ids) -> tenantRepository.findAll(QTenant.tenant.users.any().id.in(usersIds)))
.map((it) -> StreamSupport.stream(it.spliterator(), false))
.map((strm) -> strm.map((tenant) -> tenantMapper.toDto(tenant)).collect(Collectors.toSet()));
}
My tenantRepository.findAll
returns an iterable
of Tenant
entity
Is this the better approach to get all performance, with good code?
userIds
nullable? Passing in an empty set, instead ofnull
, would be equivalent, and cleaner, and remove theOptional.ofNullable()
. \$\endgroup\$ – AJNeufeld Sep 2 at 3:36