I have 2 lists. One that I get the values of my database and others that I get as input.
I have to multiply the value of productQuantity (HerdList) by proporcionValue (HerdCompositionList) that matches the primary key (productCode, ageRangeCode) and sum the values.
Below is the code with the for loop. How do I do it with streams?
Herd (Input)
int productCode;
int ageRangeCode;
int productQuantity;
HerdComposition (DB)
Integer productCode;
Integer ageRangeCode;
BigDecimal proporcionValue;
for (Herd informedItem : prodution.getHerdList()) {
for (HerdComposition herdItem : HerdCompositionList) {
if (herdItem.getProductCode() == informedItem.getProductCode()
&& herdItem.getAgeRangeCode() == informedItem.getAgeRangeCode()) {
totalHerd = totalHerd
.add(herdItem.getProporcionValue()
.multiply(new BigDecimal(informedItem.getProductQuantity())));
}
}
}