This is an automated email from the ASF dual-hosted git repository.
daim pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git
The following commit(s) were added to refs/heads/trunk by this push:
new 7bfc8fedab OAK-11495 : added utils method for repalcing Guava's
Iterables.size (#2090)
7bfc8fedab is described below
commit 7bfc8fedabaadec617d68b6903c54d7f0a22ba61
Author: Rishabh Kumar <[email protected]>
AuthorDate: Wed Feb 19 09:40:34 2025 +0530
OAK-11495 : added utils method for repalcing Guava's Iterables.size (#2090)
Co-authored-by: Rishabh Kumar <[email protected]>
---
.../oak/commons/collections/IterableUtils.java | 11 +++++++++++
.../oak/commons/collections/IterableUtilsTest.java | 23 ++++++++++++++++++++++
2 files changed, 34 insertions(+)
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 42e237df7e..b420af18ec 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
@@ -155,4 +155,15 @@ public class IterableUtils {
public static <E> boolean contains(final Iterable<E> iterable, final
Object object) {
return
org.apache.commons.collections4.IterableUtils.contains(iterable, object);
}
+
+ /**
+ * Returns the number of elements in the specified iterable.
+ *
+ * @param itr the iterable to count elements in, may not be null
+ * @return the number of elements in the iterable
+ * @throws NullPointerException if the iterable is null
+ */
+ public static int size(final Iterable<?> itr) {
+ return org.apache.commons.collections4.IterableUtils.size(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 b2ee530863..de2f1bfab2 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
@@ -195,4 +195,27 @@ public class IterableUtilsTest {
public void testContainsWithNullIterable() {
Assert.assertFalse(IterableUtils.contains(null, "a"));
}
+
+ @Test
+ public void testSizeWithNonEmptyIterable() {
+ Iterable<String> iterable = Arrays.asList("a", "b", "c");
+ Assert.assertEquals(3, IterableUtils.size(iterable));
+ }
+
+ @Test
+ public void testSizeWithEmptyIterable() {
+ Iterable<String> iterable = Collections.emptyList();
+ Assert.assertEquals(0, IterableUtils.size(iterable));
+ }
+
+ @Test
+ public void testSizeWithSingleElement() {
+ Iterable<String> iterable = Collections.singletonList("a");
+ Assert.assertEquals(1, IterableUtils.size(iterable));
+ }
+
+ @Test
+ public void testSizeWithNullIterable() {
+ Assert.assertEquals(0, IterableUtils.size(null));
+ }
}