From 91ceebb6ebafb892baec22513515adaf405024ff Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Wed, 1 Apr 2020 20:26:34 +0200 Subject: [PATCH] Product-only: - 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 --- .../FinancialsProductListWebViewBean.java | 19 ++++++------------- .../FinancialsCategoryListWebViewBean.java | 15 ++++----------- 2 files changed, 10 insertions(+), 24 deletions(-) diff --git a/src/java/org/mxchange/jfinancials/beans/generic_product/list/FinancialsProductListWebViewBean.java b/src/java/org/mxchange/jfinancials/beans/generic_product/list/FinancialsProductListWebViewBean.java index b91882de..28b691a9 100644 --- a/src/java/org/mxchange/jfinancials/beans/generic_product/list/FinancialsProductListWebViewBean.java +++ b/src/java/org/mxchange/jfinancials/beans/generic_product/list/FinancialsProductListWebViewBean.java @@ -19,7 +19,6 @@ package org.mxchange.jfinancials.beans.generic_product.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; @@ -229,23 +228,17 @@ public class FinancialsProductListWebViewBean extends BaseFinancialsBean impleme // Is the list empty, but filled cache? if (this.getAllProducts().isEmpty() && this.productCache.iterator().hasNext()) { - // Get iterator - final Iterator> iterator = this.productCache.iterator(); - // Build up list - while (iterator.hasNext()) { - // GEt next element - final Cache.Entry next = iterator.next(); - + for (final Cache.Entry currentEntry : this.productCache) { // Add to list - this.getAllProducts().add(next.getValue()); + this.getAllProducts().add(currentEntry.getValue()); } // Sort list this.getAllProducts().sort(new Comparator() { @Override - public int compare (final Product o1, final Product o2) { - return o1.getProductId() > o2.getProductId() ? 1 : o1.getProductId() < o2.getProductId() ? -1 : 0; + public int compare (final Product product1, final Product product2) { + return product1.getProductId() > product2.getProductId() ? 1 : product1.getProductId() < product2.getProductId() ? -1 : 0; } } ); @@ -285,8 +278,8 @@ public class FinancialsProductListWebViewBean extends BaseFinancialsBean impleme /** * Adds unique instance to product list. First any existing instance is - * being removed, then the new instance is added. It also updates the - * cache regardless if found or not. + * being removed, then the new instance is added. It also updates the cache + * regardless if found or not. *

* @param product Product instance to add uniquely */ diff --git a/src/java/org/mxchange/jfinancials/beans/product_category/list/FinancialsCategoryListWebViewBean.java b/src/java/org/mxchange/jfinancials/beans/product_category/list/FinancialsCategoryListWebViewBean.java index da8d7bcf..0416b3d5 100644 --- a/src/java/org/mxchange/jfinancials/beans/product_category/list/FinancialsCategoryListWebViewBean.java +++ b/src/java/org/mxchange/jfinancials/beans/product_category/list/FinancialsCategoryListWebViewBean.java @@ -19,7 +19,6 @@ package org.mxchange.jfinancials.beans.product_category.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; @@ -204,23 +203,17 @@ public class FinancialsCategoryListWebViewBean extends BaseFinancialsBean implem // Is the list empty, but filled cache? if (this.allCategories.isEmpty() && this.categoryCache.iterator().hasNext()) { - // Get iterator - final Iterator> iterator = this.categoryCache.iterator(); - // Build up list - while (iterator.hasNext()) { - // GEt next element - final Cache.Entry next = iterator.next(); - + for (final Cache.Entry currentEntry : this.categoryCache) { // Add to list - this.allCategories.add(next.getValue()); + this.allCategories.add(currentEntry.getValue()); } // Sort list this.allCategories.sort(new Comparator() { @Override - public int compare (final Category o1, final Category o2) { - return o1.getCategoryId() > o2.getCategoryId() ? 1 : o1.getCategoryId() < o2.getCategoryId() ? -1 : 0; + public int compare (final Category category1, final Category category2) { + return category1.getCategoryId() > category2.getCategoryId() ? 1 : category1.getCategoryId() < category2.getCategoryId() ? -1 : 0; } } ); -- 2.39.5