This is an automated email from the ASF dual-hosted git repository.

pgil pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git


The following commit(s) were added to refs/heads/trunk by this push:
     new cb4b33e16d Improved : Refactor some `for loops` to streams for 
readability purpose.
cb4b33e16d is described below

commit cb4b33e16d00af6e795694807fbbe447519489fb
Author: Gil Portenseigne <[email protected]>
AuthorDate: Fri Dec 5 11:42:17 2025 +0100

    Improved : Refactor some `for loops` to streams for readability purpose.
    
    No functionnal changes.
---
 .../ofbiz/product/store/ProductStoreWorker.java    | 58 +++++-----------------
 .../org/apache/ofbiz/entity/model/ModelReader.java | 11 +---
 .../ofbiz/webapp/control/RequestHandler.java       | 10 +---
 3 files changed, 16 insertions(+), 63 deletions(-)

diff --git 
a/applications/product/src/main/java/org/apache/ofbiz/product/store/ProductStoreWorker.java
 
b/applications/product/src/main/java/org/apache/ofbiz/product/store/ProductStoreWorker.java
index 08f4aca97d..d337c584ef 100644
--- 
a/applications/product/src/main/java/org/apache/ofbiz/product/store/ProductStoreWorker.java
+++ 
b/applications/product/src/main/java/org/apache/ofbiz/product/store/ProductStoreWorker.java
@@ -20,7 +20,6 @@ package org.apache.ofbiz.product.store;
 
 import java.math.BigDecimal;
 import java.security.SecureRandom;
