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

daim pushed a commit to branch OAK-11503
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git

commit 11cee42a635092603a57db94c15675196d2540d4
Author: Rishabh Kumar <[email protected]>
AuthorDate: Wed Feb 19 13:34:50 2025 +0530

    OAK-11503 : added utils method for repalcing Guava's Iterables.size
---
 .../oak/commons/collections/IterableUtils.java     | 11 ++++++++++-
 .../oak/commons/collections/IterableUtilsTest.java | 23 ++++++++++++++++++++++
 2 files changed, 33 insertions(+), 1 deletion(-)

diff --git 
a/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/collections/IterableUtils.java
 
b/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/collections/IterableUtils.java
index 15e3cb9f63..9a05516269 100644
--- 
a/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/collections/IterableUtils.java
+++ 
b/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/collections/IterableUtils.java
@@ -18,7 +18,6 @@
  */
 package org.apache.jackrabbit.oak.commons.collections;
 
-import org.apache.commons.collections4.IteratorUtils;
 import org.apache.commons.collections4.Predicate;
 import org.apache.commons.collections4.iterators.LazyIteratorChain;
 
@@ -181,4 +180,14 @@ public class IterableUtils {
     public static <E> boolean matchesAll(final Iterable<E> itr, final 
Predicate<? super E> predicate) {
         return org.apache.commons.collections4.IterableUtils.matchesAll(itr, 
predicate);
     }
+
+    /**
+     * Checks if the specified iterable is empty.
+     *
+     * @param itr the iterable to check, may be null
+     * @return true if the iterable is empty or null, false otherwise
+     */
+    public static boolean isEmpty(final Iterable<?> itr) {
+        return org.apache.commons.collections4.IterableUtils.isEmpty(itr);
+    }
 }
diff --git 
a/oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/collections/IterableUtilsTest.java
 
b/oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/collections/IterableUtilsTest.java
index 3f468924ed..39dd3a7472 100644
--- 
a/oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/collections/IterableUtilsTest.java
+++ 
b/oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/collections/IterableUtilsTest.java
@@ -254,4 +254,27 @@ public class IterableUtilsTest {
             IterableUtils.matchesAll(iterable, null);
         });
     }
+
+    @Test
+    public void testIsEmptyWithEmptyIterable() {
+        Iterable<String> iterable = Collections.emptyList();
+        Assert.assertTrue(IterableUtils.isEmpty(iterable));
+    }
+
+    @Test
+    public void testIsEmptyWithNonEmptyIterable() {
+        Iterable<String> iterable = Arrays.asList("a", "b", "c");
+        Assert.assertFalse(IterableUtils.isEmpty(iterable));
+    }
+
+    @Test
+    public void testIsEmptyWithSingleElement() {
+        Iterable<String> iterable = Collections.singletonList("a");
+        Assert.assertFalse(IterableUtils.isEmpty(iterable));
+    }
+
+    @Test
+    public void testIsEmptyWithNullIterable() {
+        Assert.assertTrue(IterableUtils.isEmpty(null));
+    }
 }

Reply via email to