From 0d27ede39392e8a8f959cfb2f0e111bada08c0a8 Mon Sep 17 00:00:00 2001 From: yegor256 Date: Tue, 6 Jun 2017 11:41:47 +0300 Subject: [PATCH 1/2] #86: doc --- src/main/java/org/cactoos/io/ResourceAsInput.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/cactoos/io/ResourceAsInput.java b/src/main/java/org/cactoos/io/ResourceAsInput.java index ed8dbf9bb8..0773d0166c 100644 --- a/src/main/java/org/cactoos/io/ResourceAsInput.java +++ b/src/main/java/org/cactoos/io/ResourceAsInput.java @@ -29,7 +29,12 @@ import org.cactoos.text.FormattedText; /** - * Jar class resource. + * Classpath resource. + * + *

Pay attention that the name of resource must always be + * global, not starting with a leading slash. Thus, + * if you want to load a text file from {@code /com/example/Test.txt}, + * you must provide this name: {@code "com/example/Test.txt"}.

* * @author Kirill (g4s8.public@gmail.com) * @version $Id$ From 92cf9a216620127f90d73cf2534646a99fb46485 Mon Sep 17 00:00:00 2001 From: yegor256 Date: Tue, 6 Jun 2017 11:45:48 +0300 Subject: [PATCH 2/2] #86: third arg for FuncWithCallback --- .../org/cactoos/func/FuncWithCallback.java | 21 +++++++++++++++++-- .../cactoos/func/FuncWithCallbackTest.java | 13 ++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/cactoos/func/FuncWithCallback.java b/src/main/java/org/cactoos/func/FuncWithCallback.java index 2e0dc53e06..5522c75c5c 100644 --- a/src/main/java/org/cactoos/func/FuncWithCallback.java +++ b/src/main/java/org/cactoos/func/FuncWithCallback.java @@ -48,6 +48,11 @@ public final class FuncWithCallback implements Func { */ private final Func callback; + /** + * The follow up. + */ + private final Func follow; + /** * Ctor. * @param fnc The func @@ -55,8 +60,20 @@ public final class FuncWithCallback implements Func { */ public FuncWithCallback(final Func fnc, final Func cbk) { + this(fnc, cbk, input -> input); + } + + /** + * Ctor. + * @param fnc The func + * @param cbk The callback + * @param flw The follow up func + */ + public FuncWithCallback(final Func fnc, + final Func cbk, final Func flw) { this.func = fnc; this.callback = cbk; + this.follow = flw; } @Override @@ -64,7 +81,7 @@ public FuncWithCallback(final Func fnc, public Y apply(final X input) throws Exception { Y result; try { - result = this.func.apply(input); + result = this.func.apply(input); } catch (final InterruptedException ex) { Thread.currentThread().interrupt(); result = this.callback.apply(ex); @@ -72,7 +89,7 @@ public Y apply(final X input) throws Exception { } catch (final Throwable ex) { result = this.callback.apply(ex); } - return result; + return this.follow.apply(result); } } diff --git a/src/test/java/org/cactoos/func/FuncWithCallbackTest.java b/src/test/java/org/cactoos/func/FuncWithCallbackTest.java index 44f4c89ff9..74339669b0 100644 --- a/src/test/java/org/cactoos/func/FuncWithCallbackTest.java +++ b/src/test/java/org/cactoos/func/FuncWithCallbackTest.java @@ -65,4 +65,17 @@ public void usesCallback() throws Exception { ); } + @Test + public void usesFollowUp() throws Exception { + MatcherAssert.assertThat( + "Can't use the follow-up func", + new FuncWithCallback<>( + input -> "works fine", + ex -> "won't happen", + input -> "follow up" + ), + new FuncApplies<>(1, Matchers.containsString("follow")) + ); + } + }