Add IOTriConsumer
MODIFY
src/changes/changes.xml
src/changes/changes.xml
@@ -357,7 +357,7 @@ The <action> type attribute can be add,update,fix,remove.
Add IOExceptionList.checkEmpty(List, Object).
</action>
<action dev="ggregory" type="add" due-to="Gary Gregory">
- Add IOBiConsumer.
+ Add IOBiConsumer, IOTriConsumer.
</action>
<action dev="ggregory" type="add" due-to="Gary Gregory">
Add and reuse IOConsumer forAll(*), forEach(*), and forEachIndexed(*).

MODIFY
src/main/java/org/apache/commons/io/UncheckedIO.java
src/main/java/org/apache/commons/io/UncheckedIO.java
import java.io.IOException;
import java.io.UncheckedIOException;
+import org.apache.commons.io.function.IOBiConsumer;
import org.apache.commons.io.function.IOBiFunction;
import org.apache.commons.io.function.IOConsumer;
import org.apache.commons.io.function.IOFunction;
import org.apache.commons.io.function.IOQuadFunction;
import org.apache.commons.io.function.IORunnable;
import org.apache.commons.io.function.IOSupplier;
+import org.apache.commons.io.function.IOTriConsumer;
import org.apache.commons.io.function.IOTriFunction;
/**
*/
public class UncheckedIO {
+ /**
+ * Accepts an IO consumer with the given arguments.
+ *
+ * @param <T> the first input type.
+ * @param <U> the second input type.
+ * @param t the first input argument.
+ * @param u the second input argument.
+ * @param consumer Consumes the value.
+ * @throws UncheckedIOException if an I/O error occurs.
+ */
+ public static <T, U> void accept(final IOBiConsumer<T, U> consumer, final T t, final U u) {
+ try {
+ consumer.accept(t, u);
+ } catch (final IOException e) {
+ throw wrap(e);
+ }
+ }
+
/**
* Accepts an IO consumer with the given argument.
*
- * @param <T> the return type of the operations.
- * @param t the consumer argument.
+ * @param <T> the input type.
+ * @param t the input argument.
* @param consumer Consumes the value.
* @throws UncheckedIOException if an I/O error occurs.
*/
}
/**
- * Applies an IO bi-function with the given arguments.
+ * Accepts an IO consumer with the given arguments.
+ *
+ * @param <T> the first input type.
+ * @param <U> the second input type.
+ * @param <V> the third input type.
+ * @param t the first input argument.
+ * @param u the second input argument.
+ * @param v the third input argument.
+ * @param consumer Consumes the value.
+ * @throws UncheckedIOException if an I/O error occurs.
+ */
+ public static <T, U, V> void accept(final IOTriConsumer<T, U, V> consumer, final T t, final U u, final V v) {
+ try {
+ consumer.accept(t, u, v);
+ } catch (final IOException e) {
+ throw wrap(e);
+ }
+ }
+
+ /**
+ * Applies an IO function with the given arguments.
*
* @param function the function.
* @param <T> the first function argument type.

MODIFY
src/main/java/org/apache/commons/io/function/Constants.java
src/main/java/org/apache/commons/io/function/Constants.java
* No-op singleton.
*/
@SuppressWarnings("rawtypes")
- static final IOBiConsumer IO_BI_CONSUMER = (t, u) -> {/* NOOP */};
+ static final IOBiConsumer IO_BI_CONSUMER = (t, u) -> {/* No-op */};
/**
* No-op singleton.
*/
static final IOPredicate<Object> IO_PREDICATE_TRUE = t -> true;
+ /**
+ * No-op singleton.
+ */
+ @SuppressWarnings("rawtypes")
+ static final IOTriConsumer IO_TRI_CONSUMER = (t, u, v) -> {/* No-op */};
+
private Constants() {
// We don't want instances
}

ADD
src/main/java/org/apache/commons/io/function/IOTriConsumer.java
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.io.function;
+
+import java.io.IOException;
+import java.util.Objects;
+import java.util.function.BiConsumer;
+
+/**
+ * Like {@link BiConsumer} but throws {@link IOException}.
+ *
+ * @param <T> the type of the first argument to the operation
+ * @param <U> the type of the second argument to the operation
+ * @param <V> the type of the third argument to the operation
+ *
+ * @see BiConsumer
+ * @since 2.12.0
+ */
+@FunctionalInterface
+public interface IOTriConsumer<T, U, V> {
+
+ /**
+ * Returns The no-op singleton.
+ *
+ * @param <T> the type of the first argument to the operation
+ * @param <U> the type of the second argument to the operation
+ * @param <V> the type of the third argument to the operation
+ * @return The NOOP singleton.
+ */
+ static <T, U, V> IOTriConsumer<T, U, V> noop() {
+ return Constants.IO_TRI_CONSUMER;
+ }
+
+ /**
+ * Performs this operation on the given arguments.
+ *
+ * @param t the first input argument
+ * @param u the second input argument
+ * @param v the second third argument
+ * @throws IOException if an I/O error occurs.
+ */
+ void accept(T t, U u, V v) throws IOException;
+
+ /**
+ * Returns a composed {@link IOTriConsumer} that performs, in sequence, this operation followed by the {@code after}
+ * operation. If performing either operation throws an exception, it is relayed to the caller of the composed operation.
+ * If performing this operation throws an exception, the {@code after} operation will not be performed.
+ *
+ * @param after the operation to perform after this operation
+ * @return a composed {@link IOTriConsumer} that performs in sequence this operation followed by the {@code after}
+ * operation
+ * @throws NullPointerException if {@code after} is null
+ */
+ default IOTriConsumer<T, U, V> andThen(final IOTriConsumer<? super T, ? super U, ? super V> after) {
+ Objects.requireNonNull(after);
+ return (t, u, v) -> {
+ accept(t, u, v);
+ after.accept(t, u, v);
+ };
+ }
+}

ADD
src/test/java/org/apache/commons/io/function/IOTriConsumerTest.java
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.io.function;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.io.IOException;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests {@link IOTriConsumer}.
+ */
+public class IOTriConsumerTest {
+
+ @Test
+ public void testAccept() throws IOException {
+ final AtomicReference<String> ref = new AtomicReference<>();
+ final IOTriConsumer<String, Integer, Character> consumer = (s, i, b) -> ref.set(s + i + b);
+ consumer.accept("A", 1, 'b');
+ assertEquals("A1b", ref.get());
+ }
+
+ @Test
+ public void testAndThen() throws IOException {
+ final AtomicReference<String> ref = new AtomicReference<>();
+ final IOTriConsumer<String, Integer, Character> consumer1 = (s, i, b) -> ref.set(s + i + b);
+ final IOTriConsumer<String, Integer, Character> consumer2 = (s, i, b) -> ref.set(ref.get() + b + i + s);
+ consumer1.andThen(consumer2).accept("B", 2, 'b');
+ assertEquals("B2bb2B", ref.get());
+ }
+
+ @Test
+ public void testNoop() throws IOException {
+ IOTriConsumer.noop().accept(null, null, null);
+ }
+
+}

Add IOTriConsumer