From d92476ab8896570d110f7ed689e615c5fcb842d1 Mon Sep 17 00:00:00 2001 From: Riccardo Ianniello Date: Thu, 9 Jan 2020 15:24:44 +0100 Subject: [PATCH] (#1226) Moved ForEach primitives to func package --- .../cactoos/{iterator => func}/ForEach.java | 23 +++-------- .../{iterator => func}/ForEachInThreads.java | 26 ++++-------- .../ForEachInThreadsTest.java | 40 +------------------ .../{iterator => func}/ForEachTest.java | 23 +++-------- 4 files changed, 19 insertions(+), 93 deletions(-) rename src/main/java/org/cactoos/{iterator => func}/ForEach.java (82%) rename src/main/java/org/cactoos/{iterator => func}/ForEachInThreads.java (80%) rename src/test/java/org/cactoos/{iterator => func}/ForEachInThreadsTest.java (70%) rename src/test/java/org/cactoos/{iterator => func}/ForEachTest.java (80%) diff --git a/src/main/java/org/cactoos/iterator/ForEach.java b/src/main/java/org/cactoos/func/ForEach.java similarity index 82% rename from src/main/java/org/cactoos/iterator/ForEach.java rename to src/main/java/org/cactoos/func/ForEach.java index 0c63322da2..1ba771e81a 100644 --- a/src/main/java/org/cactoos/iterator/ForEach.java +++ b/src/main/java/org/cactoos/func/ForEach.java @@ -21,12 +21,10 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package org.cactoos.iterator; +package org.cactoos.func; import org.cactoos.Func; import org.cactoos.Proc; -import org.cactoos.func.FuncOf; -import org.cactoos.iterable.IterableOf; import org.cactoos.scalar.And; /** @@ -49,14 +47,14 @@ * There is no thread-safety guarantee. * * @param The type to itetare over - * @since 0.44 + * @since 1.0 */ public final class ForEach implements Proc> { /** * The proc. */ - private final Func wrapped; + private final Func func; /** * Ctor. @@ -64,26 +62,15 @@ public final class ForEach implements Proc> { * @param proc The proc to execute */ public ForEach(final Proc proc) { - this.wrapped = new FuncOf<>( + this.func = new FuncOf<>( proc, true ); } - /** - * Ctor. - * - * @param src The iterable - * @exception Exception If fails - */ - @SafeVarargs - public final void exec(final X... src) throws Exception { - this.exec(new IterableOf<>(src)); - } - @Override public void exec(final Iterable input) throws Exception { new And( - this.wrapped, input + this.func, input ).value(); } diff --git a/src/main/java/org/cactoos/iterator/ForEachInThreads.java b/src/main/java/org/cactoos/func/ForEachInThreads.java similarity index 80% rename from src/main/java/org/cactoos/iterator/ForEachInThreads.java rename to src/main/java/org/cactoos/func/ForEachInThreads.java index 1440444d81..8d5a4ead06 100644 --- a/src/main/java/org/cactoos/iterator/ForEachInThreads.java +++ b/src/main/java/org/cactoos/func/ForEachInThreads.java @@ -21,12 +21,10 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package org.cactoos.iterator; +package org.cactoos.func; import org.cactoos.Func; import org.cactoos.Proc; -import org.cactoos.func.FuncOf; -import org.cactoos.iterable.IterableOf; import org.cactoos.scalar.AndInThreads; /** @@ -44,20 +42,21 @@ * new ProcOf<>(input -> System.out.printf("\'%s\' ", input)), * ).execute( * new IterableOf<>("Mary", "John", "William", "Napkin") - * ); // will print 'Mary' 'John' 'William' 'Napkin' to standard output. Sorting is not guaranteed. + * ); // Will print 'Mary' 'John' 'William' 'Napkin' to standard output. + * // Order of printing can be random. * } *

* There is no thread-safety guarantee. * * @param The type to itetare over - * @since 0.44 + * @since 1.0 */ public final class ForEachInThreads implements Proc> { /** * The proc. */ - private final Func wrapped; + private final Func func; /** * Ctor. @@ -65,26 +64,15 @@ public final class ForEachInThreads implements Proc> { * @param proc The proc to execute */ public ForEachInThreads(final Proc proc) { - this.wrapped = new FuncOf<>( + this.func = new FuncOf<>( proc, true ); } - /** - * Ctor. - * - * @param src The iterable - * @exception Exception If fails - */ - @SafeVarargs - public final void exec(final X... src) throws Exception { - this.exec(new IterableOf<>(src)); - } - @Override public void exec(final Iterable input) throws Exception { new AndInThreads( - this.wrapped, input + this.func, input ).value(); } diff --git a/src/test/java/org/cactoos/iterator/ForEachInThreadsTest.java b/src/test/java/org/cactoos/func/ForEachInThreadsTest.java similarity index 70% rename from src/test/java/org/cactoos/iterator/ForEachInThreadsTest.java rename to src/test/java/org/cactoos/func/ForEachInThreadsTest.java index ff2476eb13..20cef9ac36 100644 --- a/src/test/java/org/cactoos/iterator/ForEachInThreadsTest.java +++ b/src/test/java/org/cactoos/func/ForEachInThreadsTest.java @@ -21,12 +21,10 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package org.cactoos.iterator; +package org.cactoos.func; import java.util.ArrayList; import java.util.List; -import org.cactoos.Proc; -import org.cactoos.func.ProcNoNulls; import org.cactoos.list.ListOf; import org.cactoos.list.Synced; import org.hamcrest.Matcher; @@ -38,7 +36,7 @@ /** * Test case for {@link ForEachInThreads}. * - * @since 0.44 + * @since 1.0 * @checkstyle JavadocMethodCheck (500 lines) */ public class ForEachInThreadsTest { @@ -81,38 +79,4 @@ public void testProcIterable() throws Exception { ).affirm(); } - @Test - public void testProcVarargs() throws Exception { - final List list = new Synced<>( - new ArrayList<>( - 2 - ) - ); - new ForEachInThreads( - (Proc) list::add - ).exec( - 1, 1 - ); - new Assertion<>( - "List does not contain mapped Iterable elements (2)", list, - new IsIterableContainingInAnyOrder( - new ListOf>( - new MatcherOf<>( - value -> { - return value.equals( - 1 - ); - } - ), new MatcherOf<>( - value -> { - return value.equals( - 1 - ); - } - ) - ) - ) - ).affirm(); - } - } diff --git a/src/test/java/org/cactoos/iterator/ForEachTest.java b/src/test/java/org/cactoos/func/ForEachTest.java similarity index 80% rename from src/test/java/org/cactoos/iterator/ForEachTest.java rename to src/test/java/org/cactoos/func/ForEachTest.java index fc99484bf3..20512bca39 100644 --- a/src/test/java/org/cactoos/iterator/ForEachTest.java +++ b/src/test/java/org/cactoos/func/ForEachTest.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package org.cactoos.iterator; +package org.cactoos.func; import java.util.LinkedList; import java.util.List; @@ -35,7 +35,7 @@ /** * Test case for {@link ForEach}. * - * @since 0.44 + * @since 1.0 * @checkstyle JavadocMethodCheck (500 lines) */ public class ForEachTest { @@ -51,22 +51,9 @@ public void testProcIterable() throws Exception { ) ); new Assertion<>( - "List does not contain mapped Iterable elements (1)", list, new IsEqual<>( - new ListOf<>( - 1, 1 - ) - ) - ).affirm(); - } - - @Test - public void testProcVarargs() throws Exception { - final List list = new LinkedList<>(); - new ForEach( - (Proc) list::add - ).exec(1, 1); - new Assertion<>( - "List does not contain mapped Iterable elements (2)", list, new IsEqual<>( + "List does not contain mapped Iterable elements (1)", + list, + new IsEqual<>( new ListOf<>( 1, 1 )