1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 package org.apache.commons.io.function;
19
20 import java.io.IOException;
21 import java.util.Objects;
22 import java.util.function.BiConsumer;
23
24 /**
25 * Like {@link BiConsumer} but throws {@link IOException}.
26 *
27 * @param <T> the type of the first argument to the operation
28 * @param <U> the type of the second argument to the operation
29 * @param <V> the type of the third argument to the operation
30 *
31 * @see BiConsumer
32 * @since 2.12.0
33 */
34 @FunctionalInterface
35 public interface IOTriConsumer<T, U, V> {
36
37 /**
38 * Returns the no-op singleton.
39 *
40 * @param <T> the type of the first argument to the operation
41 * @param <U> the type of the second argument to the operation
42 * @param <V> the type of the third argument to the operation
43 * @return The no-op singleton.
44 */
45 @SuppressWarnings("unchecked")
46 static <T, U, V> IOTriConsumer<T, U, V> noop() {
47 return Constants.IO_TRI_CONSUMER;
48 }
49
50 /**
51 * Performs this operation on the given arguments.
52 *
53 * @param t the first input argument
54 * @param u the second input argument
55 * @param v the second third argument
56 * @throws IOException if an I/O error occurs.
57 */
58 void accept(T t, U u, V v) throws IOException;
59
60 /**
61 * Creates a composed {@link IOTriConsumer} that performs, in sequence, this operation followed by the {@code after}
62 * operation. If performing either operation throws an exception, it is relayed to the caller of the composed operation.
63 * If performing this operation throws an exception, the {@code after} operation will not be performed.
64 *
65 * @param after the operation to perform after this operation
66 * @return a composed {@link IOTriConsumer} that performs in sequence this operation followed by the {@code after}
67 * operation
68 * @throws NullPointerException if {@code after} is null
69 */
70 default IOTriConsumer<T, U, V> andThen(final IOTriConsumer<? super T, ? super U, ? super V> after) {
71 Objects.requireNonNull(after);
72 return (t, u, v) -> {
73 accept(t, u, v);
74 after.accept(t, u, v);
75 };
76 }
77 }