Skip to content

Commit

Permalink
(#825) Scalar replaced with Proc
Browse files Browse the repository at this point in the history
  • Loading branch information
borysfan committed Feb 11, 2019
1 parent 3d83b3c commit 074afad
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
21 changes: 12 additions & 9 deletions src/main/java/org/cactoos/scalar/Binary.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
*/
package org.cactoos.scalar;

import org.cactoos.Proc;
import org.cactoos.Scalar;
import org.cactoos.func.ProcOf;

/**
* Binary operation.
Expand Down Expand Up @@ -54,9 +56,9 @@ public final class Binary implements Scalar<Boolean> {
private final Scalar<Boolean> condition;

/**
* Scalar executed when condition is true.
* Proc executed when condition is true.
*/
private final Scalar<?> consequent;
private final Proc<Boolean> consequent;

/**
* Ctor.
Expand All @@ -66,20 +68,21 @@ public final class Binary implements Scalar<Boolean> {
*/
public Binary(final Scalar<Boolean> condition, final Runnable runnable) {
this(
condition, () -> {
runnable.run();
return 0;
}
condition,
new ProcOf<>(runnable)
);
}

/**
* Ctor.
*
* @param condition Boolean function
* @param consequent Scalar executed when condition is true
* @param consequent Proc executed when condition is true
*/
public Binary(final Scalar<Boolean> condition, final Scalar<?> consequent) {
public Binary(
final Scalar<Boolean> condition,
final Proc<Boolean> consequent
) {
this.condition = condition;
this.consequent = consequent;
}
Expand All @@ -88,7 +91,7 @@ public Binary(final Scalar<Boolean> condition, final Scalar<?> consequent) {
public Boolean value() throws Exception {
final Boolean result = this.condition.value();
if (result) {
this.consequent.value();
this.consequent.exec(true);
}
return result;
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/cactoos/scalar/BinaryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void conditionTrue() {
final AtomicInteger counter = new AtomicInteger(0);
final Binary binary = new Binary(
new True(),
(Runnable) counter::incrementAndGet
counter::incrementAndGet
);
new Assertion<>(
"Binary has to return true",
Expand All @@ -65,7 +65,7 @@ public void conditionFalse() {
final AtomicInteger counter = new AtomicInteger(0);
final Binary binary = new Binary(
new False(),
(Runnable) counter::incrementAndGet
counter::incrementAndGet
);
new Assertion<>(
"Binary has to return false",
Expand Down

0 comments on commit 074afad

Please sign in to comment.