]> git.mxchange.org Git - jfinancials-war.git/commitdiff
Product-only:
authorRoland Häder <roland@mxchange.org>
Wed, 1 Apr 2020 18:26:34 +0000 (20:26 +0200)
committerRoland Häder <roland@mxchange.org>
Wed, 1 Apr 2020 18:26:34 +0000 (20:26 +0200)
- 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>
src/java/org/mxchange/jfinancials/beans/generic_product/list/FinancialsProductListWebViewBean.java
src/java/org/mxchange/jfinancials/beans/product_category/list/FinancialsCategoryListWebViewBean.java

index b91882de6b9fe39b28241bfe4d94f3889442a70c..28b691a9b6cbfcf15776b58296e05ca78c5b0578 100644 (file)
@@ -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
         */
index da8d7bcf117dad4badc539056e71e37826abf387..0416b3d5a8b744a080fa7c8d8eb00e08e15c7a80 100644 (file)
@@ -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;
                                }
                        }
                        );