Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Apr 12, 2018
2 parents f08a43d + 8dce6a3 commit b4223ce
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/main/java/org/cactoos/scalar/Or.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
* use {@link UncheckedScalar} or {@link IoCheckedScalar} decorators.</p>
*
* @author Vseslav Sekorin (vssekorin@gmail.com)
* @author Mehmet Yildirim (memoyil@gmail.com)
* @version $Id$
* @since 0.8
*/
Expand Down Expand Up @@ -121,6 +122,22 @@ public <X> Or(final Func<X, Boolean> func, final Iterable<X> src) {
);
}

/**
* Ctor.
* @param subject The subject
* @param conditions Funcs to map
* @param <X> Type of items in the iterable
*/
@SafeVarargs
public <X> Or(final X subject, final Func<X, Boolean>... conditions) {
this(
new Mapped<>(
item -> (Scalar<Boolean>) () -> item.apply(subject),
new IterableOf<>(conditions)
)
);
}

/**
* Ctor.
* @param scalar The Scalar.
Expand Down
28 changes: 28 additions & 0 deletions src/test/java/org/cactoos/scalar/OrTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
* Test case for {@link Or}.
*
* @author Vseslav Sekorin (vssekorin@gmail.com)
* @author Mehmet Yildirim (memoyil@gmail.com)
* @version $Id$
* @since 0.8
* @checkstyle JavadocMethodCheck (500 lines)
Expand Down Expand Up @@ -144,4 +145,31 @@ public void testFuncVarargs() throws Exception {
new ScalarHasValue<>(false)
);
}

@Test
public void testMultipleFuncConditionTrue() throws Exception {
MatcherAssert.assertThat(
"Can't compare subject with true conditions",
new Or(
3,
input -> input > 0,
input -> input > 5,
input -> input > 4
),
new ScalarHasValue<>(true)
);
}

@Test
public void testMultipleFuncConditionFalse() throws Exception {
MatcherAssert.assertThat(
"Can't compare subject with false conditions",
new Or(
"cactoos",
input -> input.contains("singleton"),
input -> input.contains("static")
),
new ScalarHasValue<>(false)
);
}
}

0 comments on commit b4223ce

Please sign in to comment.