mbaedke commented on code in PR #2162:
URL: https://github.com/apache/jackrabbit-oak/pull/2162#discussion_r1987628126
##########
oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/collections/IterableUtils.java:
##########
@@ -446,4 +446,33 @@ public static <T> T find(final Iterable<T> iterable, final
Predicate<? super T>
Objects.requireNonNull(predicate, "Predicate must not be null.");
return org.apache.commons.collections4.IterableUtils.find(iterable,
predicate::test);
}
+
+ /**
+ * Returns the last element of the specified iterable, or null if the
iterable is empty.
+ * <p>
+ * The iterable must be fully traversed to find the last element. If the
iterable is empty,
+ * the null is returned instead.
+ *
+ * @param <T> the type of elements in the iterable
+ * @param iterable the iterable to get the last element from, must not be
null
+ * @return the last element in the iterable or null if the iterable is
empty
+ */
+ public static <T> T getLast(final Iterable<T> iterable) {
+
+ Objects.requireNonNull(iterable, "Iterable must not be null.");
+
+ // Optimize for Collections, especially Lists
Review Comment:
//Optimize for Lists.
I don't see any other optimization.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]