Skip to content

Commit

Permalink
Xor extends ScalarEnvelope and returns false for empty iterable
Browse files Browse the repository at this point in the history
Signed-off-by: kokodyn <kokodyn@gmail.com>
  • Loading branch information
kokodyn committed Jan 14, 2021
1 parent 5edeb4b commit 8c95275
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
24 changes: 8 additions & 16 deletions src/main/java/org/cactoos/scalar/Xor.java
Expand Up @@ -61,12 +61,7 @@
* @see IoChecked
* @since 0.49
*/
public final class Xor implements Scalar<Boolean> {

/**
* The iterable.
*/
private final Iterable<Scalar<Boolean>> origin;
public final class Xor extends ScalarEnvelope<Boolean> {

/**
* Ctor.
Expand All @@ -82,15 +77,12 @@ public Xor(final Scalar<Boolean>... scalar) {
* @param iterable The iterable.
*/
public Xor(final Iterable<Scalar<Boolean>> iterable) {
this.origin = iterable;
}

@Override
public Boolean value() throws Exception {
return new Ternary<>(
new LengthOf(this.origin).value() > 0,
new Reduced<Boolean>((a, b) -> a ^ b, this.origin),
new True()
).value();
super(
new Ternary<>(
() -> new LengthOf(iterable).value() > 0,
new Reduced<Boolean>((a, b) -> a ^ b, iterable),
new False()
)
);
}
}
4 changes: 2 additions & 2 deletions src/test/java/org/cactoos/scalar/XorTest.java
Expand Up @@ -109,9 +109,9 @@ void singleFalse() throws Exception {
@Test
void emptyIterable() throws Exception {
new Assertion<>(
"Empty iterable must be True",
"Empty iterable must be False",
new Xor(new IterableOf<Scalar<Boolean>>()),
new ScalarHasValue<>(true)
new ScalarHasValue<>(false)
).affirm();
}

Expand Down

0 comments on commit 8c95275

Please sign in to comment.