Skip to content

Commit

Permalink
#1644 lambdas
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Jul 15, 2022
1 parent 1a3841b commit 6c6720d
Show file tree
Hide file tree
Showing 17 changed files with 22 additions and 36 deletions.
4 changes: 1 addition & 3 deletions src/main/java/org/cactoos/func/BiFuncOf.java
Expand Up @@ -91,9 +91,7 @@ public BiFuncOf(final BiProc<X, Y> proc, final Z result) {
*/
public BiFuncOf(final BiFunc<X, Y, Z> fnc) {
super(
(first, second) -> {
return fnc.apply(first, second);
}
fnc::apply
);
}
}
4 changes: 2 additions & 2 deletions src/main/java/org/cactoos/io/Joined.java
Expand Up @@ -65,9 +65,9 @@ public Joined(final Input first, final Input... rest) {
@Override
public InputStream stream() throws Exception {
return new Reduced<InputStream>(
(left, right) -> new SequenceInputStream(left, right),
SequenceInputStream::new,
new Mapped<>(
input -> () -> input.stream(),
input -> input::stream,
this.inputs
)
).value();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/cactoos/scalar/CallableOf.java
Expand Up @@ -50,6 +50,6 @@ public final class CallableOf<T> extends CallableEnvelope<T> {
* @since 0.41
*/
public CallableOf(final Scalar<? extends T> slr) {
super(() -> slr.value());
super(slr::value);
}
}
2 changes: 1 addition & 1 deletion src/main/java/org/cactoos/text/Trimmed.java
Expand Up @@ -40,6 +40,6 @@ public final class Trimmed extends TextEnvelope {
* @param text The text
*/
public Trimmed(final Text text) {
super(new Mapped(str -> str.trim(), text));
super(new Mapped(String::trim, text));
}
}
4 changes: 1 addition & 3 deletions src/test/java/org/cactoos/func/BiFuncOfTest.java
Expand Up @@ -66,9 +66,7 @@ void convertsProcIntoBiFunc() throws Exception {
"Must convert procedure into bi-function",
new BiFuncOf<>(
new ProcOf<>(
input -> {
done.set(input);
}
done::set
),
result
),
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/cactoos/func/FlattenedTest.java
Expand Up @@ -39,7 +39,7 @@ void flattens() {
new Assertion<>(
"must flatten",
new Flattened<>(
new FuncOf<>(x -> new BoolOf(x))
new FuncOf<>(BoolOf::new)
),
new IsApplicable<>("true", true)
).affirm();
Expand Down
4 changes: 1 addition & 3 deletions src/test/java/org/cactoos/func/FuncOfTest.java
Expand Up @@ -44,9 +44,7 @@ void convertsProcIntoFunc() throws Exception {
"Must convert Proc into Func",
new FuncOf<>(
new ProcOf<>(
input -> {
done.set(input);
}
done::set
),
result
),
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/cactoos/io/LoggingInputStreamTest.java
Expand Up @@ -53,7 +53,7 @@ public int read() throws IOException {
);
new Assertion<>(
"Read doesn't throw an the exception.",
() -> stream.read(),
stream::read,
new Throws<>(message, IOException.class)
).affirm();
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/cactoos/io/LoggingOutputTest.java
Expand Up @@ -65,7 +65,7 @@ public void logWriteZero() throws Exception {
new TeeInput(
new InputOf(""),
new LoggingOutput(
() -> new ByteArrayOutputStream(),
ByteArrayOutputStream::new,
"memory",
logger
)
Expand Down
10 changes: 5 additions & 5 deletions src/test/java/org/cactoos/iterator/PagedTest.java
Expand Up @@ -73,7 +73,7 @@ void containAllPagedContentInOrder() throws Exception {
return true;
},
new Matched<>(
(x, y) -> x.equals(y),
String::equals,
paged,
new IteratorOf<>("one", "two", "three", "four", "five")
)
Expand Down Expand Up @@ -101,8 +101,8 @@ void reportTotalPagedLength() {
final Paged<String> paged = new Paged<>(
pages.next(),
page -> new Ternary<>(
() -> pages.hasNext(),
() -> pages.next(),
pages::hasNext,
pages::next,
() -> new IteratorOf<String>()
).value()
);
Expand All @@ -128,8 +128,8 @@ void throwsNoSuchElement() {
() -> new Paged<>(
pages.next(),
page -> new Ternary<>(
() -> pages.hasNext(),
() -> pages.next(),
pages::hasNext,
pages::next,
() -> new IteratorOf<String>()
).value()
).next()
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/cactoos/list/NoNullsTest.java
Expand Up @@ -135,7 +135,7 @@ void getThrowsErrorIfListIteratorPreviousValueIsNullValue() {
list.set(0, null);
new Assertion<>(
"must throw error if previous value in iterator is null",
() -> listiterator.previous(),
listiterator::previous,
new Throws<>(
"Previous item is NULL",
IllegalStateException.class
Expand Down
4 changes: 1 addition & 3 deletions src/test/java/org/cactoos/proc/BiProcOfTest.java
Expand Up @@ -88,9 +88,7 @@ void worksWithProc() throws Exception {
"Must execute BiProc with Proc",
new BiProcOf<>(
new ProcOf<>(
input -> {
done.set(input);
}
done::set
)
),
new Satisfies<>(
Expand Down
4 changes: 1 addition & 3 deletions src/test/java/org/cactoos/proc/ProcOfTest.java
Expand Up @@ -64,9 +64,7 @@ void worksWithLambda() throws Exception {
new Assertion<>(
"Must execute Proc with Lambda",
new ProcOf<>(
input -> {
done.set(input);
}
done::set
),
new Satisfies<>(
proc -> {
Expand Down
4 changes: 1 addition & 3 deletions src/test/java/org/cactoos/proc/RunnableOfTest.java
Expand Up @@ -44,9 +44,7 @@ void convertsProcIntoRunnable() {
"Must execute Runnable with Proc",
new RunnableOf(
new ProcOf<>(
input -> {
done.set(input);
}
done::set
),
obj
),
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/cactoos/scalar/FoldedTest.java
Expand Up @@ -43,7 +43,7 @@ void skipIterable() throws Exception {
new Assertion<>(
"Must fold elements in iterable",
new Folded<>(
0L, (first, second) -> first + second,
0L, Long::sum,
new HeadOf<>(
10,
new RangeOf<>(0L, Long.MAX_VALUE, value -> ++value)
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/cactoos/scalar/RepeatedTest.java
Expand Up @@ -44,7 +44,7 @@ void runsMultipleTimes() throws Exception {
new Assertion<>(
"Must run scalar 3 times",
new Repeated<>(
() -> atom.incrementAndGet(),
atom::incrementAndGet,
3
).value(),
new IsEqual<>(3)
Expand Down
4 changes: 1 addition & 3 deletions src/test/java/org/cactoos/scalar/ScalarOfTest.java
Expand Up @@ -93,9 +93,7 @@ void worksWithProc() {
"Must convert Proc into Scalar",
new ScalarOf<>(
new ProcOf<>(
input -> {
done.set(input);
}
done::set
),
ipt,
result
Expand Down

0 comments on commit 6c6720d

Please sign in to comment.