-import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Locale;
@@ -241,10 +240,7 @@ public final class ProductStoreWorker {
 
     public static List<GenericValue> 
getAvailableStoreShippingMethods(Delegator delegator, String productStoreId, 
GenericValue shippingAddress,
             List<BigDecimal> itemSizes, Map<String, BigDecimal> featureIdMap, 
BigDecimal weight, BigDecimal orderTotal) {
-        if (featureIdMap == null) {
-            featureIdMap = new HashMap<>();
-        }
-        List<GenericValue> shippingMethods = null;
+        List<GenericValue> shippingMethods;
         try {
             shippingMethods = 
EntityQuery.use(delegator).from("ProductStoreShipmentMethView").where("productStoreId",
                     
productStoreId).orderBy("sequenceNumber").cache(true).queryList();
@@ -287,33 +283,13 @@ public final class ProductStoreWorker {
                 BigDecimal minSize = method.getBigDecimal("minSize");
                 BigDecimal maxSize = method.getBigDecimal("maxSize");
                 if (minSize != null && minSize.compareTo(BigDecimal.ZERO) > 0) 
{
-                    boolean allMatch = false;
-                    if (itemSizes != null) {
-                        allMatch = true;
-                        for (BigDecimal size: itemSizes) {
-                            if (size.compareTo(minSize) < 0) {
-                                allMatch = false;
-                                break;
-                            }
-                        }
-                    }
-                    if (!allMatch) {
+                    if (itemSizes == null || itemSizes.stream().anyMatch(size 
-> size.compareTo(minSize) < 0)) {
                         returnShippingMethods.remove(method);
                         continue;
                     }
                 }
                 if (maxSize != null && maxSize.compareTo(BigDecimal.ZERO) > 0) 
{
-                    boolean allMatch = false;
-                    if (itemSizes != null) {
-                        allMatch = true;
-                        for (BigDecimal size: itemSizes) {
-                            if (size.compareTo(maxSize) > 0) {
-                                allMatch = false;
-                                break;
-                            }
-                        }
-                    }
-                    if (!allMatch) {
+                    if (itemSizes == null || itemSizes.stream().anyMatch(size 
-> size.compareTo(maxSize) > 0)) {
                         returnShippingMethods.remove(method);
                         continue;
                     }
@@ -396,18 +372,12 @@ public final class ProductStoreWorker {
                     } catch (GenericEntityException e) {
                         Debug.logError(e, "Unable to lookup 
ProductFeatureGroupAppl records for group : " + includeFeatures, MODULE);
                     }
-                    if (includedFeatures != null) {
-                        boolean foundOne = false;
-                        for (GenericValue appl: includedFeatures) {
-                            if 
(featureIdMap.containsKey(appl.getString("productFeatureId"))) {
-                                foundOne = true;
-                                break;
-                            }
-                        }
-                        if (!foundOne) {
-                            returnShippingMethods.remove(method);
-                            continue;
-                        }
+                    if (includedFeatures != null
+                            && (featureIdMap == null
+                                || includedFeatures.stream().noneMatch(
+                                    appl -> 
featureIdMap.containsKey(appl.getString("productFeatureId"))))) {
+                        returnShippingMethods.remove(method);
+                        continue;
                     }
                 }
                 if (UtilValidate.isNotEmpty(excludeFeatures)) {
@@ -418,13 +388,9 @@ public final class ProductStoreWorker {
                     } catch (GenericEntityException e) {
                         Debug.logError(e, "Unable to lookup 
ProductFeatureGroupAppl records for group : " + excludeFeatures, MODULE);
                     }
-                    if (excludedFeatures != null) {
-                        for (GenericValue appl: excludedFeatures) {
-                            if 
(featureIdMap.containsKey(appl.getString("productFeatureId"))) {
-                                returnShippingMethods.remove(method);
-                                continue;
-                            }
-                        }
+                    if (excludedFeatures != null && featureIdMap != null
+                            && excludedFeatures.stream().anyMatch(appl -> 
featureIdMap.containsKey(appl.getString("productFeatureId")))) {
+                        returnShippingMethods.remove(method);
                     }
                 }
             }
diff --git 
a/framework/entity/src/main/java/org/apache/ofbiz/entity/model/ModelReader.java 
b/framework/entity/src/main/java/org/apache/ofbiz/entity/model/ModelReader.java
index afd0a14c46..586adda86b 100644
--- 
a/framework/entity/src/main/java/org/apache/ofbiz/entity/model/ModelReader.java
+++ 
b/framework/entity/src/main/java/org/apache/ofbiz/entity/model/ModelReader.java
@@ -573,15 +573,8 @@ public final class ModelReader implements Serializable {
 
             if (UtilValidate.isNotEmpty(packageFilterSet)) {
                 // does it match any of these?
-                boolean foundMatch = false;
-                for (String packageFilter : packageFilterSet) {
-                    if (packageName.contains(packageFilter)) {
-                        foundMatch = true;
-                        break;
-                    }
-                }
-                if (!foundMatch) {
-                    // Debug.logInfo("Not including entity " + entityName + " 
becuase it is not in
+                if 
(packageFilterSet.stream().noneMatch(packageName::contains)) {
+                    // Debug.logInfo("Not including entity " + entityName + " 
because it is not in
                     // the package set: " + packageFilterSet, MODULE);
                     continue;
                 }
diff --git 
a/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/RequestHandler.java
 
b/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/RequestHandler.java
index e94c3f43f8..ae593e33ba 100644
--- 
a/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/RequestHandler.java
+++ 
b/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/RequestHandler.java
@@ -26,6 +26,7 @@ import java.net.MalformedURLException;
 import java.net.URL;
 import java.security.cert.X509Certificate;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Enumeration;
@@ -631,14 +632,7 @@ public final class RequestHandler {
             }
         } else if (requestUri != null) {
             String[] loginUris = 
EntityUtilProperties.getPropertyValue("security", "login.uris", 
delegator).split(",");
-            boolean removePreviousRequest = true;
-            for (int i = 0; i < loginUris.length; i++) {
-                if (requestUri.equals(loginUris[i])) {
-                    removePreviousRequest = false;
-                    break;
-                }
-            }
-            if (removePreviousRequest) {
+            if (Arrays.asList(loginUris).contains(requestUri)) {
                 // Remove previous request attribute on navigation to 
non-authenticated request
                 request.getSession().removeAttribute("_PREVIOUS_REQUEST_");
             }

Reply via email to