This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-io.git
commit 3d54ed8bb361b4d3392d350859d0c82380f73af1 Author: Gary Gregory <gardgreg...@gmail.com> AuthorDate: Sat Jul 23 19:28:56 2022 -0400 Add missing entries for adding IOBiFunction and IOTriFunction. Simplify to avoid ambiguous signature when inlining lambdas. --- src/changes/changes.xml | 3 +++ .../apache/commons/io/function/IOBiFunction.java | 15 ----------- .../apache/commons/io/function/IOTriFunction.java | 14 ----------- .../commons/io/function/IOBiFunctionTest.java | 15 ----------- .../commons/io/function/IOTriFunctionTest.java | 29 ---------------------- 5 files changed, 3 insertions(+), 73 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index d8fa98f5..bafa38d9 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -409,6 +409,9 @@ The <action> type attribute can be add,update,fix,remove. <action dev="ggregory" type="add" due-to="Gary Gregory"> Add PathUtils.getLastModifiedFileTime(*). </action> + <action dev="ggregory" type="add" due-to="Gary Gregory"> + Add IOBiFunction, IOTriFunction. + </action> <!-- UPDATE --> <action dev="kinow" type="update" due-to="Dependabot, Gary Gregory"> Bump actions/cache from 2.1.6 to 3.0.5 #307, #337. diff --git a/src/main/java/org/apache/commons/io/function/IOBiFunction.java b/src/main/java/org/apache/commons/io/function/IOBiFunction.java index ed6427da..e055f740 100644 --- a/src/main/java/org/apache/commons/io/function/IOBiFunction.java +++ b/src/main/java/org/apache/commons/io/function/IOBiFunction.java @@ -61,21 +61,6 @@ public interface IOBiFunction<T, U, R> { */ R apply(T t, U u) throws IOException; - /** - * Returns a composed function that first applies this function to its input, and then applies the {@code after} - * function to the result. If evaluation of either function throws an exception, it is relayed to the caller of the - * composed function. - * - * @param <V> the type of output of the {@code after} function, and of the composed function - * @param after the function to apply after this function is applied - * @return a composed function that first applies this function and then applies the {@code after} function - * @throws NullPointerException if after is null - */ - default <V> IOBiFunction<T, U, V> andThen(final Function<? super R, ? extends V> after) { - Objects.requireNonNull(after); - return (final T t, final U u) -> after.apply(apply(t, u)); - } - /** * Returns a composed function that first applies this function to its input, and then applies the {@code after} * function to the result. If evaluation of either function throws an exception, it is relayed to the caller of the diff --git a/src/main/java/org/apache/commons/io/function/IOTriFunction.java b/src/main/java/org/apache/commons/io/function/IOTriFunction.java index a7c4e11b..c27929f2 100644 --- a/src/main/java/org/apache/commons/io/function/IOTriFunction.java +++ b/src/main/java/org/apache/commons/io/function/IOTriFunction.java @@ -66,18 +66,4 @@ public interface IOTriFunction<T, U, V, R> { return (final T t, final U u, final V v) -> after.apply(apply(t, u, v)); } - /** - * Returns a composed function that first applies this function to its input, and then applies the {@code after} - * function to the result. If evaluation of either function throws an exception, it is relayed to the caller of the - * composed function. - * - * @param <W> the type of output of the {@code after} function, and of the composed function - * @param after the function to apply after this function is applied - * @return a composed function that first applies this function and then applies the {@code after} function - * @throws NullPointerException if after is null - */ - default <W> IOTriFunction<T, U, V, W> andThen(final Function<? super R, ? extends W> after) { - Objects.requireNonNull(after); - return (final T t, final U u, final V v) -> after.apply(apply(t, u, v)); - } } diff --git a/src/test/java/org/apache/commons/io/function/IOBiFunctionTest.java b/src/test/java/org/apache/commons/io/function/IOBiFunctionTest.java index 69f3628e..2f5f86fe 100644 --- a/src/test/java/org/apache/commons/io/function/IOBiFunctionTest.java +++ b/src/test/java/org/apache/commons/io/function/IOBiFunctionTest.java @@ -25,7 +25,6 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.LinkOption; import java.nio.file.Path; -import java.util.function.Function; import org.apache.commons.io.file.PathUtils; import org.junit.jupiter.api.Test; @@ -40,20 +39,6 @@ public class IOBiFunctionTest { return !value; } - /** - * Tests {@link IOBiFunction#andThen(Function)}. - * - * @throws IOException thrown on test failure - */ - @Test - public void testAndThenFunction() throws IOException { - final IOBiFunction<Path, LinkOption[], Boolean> isDirectory = Files::isDirectory; - final Function<Boolean, Boolean> not = b -> !b; - assertEquals(true, isDirectory.apply(PathUtils.current(), PathUtils.EMPTY_LINK_OPTION_ARRAY)); - final IOBiFunction<Path, LinkOption[], Boolean> andThen = isDirectory.andThen(not); - assertEquals(false, andThen.apply(PathUtils.current(), PathUtils.EMPTY_LINK_OPTION_ARRAY)); - } - /** * Tests {@link IOBiFunction#andThen(IOFunction)}. * diff --git a/src/test/java/org/apache/commons/io/function/IOTriFunctionTest.java b/src/test/java/org/apache/commons/io/function/IOTriFunctionTest.java index 9f5ce36e..36f5df44 100644 --- a/src/test/java/org/apache/commons/io/function/IOTriFunctionTest.java +++ b/src/test/java/org/apache/commons/io/function/IOTriFunctionTest.java @@ -22,7 +22,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.IOException; import java.math.BigInteger; import java.util.concurrent.atomic.AtomicReference; -import java.util.function.Function; import org.junit.jupiter.api.Test; @@ -53,34 +52,6 @@ public class IOTriFunctionTest { assertEquals("z", ref3.get()); } - /** - * Tests {@link IOTriFunction#andThen(Function)}. - * - * @throws IOException thrown on test failure - */ - @Test - public void testAndThenFunction() throws IOException { - final AtomicReference<Character> ref1 = new AtomicReference<>(); - final AtomicReference<Short> ref2 = new AtomicReference<>(); - final AtomicReference<String> ref3 = new AtomicReference<>(); - final IOTriFunction<AtomicReference<Character>, AtomicReference<Short>, AtomicReference<String>, String> tri = (t, u, v) -> { - ref1.set(Character.valueOf('a')); - ref2.set(Short.valueOf((short) 1)); - ref3.set("z"); - return "9"; - }; - final Function<String, BigInteger> after = t -> { - ref1.set(Character.valueOf('b')); - ref2.set(Short.valueOf((short) 2)); - ref3.set("zz"); - return BigInteger.valueOf(Long.parseLong(t)).add(BigInteger.ONE); - }; - assertEquals(BigInteger.TEN, tri.andThen(after).apply(ref1, ref2, ref3)); - assertEquals(Character.valueOf('b'), ref1.get()); - assertEquals(Short.valueOf((short) 2), ref2.get()); - assertEquals("zz", ref3.get()); - } - /** * Tests {@link IOTriFunction#andThen(IOFunction)}. *