For small datasets, what would be better when it comes to good practices and performance?
Using streams with an AtomicBoolean (with the overhead it adds) like this:
AtomicBoolean paymentFound = new AtomicBoolean(false);
providerProduct.getProviderPayments().stream()
.filter(payment -> payment.isCorporateCreditCard() && providerId.equals(payment.getPaymentCreditCard().getId()))
.forEach(payment -> {
if (!paymentFound.get()) {
setPaymentValues(product, providerProduct, payment);
paymentFound.set(true);
}
providerPayments.add(payment);
});
}
Or avoid using the AtomicBoolean and have this instead:
private void calculateWhatever(Product product, ProviderProduct providerProduct) {
boolean paymentFound = false;
for (ProviderPayment payment : providerProduct.getProviderPayments()) {
CreditCard creditCard = payment.getPaymentCreditCard();
if (payment.isCorporateCreditCard() && providerId.equals(creditCard.getId())) {
if (!paymentFound) {
setPaymentValues(product, providerProduct, payment);
paymentFound = true;
}
providerPayments.add(payment);
}
}
}