From aa2eb706af003f489c55ea2edee9b39b36f46be2 Mon Sep 17 00:00:00 2001 From: yegor256 Date: Thu, 22 Jun 2017 08:01:53 +0300 Subject: [PATCH] no recursion --- src/main/java/org/cactoos/func/And.java | 28 +++++++------------------ src/main/java/org/cactoos/func/Or.java | 28 +++++++------------------ 2 files changed, 14 insertions(+), 42 deletions(-) diff --git a/src/main/java/org/cactoos/func/And.java b/src/main/java/org/cactoos/func/And.java index 8adc224e22..4c8b422a8a 100644 --- a/src/main/java/org/cactoos/func/And.java +++ b/src/main/java/org/cactoos/func/And.java @@ -23,7 +23,6 @@ */ package org.cactoos.func; -import java.util.Iterator; import org.cactoos.Func; import org.cactoos.Proc; import org.cactoos.Scalar; @@ -112,27 +111,14 @@ public And(final Iterable> src) { @Override public Boolean asValue() throws Exception { - return this.conjunction(this.iterable.iterator(), true); - } - - /** - * Conjunction. - * - * @param iterator The iterator - * @param value Previous value - * @return The result - * @throws Exception If fails - */ - private Boolean conjunction( - final Iterator> iterator, - final boolean value - ) throws Exception { - final Boolean result; - if (iterator.hasNext() && value) { - result = this.conjunction(iterator, iterator.next().asValue()); - } else { - result = value; + boolean result = true; + for (final Scalar item : this.iterable) { + if (!item.asValue()) { + result = false; + break; + } } return result; } + } diff --git a/src/main/java/org/cactoos/func/Or.java b/src/main/java/org/cactoos/func/Or.java index efe68f03b3..ff424ae921 100644 --- a/src/main/java/org/cactoos/func/Or.java +++ b/src/main/java/org/cactoos/func/Or.java @@ -23,7 +23,6 @@ */ package org.cactoos.func; -import java.util.Iterator; import org.cactoos.Scalar; import org.cactoos.list.ArrayAsIterable; @@ -62,27 +61,14 @@ public Or(final Iterable> src) { @Override public Boolean asValue() throws Exception { - return this.disjunction(this.iterable.iterator(), false); - } - - /** - * Disjunction. - * - * @param iterator The iterator - * @param value Previous value - * @return The result - * @throws Exception If fails - */ - private Boolean disjunction( - final Iterator> iterator, - final boolean value - ) throws Exception { - final Boolean result; - if (iterator.hasNext() && !value) { - result = this.disjunction(iterator, iterator.next().asValue()); - } else { - result = value; + boolean result = false; + for (final Scalar item : this.iterable) { + if (item.asValue()) { + result = true; + break; + } } return result; } + }