How to write this logic, made in C#, in Java?
var posicoes = await _serviceProduto.BuscarClienteProduto(_userId, _userTipo, null, null);
var clientes = await _service.BuscarCliente(_userId, _userTipo, null);
var t = clientes.Where(a => !posicoes.Any(b => b.ClienteId == a.ClienteId)).ToList();
return Ok(t);
Whats the type of "var t"? The return of "BuscarClienteProduto" or "BuscarCliente"?
I'm doing something like this (it has some compiling errors):
Do you have any idea of what method is equivalent for "Any()"? Or should I make it all diffent?
List<CustomerProductResponse> posicoes = customerProductService.getClienteProduto(null, idUser, _userTipo, null);
List<CustomerResponse> clientes = customerService.getCliente(null, idUser, _userTipo);
List<CustomerResponse> lista = clientes.stream()
.filter(a -> !posicoes.xxx(b -> b.clienteId == a.clienteId))
.map(b -> new CustomerResponse(b))
.collect(Collectors.toList());
The equivalent is anyMatch
. You can use it as below:
List<CustomerResponse> lista = clientes.stream()
.filter(a -> !posicoes.stream().anyMatch(b -> b.clienteId == a.clienteId))
.collect(Collectors.toList());
EDIT: Removed the map
as it should not be necessary. The original C# code posted in the question does not have a Select
either, which would be the equivalent to Java's map
.
You can check more details in the official documentation .
You may also use noneMatch
, to avoid the negation. Details here .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.