You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by tn...@apache.org on 2015/05/27 23:34:35 UTC
svn commit: r1682126 - in
/commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4:
FluentIterable.java IterableUtils.java IteratorUtils.java
Author: tn
Date: Wed May 27 21:34:35 2015
New Revision: 1682126
URL: http://svn.apache.org/r1682126
Log:
Add apply method to FluentIterable.
Modified:
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/FluentIterable.java
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/IterableUtils.java
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/IteratorUtils.java
Modified: commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/FluentIterable.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/FluentIterable.java?rev=1682126&r1=1682125&r2=1682126&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/FluentIterable.java (original)
+++ commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/FluentIterable.java Wed May 27 21:34:35 2015
@@ -345,6 +345,16 @@ public class FluentIterable<E> implement
}
/**
+ * Applies the closure to all elements contained in this iterable.
+ *
+ * @param closure the closure to apply to each element, may not be null
+ * @throws NullPointerException if closure is null
+ */
+ public void apply(final Closure<? super E> closure) {
+ IterableUtils.apply(iterable, closure);
+ }
+
+ /**
* Checks if all elements contained in this iterable are matching the
* provided predicate.
* <p>
Modified: commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/IterableUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/IterableUtils.java?rev=1682126&r1=1682125&r2=1682126&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/IterableUtils.java (original)
+++ commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/IterableUtils.java Wed May 27 21:34:35 2015
@@ -446,6 +446,18 @@ public class IterableUtils {
}
/**
+ * Applies the closure to each element of the provided iterable.
+ *
+ * @param <E> the element type
+ * @param iterable the iterator to use, may be null
+ * @param closure the closure to apply to each element, may not be null
+ * @throws NullPointerException if closure is null
+ */
+ public static <E> void apply(final Iterable<E> iterable, final Closure<? super E> closure) {
+ IteratorUtils.apply(emptyIteratorIfNull(iterable), closure);
+ }
+
+ /**
* Answers true if a predicate is true for every element of an iterable.
* <p>
* A <code>null</code> or empty iterable returns true.
Modified: commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/IteratorUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/IteratorUtils.java?rev=1682126&r1=1682125&r2=1682126&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/IteratorUtils.java (original)
+++ commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/IteratorUtils.java Wed May 27 21:34:35 2015
@@ -1176,6 +1176,28 @@ public class IteratorUtils {
//-----------------------------------------------------------------------
/**
+ * Applies the closure to each element of the provided iterator.
+ *
+ * @param <E> the element type
+ * @param iterator the iterator to use, may be null
+ * @param closure the closure to apply to each element, may not be null
+ * @throws NullPointerException if closure is null
+ * @since 4.1
+ */
+ public static <E> void apply(final Iterator<E> iterator, final Closure<? super E> closure) {
+ if (closure == null) {
+ throw new NullPointerException("Closure must not be null");
+ }
+
+ if (iterator != null) {
+ while (iterator.hasNext()) {
+ final E element = iterator.next();
+ closure.execute(element);
+ }
+ }
+ }
+
+ /**
* Answers true if a predicate is true for any element of the iterator.
* <p>
* A <code>null</code> or empty iterator returns false.