You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by da...@apache.org on 2025/02/19 08:05:01 UTC
(jackrabbit-oak) branch OAK-11503 created (now 11cee42a63)
This is an automated email from the ASF dual-hosted git repository.
daim pushed a change to branch OAK-11503
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git
at 11cee42a63 OAK-11503 : added utils method for repalcing Guava's Iterables.size
This branch includes the following new commits:
new 11cee42a63 OAK-11503 : added utils method for repalcing Guava's Iterables.size
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(jackrabbit-oak) 01/01: OAK-11503 : added utils method for repalcing Guava's Iterables.size
Posted by da...@apache.org.
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 <di...@adobe.com>
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));
+ }
}