]> git.mxchange.org Git - jfinancials-war.git/commitdiff
Don't cherry-pick:
authorRoland Häder <roland@mxchange.org>
Wed, 1 Apr 2020 18:27:34 +0000 (20:27 +0200)
committerRoland Häder <roland@mxchange.org>
Wed, 1 Apr 2020 18:27:34 +0000 (20:27 +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/financial/model/receipt/list/FinancialsReceiptListWebViewBean.java
src/java/org/mxchange/jfinancials/beans/financial/model/receipt_item/list/FinancialsReceiptItemListWebViewBean.java

index 02373c0b0219775c6dca8210b78cc2a029824ec1..bef24c59eca52573863ab150c9b9f65eb5ac9036 100644 (file)
@@ -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<Cache.Entry<Long, BillableReceipt>> iterator = this.receiptCache.iterator();
-
                        // Build up list
-                       while (iterator.hasNext()) {
-                               // GEt next element
-                               final Cache.Entry<Long, BillableReceipt> next = iterator.next();
-
+                       for (final Cache.Entry<Long, BillableReceipt> currentEntry : this.receiptCache) {
                                // Add to list
-                               this.getAllReceipts().add(next.getValue());
+                               this.getAllReceipts().add(currentEntry.getValue());
                        }
 
                        // Sort list
                        this.getAllReceipts().sort(new Comparator<BillableReceipt>() {
                                @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;
                                }
                        }
                        );
index 77c43fc2a712afd68cdb4e88d1f3f81f6528e3b0..a9b5194a92fad031cdaf4a6aeb8c6db8119993be 100644 (file)
@@ -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<Cache.Entry<Long, BillableReceiptItem>> iterator = this.receiptItemCache.iterator();
-
                        // Build up list
-                       while (iterator.hasNext()) {
-                               // GEt next element
-                               final Cache.Entry<Long, BillableReceiptItem> next = iterator.next();
-
+                       for (final Cache.Entry<Long, BillableReceiptItem> currentEntry : this.receiptItemCache) {
                                // Add to list
-                               this.getAllReceiptItems().add(next.getValue());
+                               this.getAllReceiptItems().add(currentEntry.getValue());
                        }
 
                        // Sort list
                        this.getAllReceiptItems().sort(new Comparator<BillableReceiptItem>() {
                                @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<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();
-
+               for (final BillableReceiptItem item : this.getAllReceiptItems()) {
                        // Is the same?
                        if (ReceiptItems.isSameReceiptItem(item, receiptItem)) {
                                // Yes, found it