From: Roland Häder <roland@mxchange.org>
Date: Wed, 1 Apr 2020 18:26:34 +0000 (+0200)
Subject: Product-only:
X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=91ceebb6ebafb892baec22513515adaf405024ff;p=jfinancials-war.git

Product-only:
- rewrote while(iterator) loops to for(item:List/Map.Entry) approach to avoid
  local copies of Iterator<Foo> instances

Signed-off-by: Roland Häder <roland@mxchange.org>
---

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<Cache.Entry<Long, Product>> iterator = this.productCache.iterator();
-
 			// Build up list
-			while (iterator.hasNext()) {
-				// GEt next element
-				final Cache.Entry<Long, Product> next = iterator.next();
-
+			for (final Cache.Entry<Long, Product> currentEntry : this.productCache) {
 				// Add to list
-				this.getAllProducts().add(next.getValue());
+				this.getAllProducts().add(currentEntry.getValue());
 			}
 
 			// Sort list
 			this.getAllProducts().sort(new Comparator<Product>() {
 				@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.
 	 * <p>
 	 * @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<Cache.Entry<Long, Category>> iterator = this.categoryCache.iterator();
-
 			// Build up list
-			while (iterator.hasNext()) {
-				// GEt next element
-				final Cache.Entry<Long, Category> next = iterator.next();
-
+			for (final Cache.Entry<Long, Category> currentEntry : this.categoryCache) {
 				// Add to list
-				this.allCategories.add(next.getValue());
+				this.allCategories.add(currentEntry.getValue());
 			}
 
 			// Sort list
 			this.allCategories.sort(new Comparator<Category>() {
 				@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;
 				}
 			}
 			);