I have an "ItemSolicCompra" object and inside this object has another object called "Product" and product has attributes (name, id, etc ...). I have a List that on some occasions these products are repeated (id, name, qtde).
I would like to know if you have how to get the product "x @ 123" and "x @ 456" that has equal attributes, play in a list and add their quantities, because in my for it is infinitely passing through the objects and accounting . The sum should give 10 but continues to execute by doing (... 15 ... 20 ... 25 ... 30 ... 35), and the maximum sum of the quantity of the objects should be 10.
private int calculaQtde(_Produto produto, _Compra compra) {
int somaTotal = 0;
for(_ItemOrcamento itemOrcamento:compra.getItens()){
for (_SolicCompra solicCompra:itemOrcamento.getOrcamento().getCotacao().getSolicitacoes()){
for (_ItemSolicCompra itemSolicCompra:solicCompra.getItens()){
if (itemSolicCompra.getProduto().getId() == produto.getId()) {
somaTotal += itemSolicCompra.getQtde();
}
}
}
}
return somaTotal;
}