From: Roland Häder Date: Sat, 30 Nov 2019 01:13:44 +0000 (+0100) Subject: Don't cherry-pick: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=6508c8b8dfc76698939a4e500c15f288d45b9962;p=jfinancials-war.git Don't cherry-pick: - rewrote isReceiptItemAdded() as contains() didn't work as expected - but still skip longer running code when contains() return true (same object) Signed-off-by: Roland Häder --- diff --git a/src/java/org/mxchange/jfinancials/beans/financial/model/receipt_item/list/FinancialsReceiptItemListWebViewBean.java b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt_item/list/FinancialsReceiptItemListWebViewBean.java index 146a06d1..07043211 100644 --- a/src/java/org/mxchange/jfinancials/beans/financial/model/receipt_item/list/FinancialsReceiptItemListWebViewBean.java +++ b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt_item/list/FinancialsReceiptItemListWebViewBean.java @@ -35,6 +35,7 @@ import org.mxchange.jfinancials.beans.user.login.FinancialsUserLoginWebSessionCo import org.mxchange.jfinancials.events.receipt_item.added.ObservableReceiptItemAddedEvent; import org.mxchange.jfinancials.model.receipt_item.BillableReceiptItem; import org.mxchange.jfinancials.model.receipt_item.FinancialReceiptItemSessionBeanRemote; +import org.mxchange.jfinancials.model.receipt_item.ReceiptItems; import org.mxchange.juserlogincore.events.login.ObservableUserLoggedInEvent; /** @@ -242,8 +243,33 @@ public class FinancialsReceiptItemListWebViewBean extends BaseFinancialsBean imp @Override public boolean isReceiptItemAdded (final BillableReceiptItem receiptItem) { - // Always trust the cache - return this.getAllReceiptItems().contains(receiptItem); + // Does it contain the same object? + if (this.getAllReceiptItems().contains(receiptItem)) { + // Yes, skip below code + return true; + } + + // Get iterator from list + final Iterator iterator = this.getAllReceiptItems().iterator(); + + // Default is not the same + boolean alreadyAdded = false; + + // Loop over all + while (iterator.hasNext()) { + // Get current item + final BillableReceiptItem item = iterator.next(); + + // Is the same? + if (ReceiptItems.isSameReceiptItem(item, receiptItem)) { + // Yes, found it + alreadyAdded = true; + break; + } + } + + // Return flag + return alreadyAdded; } }