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

jamesbognar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/juneau.git


The following commit(s) were added to refs/heads/master by this push:
     new f3f9817b9 Test modernization, clean up utility classes.
f3f9817b9 is described below

commit f3f9817b94f2e0074793da4849c69baec12b817f
Author: James Bognar <[email protected]>
AuthorDate: Mon Aug 25 11:26:38 2025 -0400

    Test modernization, clean up utility classes.
---
 .../org/apache/juneau/common/internal/Utils.java   | 30 ++++++++++++++++++----
 .../org/apache/juneau/internal/ObjectUtils.java    | 11 +-------
 2 files changed, 26 insertions(+), 15 deletions(-)

diff --git 
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/internal/Utils.java
 
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/internal/Utils.java
index 080e959f0..71578dddf 100644
--- 
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/internal/Utils.java
+++ 
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/internal/Utils.java
@@ -118,9 +118,29 @@ public class Utils {
                return opt(s);
        }
 
-       /** Equals */
-       public static <T> boolean eq(T s1, T s2) {
-               return Objects.equals(s1, s2);
+       /**
+        * Tests two objects for equality, gracefully handling nulls and arrays.
+        *
+        * @param <T> The value types.
+        * @param o1 Object 1.
+        * @param o2 Object 2.
+        * @return <jk>true</jk> if both objects are equal based on the {@link 
Object#equals(Object)} method.
+        */
+       public static <T> boolean eq(T o1, T o2) {
+               if (isArray(o1) && isArray(o2)) {
+                       int l1 = Array.getLength(o1), l2 = Array.getLength(o2);
+                       if (l1 != l2)
+                               return false;
+                       for (int i = 0; i < l1; i++)
+                               if (! eq(Array.get(o1, i), Array.get(o2, i)))
+                                       return false;
+                       return true;
+               }
+               return Objects.equals(o1, o2);
+       }
+
+       private static boolean isArray(Object o) {
+               return o != null && o.getClass().isArray();
        }
 
        /**
@@ -562,10 +582,10 @@ public class Utils {
                } else if (o2 == null) {
                        return 1;
                }
-       
+
                if (o1.getClass() == o2.getClass() && o1 instanceof Comparable)
                        return ((Comparable)o1).compareTo(o2);
-       
+
                return 0;
        }
 
diff --git 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/ObjectUtils.java
 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/ObjectUtils.java
index fa727e736..5b911dac9 100644
--- 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/ObjectUtils.java
+++ 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/ObjectUtils.java
@@ -39,16 +39,7 @@ public class ObjectUtils {
         * @return <jk>true</jk> if both objects are equal based on the {@link 
Object#equals(Object)} method.
         */
        public static <T> boolean eq(T o1, T o2) {
-               if (isArray(o1) && isArray(o2)) {
-                       int l1 = Array.getLength(o1), l2 = Array.getLength(o2);
-                       if (l1 != l2)
-                               return false;
-                       for (int i = 0; i < l1; i++)
-                               if (! eq(Array.get(o1, i), Array.get(o2, i)))
-                                       return false;
-                       return true;
-               }
-               return Objects.equals(o1, o2);
+               return Utils.eq(o1, o2);
        }
 
        /**

Reply via email to