]> git.mxchange.org Git - jfinancials-war.git/commitdiff
Don't cherry-pick:
authorRoland Häder <roland@mxchange.org>
Sat, 30 Nov 2019 01:13:44 +0000 (02:13 +0100)
committerRoland Häder <roland@mxchange.org>
Sat, 30 Nov 2019 01:15:15 +0000 (02:15 +0100)
- 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 <roland@mxchange.org>
src/java/org/mxchange/jfinancials/beans/financial/model/receipt_item/list/FinancialsReceiptItemListWebViewBean.java

index 146a06d1c2f6c66fdd1320320e15b6790f6107bb..0704321158007919761ba4f9423144fc34b59f99 100644 (file)
@@ -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<BillableReceiptItem> 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;
        }
 
 }