From 2ee278b528e7b3d070d628b31527fcd88ffdf3e5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Wed, 1 Apr 2020 20:27:34 +0200 Subject: [PATCH] Don't cherry-pick: - rewrote while(iterator) loops to for(item:List/Map.Entry) approach to avoid local copies of Iterator instances MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../FinancialsReceiptListWebViewBean.java | 15 ++++-------- .../FinancialsReceiptItemListWebViewBean.java | 23 ++++--------------- 2 files changed, 9 insertions(+), 29 deletions(-) diff --git a/src/java/org/mxchange/jfinancials/beans/financial/model/receipt/list/FinancialsReceiptListWebViewBean.java b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt/list/FinancialsReceiptListWebViewBean.java index 02373c0b..bef24c59 100644 --- a/src/java/org/mxchange/jfinancials/beans/financial/model/receipt/list/FinancialsReceiptListWebViewBean.java +++ b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt/list/FinancialsReceiptListWebViewBean.java @@ -19,7 +19,6 @@ package org.mxchange.jfinancials.beans.financial.model.receipt.list; import fish.payara.cdi.jsr107.impl.NamedCache; import java.text.MessageFormat; import java.util.Comparator; -import java.util.Iterator; import java.util.LinkedList; import java.util.List; import javax.annotation.PostConstruct; @@ -195,23 +194,17 @@ public class FinancialsReceiptListWebViewBean extends BaseFinancialsBean impleme // Is the list empty, but filled cache? if (this.getAllReceipts().isEmpty() && this.receiptCache.iterator().hasNext()) { - // Get iterator - final Iterator> iterator = this.receiptCache.iterator(); - // Build up list - while (iterator.hasNext()) { - // GEt next element - final Cache.Entry next = iterator.next(); - + for (final Cache.Entry currentEntry : this.receiptCache) { // Add to list - this.getAllReceipts().add(next.getValue()); + this.getAllReceipts().add(currentEntry.getValue()); } // Sort list this.getAllReceipts().sort(new Comparator() { @Override - public int compare (final BillableReceipt o1, final BillableReceipt o2) { - return o1.getReceiptId() > o2.getReceiptId() ? 1 : o1.getReceiptId() < o2.getReceiptId() ? -1 : 0; + public int compare (final BillableReceipt receipt1, final BillableReceipt receipt2) { + return receipt1.getReceiptId() > receipt2.getReceiptId() ? 1 : receipt1.getReceiptId() < receipt2.getReceiptId() ? -1 : 0; } } ); 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 77c43fc2..a9b5194a 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 @@ -19,7 +19,6 @@ package org.mxchange.jfinancials.beans.financial.model.receipt_item.list; import fish.payara.cdi.jsr107.impl.NamedCache; import java.text.MessageFormat; import java.util.Comparator; -import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Objects; @@ -218,23 +217,17 @@ public class FinancialsReceiptItemListWebViewBean extends BaseFinancialsBean imp // Is the list empty, but filled cache? if (this.getAllReceiptItems().isEmpty() && this.receiptItemCache.iterator().hasNext()) { - // Get iterator - final Iterator> iterator = this.receiptItemCache.iterator(); - // Build up list - while (iterator.hasNext()) { - // GEt next element - final Cache.Entry next = iterator.next(); - + for (final Cache.Entry currentEntry : this.receiptItemCache) { // Add to list - this.getAllReceiptItems().add(next.getValue()); + this.getAllReceiptItems().add(currentEntry.getValue()); } // Sort list this.getAllReceiptItems().sort(new Comparator() { @Override - public int compare (final BillableReceiptItem o1, final BillableReceiptItem o2) { - return o1.getItemId() > o2.getItemId() ? 1 : o1.getItemId() < o2.getItemId() ? -1 : 0; + public int compare (final BillableReceiptItem receiptItem1, final BillableReceiptItem receiptItem2) { + return receiptItem1.getItemId() > receiptItem2.getItemId() ? 1 : receiptItem1.getItemId() < receiptItem2.getItemId() ? -1 : 0; } } ); @@ -249,17 +242,11 @@ public class FinancialsReceiptItemListWebViewBean extends BaseFinancialsBean imp 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(); - + for (final BillableReceiptItem item : this.getAllReceiptItems()) { // Is the same? if (ReceiptItems.isSameReceiptItem(item, receiptItem)) { // Yes, found it -- 2.39.5